Exemple #1
0
    def setUp(self):
        self.app = TestSuite().create_container().container
        self.app.bind('Csrf', Csrf(self.app.make('Request')))
        self.csrf = self.app.make('Csrf')
        self.request = self.app.make('Request')
        middleware = self.app.resolve(CsrfMiddleware)

        middleware.before()
    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 setup_method(self):
        self.app = App()
        wsgi = generate_wsgi()
        self.request = Request(wsgi)
        self.route = Route().load_environ(wsgi)
        self.view = View(self.app)
        self.app.bind('Request', self.request)

        self.request = self.app.make('Request')
        self.app.bind('WebRoutes', [
            Get().route('/test/@route', None),
            Get().route('/test/10', None),
        ])
        self.request.container = self.app

        self.middleware = CsrfMiddleware(self.request, Csrf(self.request),
                                         self.view)
Exemple #4
0
 def register(self):
     self.app.bind('Csrf', Csrf(self.app.make('Request')))
Exemple #5
0
from masonite.app import App
from middleware.CsrfMiddleware import CsrfMiddleware
from masonite.auth.Csrf import Csrf
from masonite.testsuite.TestSuite import TestSuite

container = TestSuite().create_container().container

container.bind('Csrf', Csrf(container.make('Request')))

csrf = container.make('Csrf')
request = container.make('Request')

middleware = container.resolve(CsrfMiddleware)

middleware.before()


def test_middleware_sets_csrf_cookie():
    assert request.get_cookie('csrf_token', decrypt=False)


def test_middleware_shares_view():
    assert 'csrf_field' in container.make('ViewClass').dictionary
    assert 'input' in container.make('ViewClass').dictionary['csrf_field']


def test_verify_token():
    token = request.get_cookie('csrf_token', decrypt=False)
    assert csrf.verify_csrf_token(token)