class MultipleHmacMiddlewareTestCase(TestCase): def setUp(self): self.hmacmiddleware = HmacMiddleware() self.factory = RequestFactory() self.hmac = Hmac() def test_raise_exception_when_signature_is_not_send(self): request = self.factory.get('/example',) with self.assertRaises(PermissionDenied): self.hmacmiddleware.process_request(request) def test_should_be_ok_when_correct_hmac_is_send(self): signature = self.hmac.make_hmac_for('serviceA') request = self.factory.get('/example', **{'HTTP_' + self.hmac.header.upper(): signature}) self.hmacmiddleware.process_request(request) def test_raise_exception_when_signature_changed(self): signature = self.hmac.make_hmac_for('serviceA', 'some data') request = self.factory.get('/example', **{'HTTP_' + self.hmac.header.upper(): signature}) with self.assertRaises(PermissionDenied): self.hmacmiddleware.process_request(request) def test_raise_exception_when_invalid_hmac_is_send(self): request = self.factory.get('/example', **{'HTTP_' + self.hmac.header.upper(): '00'}) with self.assertRaises(PermissionDenied): self.hmacmiddleware.process_request(request)
def setUp(self): self.hmacmiddleware = HmacMiddleware() self.factory = RequestFactory() self.hmac = Hmac()