diff options
Diffstat (limited to 'src/leap/soledad/tests/test_crypto.py')
-rw-r--r-- | src/leap/soledad/tests/test_crypto.py | 43 |
1 files changed, 26 insertions, 17 deletions
diff --git a/src/leap/soledad/tests/test_crypto.py b/src/leap/soledad/tests/test_crypto.py index 039d2f3c..676c13b0 100644 --- a/src/leap/soledad/tests/test_crypto.py +++ b/src/leap/soledad/tests/test_crypto.py @@ -22,22 +22,26 @@ Tests for cryptographic related stuff. import os +try: + import simplejson as json +except ImportError: + import json # noqa +from leap.soledad.backends.leap_backend import ( + LeapDocument, + encrypt_doc_json, + decrypt_doc_json, + EncryptionSchemes, +) +from leap.soledad import KeyAlreadyExists +from leap.soledad.crypto import SoledadCrypto from leap.common.testing.basetest import BaseLeapTest -from leap.soledad.backends.leap_backend import LeapDocument from leap.soledad.tests import BaseSoledadTest from leap.soledad.tests import ( KEY_FINGERPRINT, PRIVATE_KEY, ) -from leap.soledad import KeyAlreadyExists -from leap.soledad.crypto import SoledadCrypto - -try: - import simplejson as json -except ImportError: - import json # noqa class EncryptedSyncTestCase(BaseSoledadTest): @@ -45,26 +49,31 @@ class EncryptedSyncTestCase(BaseSoledadTest): Tests that guarantee that data will always be encrypted when syncing. """ - def test_get_set_encrypted_json(self): + def test_encrypt_decrypt_json(self): """ - Test getting and setting encrypted content. + Test encrypting and decrypting documents. """ - doc1 = LeapDocument(crypto=self._soledad._crypto) + doc1 = LeapDocument(doc_id='id') doc1.content = {'key': 'val'} - doc2 = LeapDocument(doc_id=doc1.doc_id, - encrypted_json=doc1.get_encrypted_json(), - crypto=self._soledad._crypto) + enc_json = encrypt_doc_json( + self._soledad._crypto, doc1.doc_id, doc1.get_json()) + plain_json = decrypt_doc_json( + self._soledad._crypto, doc1.doc_id, enc_json) + doc2 = LeapDocument(doc_id=doc1.doc_id, json=plain_json) res1 = doc1.get_json() res2 = doc2.get_json() self.assertEqual(res1, res2, 'incorrect document encryption') - def test_successful_symmetric_encryption(self): + def test_encrypt_sym(self): """ Test for successful symmetric encryption. """ - doc1 = LeapDocument(crypto=self._soledad._crypto) + doc1 = LeapDocument() doc1.content = {'key': 'val'} - enc_json = json.loads(doc1.get_encrypted_json())['_encrypted_json'] + enc_json = json.loads( + encrypt_doc_json( + self._soledad._crypto, + doc1.doc_id, doc1.get_json()))['_encrypted_json'] self.assertEqual( True, self._soledad._crypto.is_encrypted_sym(enc_json), |