summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorRuben Pollan <meskio@sindominio.net>2017-10-31 11:02:00 +0100
committerRuben Pollan <meskio@sindominio.net>2017-12-03 23:12:14 +0100
commitfb7eef011cc672f1884bcfcd4c859a549d8f3e49 (patch)
tree753190cbeeae7f1934590533f467a717cfabdaab /tests
parentf6c71494f0ada864e80ee74c60ec09939a14f44b (diff)
[feat] extend the expiration of private keys if needed
Check on every fetch of the private key if the expiration is less than two months before it expire. And extend the expiration if needed. - Resolves: #8217
Diffstat (limited to 'tests')
-rw-r--r--tests/integration/keymanager/test_keymanager.py33
1 files changed, 32 insertions, 1 deletions
diff --git a/tests/integration/keymanager/test_keymanager.py b/tests/integration/keymanager/test_keymanager.py
index 8ed70bdf..544a1a18 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, date
+from datetime import datetime, date, timedelta
from twisted.internet import defer
from twisted.trial import unittest
@@ -191,6 +191,37 @@ class KeyManagerKeyManagementTestCase(KeyManagerWithSoledadTestCase):
self.assertFalse(key.private)
@defer.inlineCallbacks
+ def test_get_expired_private_key_extends_expiration(self):
+ token = "mytoken"
+ km = self._key_manager(user=ADDRESS_EXPIRING, token=token)
+ km._nicknym.put_key = mock.Mock(return_value=defer.succeed(''))
+
+ yield km.put_raw_key(PRIVATE_EXPIRING_KEY, ADDRESS_EXPIRING)
+ key = yield km.get_key(ADDRESS_EXPIRING, private=True)
+
+ def assert_expiration_date(key):
+ expected = datetime.now() + timedelta(days=365)
+ self.assertTrue(expected - key.expiry_date < timedelta(days=1))
+
+ # check that the right key is returned with the expiration extended
+ self.assertTrue(key.private)
+ assert_expiration_date(key)
+ self.assertTrue(km._nicknym.put_key.called)
+ key_sent_data = km._nicknym.put_key.call_args[0][1]
+ key_sent_pub, key_sent_priv = km._openpgp.parse_key(key_sent_data)
+ self.assertTrue(key_sent_priv is None)
+ assert_expiration_date(key_sent_pub)
+
+ # check that the key in the keyring has the right expiration and
+ # a second get key doesn't try to extend the expiration again
+ km._nicknym.put_key = mock.Mock(return_value=defer.succeed(''))
+ pubkey = yield km.get_key(ADDRESS_EXPIRING)
+ privkey = yield km.get_key(ADDRESS_EXPIRING, private=True)
+ self.assertFalse(km._nicknym.put_key.called)
+ assert_expiration_date(privkey)
+ assert_expiration_date(pubkey)
+
+ @defer.inlineCallbacks
def test_get_public_key_with_binary_private_key(self):
km = self._key_manager()
yield km._openpgp.put_raw_key(self.get_private_binary_key(), ADDRESS)