diff options
author | Hubert Chathi <hubert@uhoreg.ca> | 2019-04-08 15:08:17 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-04-08 15:08:17 -0400 |
commit | 2a6400716c1e17b65507cd2a433192f81cd402df (patch) | |
tree | eb034ad74fab1e337b422d387e8e9a8b62bfb098 /python/tests | |
parent | fcfa5f12a4cd482973fdf03000af4a26a360dc2e (diff) | |
parent | 709687a7b56d6768831766459940b6f0bb078d85 (diff) |
Merge branch 'master' into poljar/python-sas
Diffstat (limited to 'python/tests')
-rw-r--r-- | python/tests/pk_test.py | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/python/tests/pk_test.py b/python/tests/pk_test.py new file mode 100644 index 0000000..f2aa147 --- /dev/null +++ b/python/tests/pk_test.py @@ -0,0 +1,49 @@ +import pytest + +from olm import PkDecryption, PkDecryptionError, PkEncryption + + +class TestClass(object): + def test_invalid_encryption(self): + with pytest.raises(ValueError): + PkEncryption("") + + def test_decrytion(self): + decryption = PkDecryption() + encryption = PkEncryption(decryption.public_key) + plaintext = "It's a secret to everybody." + message = encryption.encrypt(plaintext) + decrypted_plaintext = decryption.decrypt(message) + isinstance(decrypted_plaintext, str) + assert plaintext == decrypted_plaintext + + def test_invalid_decrytion(self): + decryption = PkDecryption() + encryption = PkEncryption(decryption.public_key) + plaintext = "It's a secret to everybody." + message = encryption.encrypt(plaintext) + message.ephemeral_key = "?" + with pytest.raises(PkDecryptionError): + decryption.decrypt(message) + + def test_pickling(self): + decryption = PkDecryption() + encryption = PkEncryption(decryption.public_key) + plaintext = "It's a secret to everybody." + message = encryption.encrypt(plaintext) + + pickle = decryption.pickle() + unpickled = PkDecryption.from_pickle(pickle) + decrypted_plaintext = unpickled.decrypt(message) + assert plaintext == decrypted_plaintext + + def test_invalid_unpickling(self): + with pytest.raises(ValueError): + PkDecryption.from_pickle("") + + def test_invalid_pass_pickling(self): + decryption = PkDecryption() + pickle = decryption.pickle("Secret") + + with pytest.raises(PkDecryptionError): + PkDecryption.from_pickle(pickle, "Not secret") |