summaryrefslogtreecommitdiff
path: root/tests/integration/keymanager
diff options
context:
space:
mode:
authorNavaL <ayoyo@thoughtworks.com>2016-11-16 16:53:48 +0100
committerRuben Pollan <meskio@sindominio.net>2017-12-03 20:43:24 +0100
commit3eab1813bfb9efeea65ab3ad9798b8e8dba6d163 (patch)
treeaf519eaf21e15edeb0211e0e1ad1b4b6c3301e18 /tests/integration/keymanager
parent10a8b732576aa6a21ca01f265967f9e09560c2cf (diff)
[feat] add key expiry date extension in keymanager
- extends key pair (unlocked from soledad) - extension period is counted from key creation date
Diffstat (limited to 'tests/integration/keymanager')
-rw-r--r--tests/integration/keymanager/common.py65
-rw-r--r--tests/integration/keymanager/test_keymanager.py57
2 files changed, 115 insertions, 7 deletions
diff --git a/tests/integration/keymanager/common.py b/tests/integration/keymanager/common.py
index f120223a..9e4b9ee1 100644
--- a/tests/integration/keymanager/common.py
+++ b/tests/integration/keymanager/common.py
@@ -328,3 +328,68 @@ MX1BrUFh3+YWaHHNd0pQb/iBG0ZpyW+LqfAxsQN2/VC1gP1G4xM0rmtFHGi+dKX2
=AGIo
-----END PGP PUBLIC KEY BLOCK-----
"""
+
+# key with expiry date, change if key below is changed
+ADDRESS_EXPIRING = 'leap.expiring@leap.se'
+KEY_EXPIRING_CREATION_DATE = '2016-11-06'
+
+PRIVATE_EXPIRING_KEY = """
+-----BEGIN PGP PRIVATE KEY BLOCK-----
+Version: GnuPG v1
+
+lQOYBFgecsEBCACq1AoEydTRFV6jsGUhKBzfstNyLR8C8xEOIohAfyg7TgEGwJEv
+AWqr54YiX386BX6Z8v7v6m+KpvJPAcU2ARxPk9lu6hCCSWbWJCN1+GyV+b8VzFll
+zSWVUb5lsh2nfxCYCTYZm4IIF+PYDhkC+MIf6ZIUFQVT9xZa5mR/LmhY8CjT3Sqq
+BVvCjtIsgPwystXpzyaqExlgf2xWun8TjIMb9KxGiV6s73tFccrauDgxmLjBcCj6
+UcJpZhWTfsTQmtz45DNAfirETdNvoYUo3gaGgmlHHE1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/dzuC1EAWMUzNNwGg+SJznmB0aKFzJARdDBoE04riSYI72yVAVX
+V57ky7/6f0PzxYOWugLhBADf33Pvax4P0R3UkVatTIqTYY7nuJIZbwzWcSw7ZY/s
++X4DHIHy01mHijWT0St56nGOIiAdUDPD5Wdwky2mn1j4JAb6ryaYOtBQWINyrr0q
+xlj6KNFIIrCPE1ECO5ASRHf/WKfewSyvpXnNJ60dc8eVmtGj3HTZFGXLH6Reza90
+cQQA9EpCDTPaXckbc37kAi3IoMuk/rw1D+6x9iuK9AE4ZLD52cuWn3v02NLKDbzl
+Qgew0XV+j1EXEckRfmoXyfaRxSNZvCTtqQ+d1Oge9adRj3lC8Eocv4ZQpErY2LQb
+4UI3UwfqIgJrKztURJ47K7If7A5Xz/HEW5GMl8acNWrKk7sEAMMA/B11g26UgYt1
+b0gagGcJNFAOH3yvh5Gu0QRA62qRp97XU5CulI+Lgo0vVBbtDsboluQG1sehWjgE
+yeYMX9KuK6alu/Pvym7XNj888GOB5q4w98jP6pyG1gBaWc9c2WrTYegs0oyHROzS
+DCsC7UFjCULAPYE4jqORq9kkw/3+P52JASUEGAECAA8FAlgecsECGwwFCQAJOoAA
+CgkQkRHzOeAV2iqm1Af+IgbIwp66zyelRMn6hJqwelmnrX1XSWAVRjaP4bxQWTUN
+2YqJhMEDBN6cWks1xkez/Ve/vKLJekW7NZEG10GIzzyuAFuNDExj9Ccvf/NTS+n+
+0tFaWe8adaVHjixnQ8fLc/GrYQwrobcpkalHdQ6Podxt3vW3LZ8gMhc8WvI6rLVT
+/w+7QQkI3OCd/0wBB6TvxzAJVxjshcr5ij7qhA6xIjqzFCWiAiXE0BLajIaA18IB
+igFmwKFUYT9cYIZo4gCdOkzdM7KQXiMfLGc12SPl5G0fkjs1CLT8k5wmWfwEjKCW
+JfWPBQqMwc5KLqFlXB0XQajdf0vxnnbbgK/Sbssntg==
+=2Zjl
+-----END PGP PRIVATE KEY BLOCK-----
+"""
diff --git a/tests/integration/keymanager/test_keymanager.py b/tests/integration/keymanager/test_keymanager.py
index 1e836a5d..466414a1 100644
--- a/tests/integration/keymanager/test_keymanager.py
+++ b/tests/integration/keymanager/test_keymanager.py
@@ -21,7 +21,7 @@ import json
import urllib
import tempfile
import pkg_resources
-from datetime import datetime
+from datetime import datetime, timedelta
from twisted.internet import defer
from twisted.trial import unittest
@@ -31,6 +31,7 @@ import mock
from leap.common import ca_bundle
from leap.bitmask.keymanager import errors
+from leap.bitmask.keymanager.errors import KeyExpiryExtensionError
from leap.bitmask.keymanager.keys import (
OpenPGPKey,
is_address,
@@ -47,18 +48,19 @@ from common import (
PUBLIC_KEY_2,
PRIVATE_KEY,
PRIVATE_KEY_2,
+ ADDRESS_EXPIRING,
+ KEY_EXPIRING_CREATION_DATE,
+ PRIVATE_EXPIRING_KEY,
NEW_PUB_KEY,
OLD_AND_NEW_KEY_ADDRESS
)
-
NICKSERVER_URI = "http://leap.se/"
REMOTE_KEY_URL = "http://site.domain/key"
INVALID_MAIL_ADDRESS = "notexistingemail@example.org"
class KeyManagerUtilTestCase(unittest.TestCase):
-
def test_is_address(self):
self.assertTrue(
is_address('user@leap.se'),
@@ -131,7 +133,6 @@ class KeyManagerUtilTestCase(unittest.TestCase):
class KeyManagerKeyManagementTestCase(KeyManagerWithSoledadTestCase):
-
@defer.inlineCallbacks
def _test_gen_key(self):
km = self._key_manager()
@@ -497,8 +498,8 @@ class KeyManagerKeyManagementTestCase(KeyManagerWithSoledadTestCase):
self.assertEqual(expected, self._slurp_file(tmp_output.name))
def _dump_to_file(self, filename, content):
- with open(filename, 'w') as out:
- out.write(content)
+ with open(filename, 'w') as out:
+ out.write(content)
def _slurp_file(self, filename):
with open(filename) as f:
@@ -552,9 +553,50 @@ class KeyManagerKeyManagementTestCase(KeyManagerWithSoledadTestCase):
yield km.put_raw_key(PRIVATE_KEY, ADDRESS)
km.send_key.assert_called_once_with()
+ @defer.inlineCallbacks
+ def test_keymanager_extend_key_expiry_date_for_key_pair(self):
+ km = self._key_manager(user=ADDRESS_EXPIRING)
-class KeyManagerCryptoTestCase(KeyManagerWithSoledadTestCase):
+ yield km._openpgp.put_raw_key(PRIVATE_EXPIRING_KEY, ADDRESS_EXPIRING)
+ key = yield km.get_key(ADDRESS_EXPIRING)
+
+ yield km.extend_key(validity='1w')
+
+ new_expiry_date = datetime.strptime(
+ KEY_EXPIRING_CREATION_DATE, '%Y-%m-%d')
+ new_expiry_date += timedelta(weeks=1)
+ renewed_public_key = yield km.get_key(ADDRESS_EXPIRING)
+ renewed_private_key = yield km.get_key(ADDRESS_EXPIRING, private=True)
+
+ self.assertEqual(new_expiry_date.date(),
+ renewed_public_key.expiry_date.date())
+ self.assertEqual(new_expiry_date.date(),
+ renewed_private_key.expiry_date.date())
+ self.assertEqual(key.fingerprint, renewed_public_key.fingerprint)
+ self.assertEqual(key.fingerprint, renewed_private_key.fingerprint)
+
+ @defer.inlineCallbacks
+ def test_key_extension_with_invalid_period_throws_exception(self):
+ km = self._key_manager(user=ADDRESS_EXPIRING)
+
+ yield km._openpgp.put_raw_key(PRIVATE_EXPIRING_KEY, ADDRESS_EXPIRING)
+ key = yield km.get_key(ADDRESS_EXPIRING)
+
+ invalid_validity_option = '2xw'
+
+ with self.assertRaises(KeyExpiryExtensionError):
+ yield km.extend_key(validity=invalid_validity_option)
+
+ renewed_public_key = yield km.get_key(ADDRESS_EXPIRING)
+ renewed_private_key = yield km.get_key(ADDRESS_EXPIRING, private=True)
+ self.assertEqual(key.expiry_date, renewed_public_key.expiry_date)
+ self.assertEqual(key.expiry_date, renewed_private_key.expiry_date)
+ self.assertEqual(key.fingerprint, renewed_public_key.fingerprint)
+ self.assertEqual(key.fingerprint, renewed_private_key.fingerprint)
+
+
+class KeyManagerCryptoTestCase(KeyManagerWithSoledadTestCase):
RAW_DATA = 'data'
@defer.inlineCallbacks
@@ -645,6 +687,7 @@ class KeyManagerCryptoTestCase(KeyManagerWithSoledadTestCase):
if __name__ == "__main__":
import unittest
+
unittest.main()
# key 0F91B402: someone@somedomain.org