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
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')
def test_good_man_params_signature_ok(self): signature = sign(self.params, self.salt) self.assertTrue(self.hk.signature_ok(self.params, signature))
def sign(params, salt, date=None): return client.sign(params, salt, date)