summaryrefslogtreecommitdiff
path: root/src/leap/keymanager/tests/test_openpgp.py
diff options
context:
space:
mode:
authorRuben Pollan <meskio@sindominio.net>2015-12-15 13:29:44 +0100
committerRuben Pollan <meskio@sindominio.net>2016-02-25 11:35:18 -0600
commit64eaf2ee426623072bc2d9b1faf77ab831cb3be1 (patch)
treef25638fc9c2bc2ddcbb2262492c18beb990d8696 /src/leap/keymanager/tests/test_openpgp.py
parentb8e03b8fc18d2f1a02210b622c3befe562f46ab7 (diff)
[feat] move validation, usage and audited date to the active document
- Resolves: #7485
Diffstat (limited to 'src/leap/keymanager/tests/test_openpgp.py')
-rw-r--r--src/leap/keymanager/tests/test_openpgp.py54
1 files changed, 53 insertions, 1 deletions
diff --git a/src/leap/keymanager/tests/test_openpgp.py b/src/leap/keymanager/tests/test_openpgp.py
index 96b40a0e..66415916 100644
--- a/src/leap/keymanager/tests/test_openpgp.py
+++ b/src/leap/keymanager/tests/test_openpgp.py
@@ -29,7 +29,10 @@ from leap.keymanager import (
KeyNotFound,
openpgp,
)
-from leap.keymanager.keys import TYPE_ID_PRIVATE_INDEX
+from leap.keymanager.keys import (
+ TYPE_ID_PRIVATE_INDEX,
+ TYPE_ADDRESS_PRIVATE_INDEX,
+)
from leap.keymanager.openpgp import OpenPGPKey
from leap.keymanager.tests import (
KeyManagerWithSoledadTestCase,
@@ -308,6 +311,7 @@ class OpenPGPCryptoTestCase(KeyManagerWithSoledadTestCase):
try:
yield self.assertFailure(pgp.get_key(ADDRESS, private=False),
KeyNotFound)
+ # it should have deleted the index
self.assertEqual(self._soledad.delete_doc.call_count, 1)
finally:
self._soledad.get_from_index = get_from_index
@@ -349,6 +353,54 @@ class OpenPGPCryptoTestCase(KeyManagerWithSoledadTestCase):
self._soledad.get_from_index = get_from_index
self._soledad.delete_doc = delete_doc
+ @inlineCallbacks
+ def test_self_repair_five_active_docs(self):
+ pgp = openpgp.OpenPGPScheme(
+ self._soledad, gpgbinary=self.gpg_binary_path)
+
+ get_from_index = self._soledad.get_from_index
+ delete_doc = self._soledad.delete_doc
+
+ def my_get_from_index(*args):
+ if (args[0] == TYPE_ADDRESS_PRIVATE_INDEX and
+ args[2] == ADDRESS):
+ k1 = OpenPGPKey(ADDRESS, key_id="1",
+ last_audited_at=datetime(2005, 1, 1))
+ k2 = OpenPGPKey(ADDRESS, key_id="2",
+ last_audited_at=datetime(2007, 1, 1))
+ k3 = OpenPGPKey(ADDRESS, key_id="3",
+ last_audited_at=datetime(2007, 1, 1),
+ encr_used=True, sign_used=True)
+ k4 = OpenPGPKey(ADDRESS, key_id="4",
+ last_audited_at=datetime(2007, 1, 1),
+ sign_used=True)
+ k5 = OpenPGPKey(ADDRESS, key_id="5",
+ last_audited_at=datetime(2007, 1, 1),
+ encr_used=True)
+ deferreds = []
+ for k in [k1, k2, k3, k4, k5]:
+ d = self._soledad.create_doc_from_json(
+ k.get_active_json(ADDRESS))
+ deferreds.append(d)
+ return gatherResults(deferreds)
+ elif args[0] == TYPE_ID_PRIVATE_INDEX:
+ key_id = args[2]
+ self.assertEqual(key_id, "3")
+ k = OpenPGPKey(ADDRESS, key_id="3")
+ return succeed(
+ [self._soledad.create_doc_from_json(k.get_json())])
+ return get_from_index(*args)
+
+ self._soledad.get_from_index = my_get_from_index
+ self._soledad.delete_doc = Mock(return_value=succeed(None))
+
+ try:
+ yield pgp.get_key(ADDRESS, private=False)
+ self.assertEqual(self._soledad.delete_doc.call_count, 4)
+ finally:
+ self._soledad.get_from_index = get_from_index
+ self._soledad.delete_doc = delete_doc
+
def _assert_key_not_found(self, pgp, address, private=False):
d = pgp.get_key(address, private=private)
return self.assertFailure(d, KeyNotFound)