summaryrefslogtreecommitdiff
path: root/src/leap/soledad/tests
diff options
context:
space:
mode:
Diffstat (limited to 'src/leap/soledad/tests')
-rw-r--r--src/leap/soledad/tests/test_encrypted.py88
1 files changed, 76 insertions, 12 deletions
diff --git a/src/leap/soledad/tests/test_encrypted.py b/src/leap/soledad/tests/test_encrypted.py
index 0a4eb9cc..eb78fbe3 100644
--- a/src/leap/soledad/tests/test_encrypted.py
+++ b/src/leap/soledad/tests/test_encrypted.py
@@ -1,6 +1,11 @@
from leap.soledad.backends.leap_backend import LeapDocument
from leap.soledad.tests import BaseSoledadTest
from leap.soledad.tests import KEY_FINGERPRINT
+from leap.soledad import (
+ Soledad,
+ KeyAlreadyExists,
+)
+from leap.soledad.util import GPGWrapper
try:
import simplejson as json
@@ -41,12 +46,13 @@ class EncryptedSyncTestCase(BaseSoledadTest):
def test_export_recovery_document_raw(self):
rd = self._soledad.export_recovery_document(None)
self.assertEqual(
- [
- self._soledad._user_email,
- self._soledad._gpg.export_keys(self._soledad._fingerprint,
- secret=True),
- self._soledad._secret
- ],
+ {
+ 'user_email': self._soledad._user_email,
+ 'privkey': self._soledad._gpg.export_keys(
+ self._soledad._fingerprint,
+ secret=True),
+ 'secret': self._soledad._secret
+ },
json.loads(rd),
"Could not export raw recovery document."
)
@@ -55,12 +61,13 @@ class EncryptedSyncTestCase(BaseSoledadTest):
rd = self._soledad.export_recovery_document('123456')
self.assertEqual(True,
self._soledad._gpg.is_encrypted_sym(rd))
- data = [
- self._soledad._user_email,
- self._soledad._gpg.export_keys(self._soledad._fingerprint,
- secret=True),
- self._soledad._secret,
- ]
+ data = {
+ 'user_email': self._soledad._user_email,
+ 'privkey': self._soledad._gpg.export_keys(
+ self._soledad._fingerprint,
+ secret=True),
+ 'secret': self._soledad._secret,
+ }
raw_data = json.loads(str(self._soledad._gpg.decrypt(
rd,
passphrase='123456')))
@@ -69,3 +76,60 @@ class EncryptedSyncTestCase(BaseSoledadTest):
data,
"Could not export raw recovery document."
)
+
+ def test_import_recovery_document_raises_exception(self):
+ rd = self._soledad.export_recovery_document(None)
+ self.assertRaises(KeyAlreadyExists,
+ self._soledad.import_recovery_document, rd, None)
+
+ def test_import_recovery_document_raw(self):
+ rd = self._soledad.export_recovery_document(None)
+ gnupg_home = self.gnupg_home = "%s/gnupg2" % self.tempdir
+ s = Soledad('anotheruser@leap.se', gnupg_home=gnupg_home,
+ initialize=False, prefix=self.tempdir)
+ s._init_dirs()
+ s._gpg = GPGWrapper(gnupghome=gnupg_home)
+ s.import_recovery_document(rd, None)
+ self.assertEqual(self._soledad._user_email,
+ s._user_email, 'Failed setting user email.')
+ self.assertEqual(self._soledad._secret,
+ s._secret,
+ 'Failed settinng secret for symmetric encryption.')
+ self.assertEqual(self._soledad._fingerprint,
+ s._fingerprint,
+ 'Failed settinng fingerprint.')
+ pk1 = self._soledad._gpg.export_keys(
+ self._soledad._fingerprint,
+ secret=True)
+ pk2 = s._gpg.export_keys(s._fingerprint, secret=True)
+ self.assertEqual(
+ pk1,
+ pk2,
+ 'Failed settinng private key.'
+ )
+
+ def test_import_recovery_document_crypt(self):
+ rd = self._soledad.export_recovery_document('123456')
+ gnupg_home = self.gnupg_home = "%s/gnupg2" % self.tempdir
+ s = Soledad('anotheruser@leap.se', gnupg_home=gnupg_home,
+ initialize=False, prefix=self.tempdir)
+ s._init_dirs()
+ s._gpg = GPGWrapper(gnupghome=gnupg_home)
+ s.import_recovery_document(rd, '123456')
+ self.assertEqual(self._soledad._user_email,
+ s._user_email, 'Failed setting user email.')
+ self.assertEqual(self._soledad._secret,
+ s._secret,
+ 'Failed settinng secret for symmetric encryption.')
+ self.assertEqual(self._soledad._fingerprint,
+ s._fingerprint,
+ 'Failed settinng fingerprint.')
+ pk1 = self._soledad._gpg.export_keys(
+ self._soledad._fingerprint,
+ secret=True)
+ pk2 = s._gpg.export_keys(s._fingerprint, secret=True)
+ self.assertEqual(
+ pk1,
+ pk2,
+ 'Failed settinng private key.'
+ )