예제 #1
0
    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))
예제 #2
0
    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))
예제 #3
0
    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))
예제 #4
0
    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))
예제 #5
0
    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))
예제 #6
0
    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))
예제 #7
0
    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)
예제 #8
0
    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)