Esempio n. 1
0
    def test_bad_user_attempt(self):
        signature = sign(self.params, 'BAD SALT')
        self.params['code'] = self.code
        self.params['sign'] = signature

        # middleware testing...
        request = self.factory.get('/some/private/view/', data=self.params)

        plug_mw = PluggableAuthMiddleware()
        plug_mw.process_request(request=request)

        user_as_response = self.fake_view(request)
        self.assertTrue(user_as_response is None) # no user is in request
Esempio n. 2
0
    def test_good_man_test_middleware(self):
        signature = sign(self.params, self.salt)
        self.params['code'] = self.code
        self.params['sign'] = signature

        params_copy = deepcopy(self.params)

        # middleware testing...
        request = self.factory.get('/some/private/view/', data=self.params)

        plug_mw = PluggableAuthMiddleware()
        plug_mw.process_request(request=request)

        user_as_response = self.fake_view(request)

        self.assertFalse(user_as_response is None, msg='fake_view returned None instead of good_user')

        self.assertEqual(user_as_response, self.good_user, msg='wrong user returned')

        # params were not hurt...
        self.assertEqual(params_copy, self.params, msg='params were likely hurt in the middleware')
Esempio n. 3
0
    def get_user_as_response(self, request):
        plug_mw = PluggableAuthMiddleware()
        plug_mw.process_request(request=request)

        return self.fake_view(request)