Skip to content

Commit

Permalink
feat: Add tests for Fernet and RSA encryption
Browse files Browse the repository at this point in the history
  • Loading branch information
bhimrazy committed Jul 10, 2024
1 parent ffda111 commit a807bbd
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions tests/utilities/test_encryption.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
from litdata.utilities.encryption import FernetEncryption, RSAEncryption


def test_fernet_encryption():
password = "password"
data = b"test data"
fernet = FernetEncryption(password)
encrypted_data = fernet.encrypt(data)
decrypted_data = fernet.decrypt(encrypted_data)
assert data == decrypted_data
assert data != encrypted_data
assert decrypted_data != encrypted_data
assert isinstance(encrypted_data, bytes)
assert isinstance(decrypted_data, bytes)
assert isinstance(fernet.extension, str)
assert fernet.extension == "fernet"
assert fernet.passsword == password
assert isinstance(fernet._derive_key(password), bytes)
assert isinstance(fernet._derive_key(password), bytes)


def test_rsa_encryption():
data = b"test data"
rsa = RSAEncryption()
encrypted_data = rsa.encrypt(data)
decrypted_data = rsa.decrypt(encrypted_data)
assert data == decrypted_data
assert data != encrypted_data
assert decrypted_data != encrypted_data
assert isinstance(encrypted_data, bytes)
assert isinstance(decrypted_data, bytes)
assert isinstance(rsa.extension, str)
assert rsa.extension == "rsa"

0 comments on commit a807bbd

Please sign in to comment.