def test_unspecified_digest_should_return_false(self): secret = 'secrettoken' message = 'message blah blah horse battery staple' Secret.set(secret) digest_received = None self.assertFalse(Secret.digest_is_valid(digest_received, message))
def test_non_matching_digests_should_return_false(self): secret = 'secrettoken' message = 'message blah blah horse battery staple' Secret.set(secret) digest_received = Secret._get_hex_digest('not the original message', secret) self.assertFalse(Secret.digest_is_valid(digest_received, message))
def test_matching_digests_should_return_true(self): secret = 'secrettoken' message = 'message blah blah horse battery staple' Secret.set(secret) digest_received = Secret._get_hex_digest(message, secret) self.assertTrue(Secret.digest_is_valid(digest_received, message))
def function_with_auth(self, *args, **kwargs): header_digest = self.request.headers.get(Secret.DIGEST_HEADER_KEY) if not Secret.digest_is_valid(header_digest, self.encoded_body.decode('utf-8')): raise AuthenticationError( 'Message digest does not match header, message not authenticated.' ) return function(self, *args, **kwargs)
def function_with_auth(self, *args, **kwargs): header_digest = self.request.headers.get(Secret.DIGEST_HEADER_KEY) if not Secret.digest_is_valid(header_digest, self.encoded_body.decode('utf-8')): raise AuthenticationError('Message digest does not match header, message not authenticated.') return function(self, *args, **kwargs)