Exemplo n.º 1
0
    def test_encrypt_email_address(self):
        """
        Test function `gdpr.encryption.encrypt_email_address` by using email address from Faker lib.
        """
        cleartext = self.faker.email()

        ciphertext = encrypt_email_address(self.encryption_key, cleartext)
        assert_not_equal(cleartext, ciphertext, "The encrypted email address is equal to the original email address.")

        decrypted = decrypt_email_address(self.encryption_key, ciphertext)
        assert_equal(cleartext, decrypted, "The decrypted email address is not equal to the original email address.")
Exemplo n.º 2
0
    def test_encrypt_email_address_with_single_level_domain(self):
        """
        Test function `gdpr.encryption.encrypt_email_address` by using email address from Faker lib.
        """
        cleartext = f'{self.faker.email().split("@")[0]}@localhost'

        ciphertext = encrypt_email_address(self.encryption_key, cleartext)
        assert_not_equal(cleartext, ciphertext, "The encrypted email address is equal to the original email address.")
        assert_equal(ciphertext.split('@')[1], 'localhost')

        decrypted = decrypt_email_address(self.encryption_key, ciphertext)
        assert_equal(cleartext, decrypted, "The decrypted email address is not equal to the original email address.")
Exemplo n.º 3
0
 def get_encrypted_value(self, value, encryption_key: str):
     split = value.split(':', 1)
     if len(split) == 2:
         return f'{split[0]}:{encrypt_email_address(encryption_key, split[1])}'
     return encrypt_email_address(encryption_key, value)
Exemplo n.º 4
0
 def get_encrypted_value(self, value, encryption_key: str):
     return encrypt_email_address(encryption_key, value)