-
-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' of https://github.com/MasoniteFramework/core i…
…nto develop
- Loading branch information
Showing
7 changed files
with
75 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
def set_request_method(method_type): | ||
return "<input type='hidden' name='request_method' value='{0}'>".format(method_type) | ||
return "<input type='hidden' name='__method' value='{0}'>".format(method_type) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
from masonite.request import Request | ||
from masonite.view import View | ||
from masonite.auth.Csrf import Csrf | ||
from masonite.app import App | ||
from middleware.CsrfMiddleware import CsrfMiddleware | ||
from masonite.testsuite.TestSuite import generate_wsgi | ||
import pytest | ||
from masonite.exceptions import InvalidCSRFToken | ||
|
||
class TestCSRFMiddleware: | ||
|
||
def setup_method(self): | ||
self.app = App() | ||
self.request = Request(generate_wsgi()) | ||
self.view = View(self.app) | ||
self.app.bind('Request', self.request) | ||
|
||
self.request = self.app.make('Request') | ||
|
||
self.middleware = CsrfMiddleware(self.request, Csrf(self.request), self.view) | ||
|
||
def test_middleware_shares_correct_input(self): | ||
self.middleware.before() | ||
assert 'csrf_field' in self.view.dictionary | ||
assert self.view.dictionary['csrf_field'].startswith("<input type='hidden' name='__token' value='") | ||
|
||
def test_middleware_throws_exception_on_post(self): | ||
self.request.environ['REQUEST_METHOD'] = 'POST' | ||
self.middleware.exempt = [] | ||
with pytest.raises(InvalidCSRFToken): | ||
self.middleware.before() | ||
|
||
def test_incoming_token_does_not_throw_exception_with_token(self): | ||
self.request.environ['REQUEST_METHOD'] = 'POST' | ||
self.request.request_variables.update({'__token': self.request.get_cookie('csrf_token')}) | ||
self.middleware.exempt = [] | ||
self.middleware.before() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters