summaryrefslogtreecommitdiff
path: root/src/leap/soledad/tests/test_crypto.py
diff options
context:
space:
mode:
authordrebs <drebs@leap.se>2013-04-25 19:38:44 -0300
committerdrebs <drebs@leap.se>2013-04-25 19:54:35 -0300
commit2ef514b02fa37a0a2ebac0bb9668543e29033a7f (patch)
tree5b1d8226aef2d3cf347a4928635fcf5bc06807a0 /src/leap/soledad/tests/test_crypto.py
parentab540eacc529354cb111abc24eb2c9a70886ce21 (diff)
Fix symmetric encryption when syncing.
Also does: * Remove all crypto methods from LeapDocument. * Encode 'encryption_scheme' inside the document JSON. * Add functions for encrypting and decrypting. * Fix LeapSyncTarget so its connection actually returns a LeapSyncTarget. * Fix symmetric encryption when syncing: - don't try to encrypt tombstone documents. * Fix symmetric decryption when syncing: - Only try do decrypt if the incoming document has an '_encryption_scheme' entry with value equal to EncryptionSchemes.PUBKEY. * Fix doc skipping for non-syncable docs. * Fix tests that compared raw content with encrypted content.
Diffstat (limited to 'src/leap/soledad/tests/test_crypto.py')
-rw-r--r--src/leap/soledad/tests/test_crypto.py43
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),