-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add tests for Fernet and RSA encryption
- Loading branch information
Showing
1 changed file
with
33 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |