Esempio n. 1
0
    def test_aes_decrypt_unexpected_error(self):
        '''This test case ensures all unexpected exceptions from decrypt are converted correctly into OAuth2 encryption errors.'''

        aes_provider = AesTokenEncryption()

        with self.assertRaises(OAuth2TokenEncryptionError):
            aes_provider.decrypt_token(Token({}), "Simple IV", "Simple Key")
    def test_aes_decrypt_unexpected_error(self):
        '''This test case ensures all unexpected exceptions from decrypt are converted correctly into OAuth2 encryption errors.'''

        aes_provider = AesTokenEncryption()

        with self.assertRaises(OAuth2TokenEncryptionError):
            aes_provider.decrypt_token(Token({}), "Simple IV", "Simple Key")
Esempio n. 3
0
    def test_aes_decrypt_notoken(self):
        '''This test case ensures aes decrypt fails if no token is given.'''

        aes_provider = AesTokenEncryption()

        with self.assertRaises(OAuth2InvalidTokenDescriptorError) as ctx:
            aes_provider.decrypt_token(None, None, None)

        self.assertEqual("encrypted_str", ctx.exception.attr_name)
    def test_aes_decrypt_notoken(self):
        '''This test case ensures aes decrypt fails if no token is given.'''

        aes_provider = AesTokenEncryption()

        with self.assertRaises(OAuth2InvalidTokenDescriptorError) as ctx:
            aes_provider.decrypt_token(None, None, None)

        self.assertEqual("encrypted_str", ctx.exception.attr_name)
    def test_aes_ok(self):
        '''This test case ensures token encryption correctly supports AES-128 algorithm.'''

        aes_provider = AesTokenEncryption()

        for key_length in [16, 24, 32]:
            token_key = Random.new().read(key_length)

            token = Token({"client_id": "test client",
                           "attr1": "test"})

            token_encrypted = aes_provider.encrypt_token(token, self._aes_iv, token_key)
            token_decrypted = aes_provider.decrypt_token(token_encrypted, self._aes_iv, token_key)

            self.assertIsNotNone(token_decrypted)
            self.assertEqual(token.client_id, token_decrypted.client_id)
            self.assertEqual(token.attr1, token_decrypted.attr1)
Esempio n. 6
0
    def test_aes_ok(self):
        '''This test case ensures token encryption correctly supports AES-128 algorithm.'''

        aes_provider = AesTokenEncryption()

        for key_length in [16, 24, 32]:
            token_key = Random.new().read(key_length)

            token = Token({"client_id": "test client", "attr1": "test"})

            token_encrypted = aes_provider.encrypt_token(
                token, self._aes_iv, token_key)
            token_decrypted = aes_provider.decrypt_token(
                token_encrypted, self._aes_iv, token_key)

            self.assertIsNotNone(token_decrypted)
            self.assertEqual(token.client_id, token_decrypted.client_id)
            self.assertEqual(token.attr1, token_decrypted.attr1)