summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorRuben Pollan <meskio@sindominio.net>2017-06-08 11:14:38 +0200
committerRuben Pollan <meskio@sindominio.net>2017-06-12 20:34:15 +0200
commitf0117969b19e05d568a108b12390c47a011576f6 (patch)
treeadfd7406d0cacf31e682a62f4a5384ec747a977d /tests
parent1fd9bd8f5284ed1b61da2d5cc81e3347c61a761d (diff)
[feat] push private key updates into nicknym
Deal as well with sending key if key is outdated in the providers nicknym. - Resolves: #8819, #8832
Diffstat (limited to 'tests')
-rw-r--r--tests/integration/keymanager/test_keymanager.py27
-rw-r--r--tests/integration/keymanager/test_validation.py27
-rw-r--r--tests/integration/mail/incoming/test_incoming_mail.py4
3 files changed, 31 insertions, 27 deletions
diff --git a/tests/integration/keymanager/test_keymanager.py b/tests/integration/keymanager/test_keymanager.py
index 9f81e02..4282629 100644
--- a/tests/integration/keymanager/test_keymanager.py
+++ b/tests/integration/keymanager/test_keymanager.py
@@ -22,7 +22,6 @@ import urllib
import tempfile
import pkg_resources
from datetime import datetime
-from os import path
from twisted.internet import defer
from twisted.trial import unittest
@@ -31,7 +30,6 @@ from twisted.web import client
import mock
from leap.common import ca_bundle
-from leap.bitmask.keymanager import client
from leap.bitmask.keymanager import errors
from leap.bitmask.keymanager.keys import (
OpenPGPKey,
@@ -193,11 +191,6 @@ class KeyManagerKeyManagementTestCase(KeyManagerWithSoledadTestCase):
key.fingerprint.lower(), KEY_FINGERPRINT.lower())
self.assertTrue(key.private)
- def test_send_key_raises_key_not_found(self):
- km = self._key_manager()
- d = km.send_key()
- return self.assertFailure(d, errors.KeyNotFound)
-
@defer.inlineCallbacks
def test_send_key(self):
"""
@@ -215,8 +208,8 @@ class KeyManagerKeyManagementTestCase(KeyManagerWithSoledadTestCase):
km.api_uri = 'apiuri'
km.api_version = 'apiver'
yield km.send_key()
+ pubkey = yield km.get_key(ADDRESS, fetch_remote=False)
# setup expected args
- pubkey = yield km.get_key(km._address)
data = urllib.urlencode({
km.PUBKEY_KEY: pubkey.key_data,
})
@@ -309,7 +302,7 @@ class KeyManagerKeyManagementTestCase(KeyManagerWithSoledadTestCase):
"""
Test that getting a key successfuly fetches from server.
"""
- km = self._key_manager(url=NICKSERVER_URI)
+ km = self._key_manager(user=ADDRESS_2, url=NICKSERVER_URI)
key = yield self._fetch_key_with_address(km, ADDRESS, PUBLIC_KEY)
self.assertIsInstance(key, OpenPGPKey)
@@ -368,7 +361,7 @@ class KeyManagerKeyManagementTestCase(KeyManagerWithSoledadTestCase):
"""
Test that putting ascii key works
"""
- km = self._key_manager(url=NICKSERVER_URI)
+ km = self._key_manager(user=ADDRESS_2, url=NICKSERVER_URI)
yield km.put_raw_key(PUBLIC_KEY, ADDRESS)
key = yield km.get_key(ADDRESS)
@@ -380,7 +373,7 @@ class KeyManagerKeyManagementTestCase(KeyManagerWithSoledadTestCase):
"""
Test that putting binary key works
"""
- km = self._key_manager(url=NICKSERVER_URI)
+ km = self._key_manager(user=ADDRESS_2, url=NICKSERVER_URI)
yield km.put_raw_key(self.get_public_binary_key(), ADDRESS)
key = yield km.get_key(ADDRESS)
@@ -545,6 +538,18 @@ class KeyManagerKeyManagementTestCase(KeyManagerWithSoledadTestCase):
# then
self.assertEqual(False, key.sign_used)
+ def test_put_pubkey_address_fails(self):
+ km = self._key_manager()
+ d = km.put_raw_key(PUBLIC_KEY, ADDRESS)
+ return self.assertFailure(d, errors.KeyNotValidUpgrade)
+
+ @defer.inlineCallbacks
+ def test_put_privkey_address_sends(self):
+ km = self._key_manager()
+ km.send_key = mock.Mock()
+ yield km.put_raw_key(PRIVATE_KEY, ADDRESS)
+ km.send_key.assert_called_once_with()
+
class KeyManagerCryptoTestCase(KeyManagerWithSoledadTestCase):
diff --git a/tests/integration/keymanager/test_validation.py b/tests/integration/keymanager/test_validation.py
index aa29712..73391b3 100644
--- a/tests/integration/keymanager/test_validation.py
+++ b/tests/integration/keymanager/test_validation.py
@@ -19,6 +19,7 @@ Tests for the Validation Levels
"""
import unittest
from datetime import datetime
+from mock import MagicMock
from twisted.internet.defer import inlineCallbacks
from leap.bitmask.keymanager.errors import KeyNotValidUpgrade
@@ -44,14 +45,14 @@ class ValidationLevelsTestCase(KeyManagerWithSoledadTestCase):
@inlineCallbacks
def test_none_old_key(self):
- km = self._key_manager()
+ km = self._key_manager("unrelated@leap.se")
yield km.put_raw_key(PUBLIC_KEY, ADDRESS)
key = yield km.get_key(ADDRESS, fetch_remote=False)
self.assertEqual(key.fingerprint, KEY_FINGERPRINT)
@inlineCallbacks
def test_cant_upgrade(self):
- km = self._key_manager()
+ km = self._key_manager("unrelated@leap.se")
yield km.put_raw_key(PUBLIC_KEY, ADDRESS,
validation=ValidationLevels.Provider_Trust)
d = km.put_raw_key(UNRELATED_KEY, ADDRESS)
@@ -59,7 +60,7 @@ class ValidationLevelsTestCase(KeyManagerWithSoledadTestCase):
@inlineCallbacks
def test_fingerprint_level(self):
- km = self._key_manager()
+ km = self._key_manager("unrelated@leap.se")
yield km.put_raw_key(PUBLIC_KEY, ADDRESS)
yield km.put_raw_key(UNRELATED_KEY, ADDRESS,
validation=ValidationLevels.Fingerprint)
@@ -68,7 +69,7 @@ class ValidationLevelsTestCase(KeyManagerWithSoledadTestCase):
@inlineCallbacks
def test_expired_key(self):
- km = self._key_manager()
+ km = self._key_manager("unrelated@leap.se")
yield km.put_raw_key(EXPIRED_KEY, ADDRESS)
yield km.put_raw_key(UNRELATED_KEY, ADDRESS)
key = yield km.get_key(ADDRESS, fetch_remote=False)
@@ -76,7 +77,7 @@ class ValidationLevelsTestCase(KeyManagerWithSoledadTestCase):
@inlineCallbacks
def test_expired_fail_lower_level(self):
- km = self._key_manager()
+ km = self._key_manager("unrelated@leap.se")
yield km.put_raw_key(
EXPIRED_KEY, ADDRESS,
validation=ValidationLevels.Third_Party_Endorsement)
@@ -87,7 +88,7 @@ class ValidationLevelsTestCase(KeyManagerWithSoledadTestCase):
@inlineCallbacks
def test_can_upgrade_key(self):
- km = self._key_manager()
+ km = self._key_manager("unrelated@leap.se")
yield km.put_raw_key(OLD_PUB_KEY, OLD_AND_NEW_KEY_ADDRESS)
old_key = yield km.get_key(OLD_AND_NEW_KEY_ADDRESS, fetch_remote=False)
@@ -100,7 +101,7 @@ class ValidationLevelsTestCase(KeyManagerWithSoledadTestCase):
@inlineCallbacks
def test_roll_back(self):
- km = self._key_manager()
+ km = self._key_manager("unrelated@leap.se")
yield km.put_raw_key(EXPIRED_KEY_UPDATED, ADDRESS)
yield km.put_raw_key(EXPIRED_KEY, ADDRESS)
key = yield km.get_key(ADDRESS, fetch_remote=False)
@@ -108,7 +109,7 @@ class ValidationLevelsTestCase(KeyManagerWithSoledadTestCase):
@inlineCallbacks
def test_not_used(self):
- km = self._key_manager()
+ km = self._key_manager("unrelated@leap.se")
yield km.put_raw_key(UNEXPIRED_KEY, ADDRESS,
validation=ValidationLevels.Provider_Trust)
yield km.put_raw_key(UNRELATED_KEY, ADDRESS,
@@ -120,7 +121,8 @@ class ValidationLevelsTestCase(KeyManagerWithSoledadTestCase):
def test_used_with_verify(self):
TEXT = "some text"
- km = self._key_manager()
+ km = self._key_manager("unrelated@leap.se")
+ km._send_key = MagicMock() # let's skip sending key
yield km.put_raw_key(UNEXPIRED_PRIVATE, ADDRESS)
signature = yield km.sign(TEXT, ADDRESS)
yield self.delete_all_keys(km)
@@ -138,7 +140,8 @@ class ValidationLevelsTestCase(KeyManagerWithSoledadTestCase):
def test_used_with_decrypt(self):
TEXT = "some text"
- km = self._key_manager()
+ km = self._key_manager("unrelated@leap.se")
+ km._send_key = MagicMock() # let's skip sending key
yield km.put_raw_key(UNEXPIRED_PRIVATE, ADDRESS)
yield km.put_raw_key(PUBLIC_KEY_2, ADDRESS_2)
encrypted = yield km.encrypt(TEXT, ADDRESS_2, sign=ADDRESS)
@@ -156,7 +159,7 @@ class ValidationLevelsTestCase(KeyManagerWithSoledadTestCase):
@inlineCallbacks
def test_signed_key(self):
- km = self._key_manager()
+ km = self._key_manager("unrelated@leap.se")
yield km.put_raw_key(PUBLIC_KEY, ADDRESS)
yield km.put_raw_key(SIGNED_KEY, ADDRESS)
key = yield km.get_key(ADDRESS, fetch_remote=False)
@@ -166,7 +169,7 @@ class ValidationLevelsTestCase(KeyManagerWithSoledadTestCase):
def test_two_uuids(self):
TEXT = "some text"
- km = self._key_manager()
+ km = self._key_manager("unrelated@leap.se")
yield km.put_raw_key(UUIDS_PRIVATE, ADDRESS_2)
signature = yield km.sign(TEXT, ADDRESS_2)
yield self.delete_all_keys(km)
diff --git a/tests/integration/mail/incoming/test_incoming_mail.py b/tests/integration/mail/incoming/test_incoming_mail.py
index 43dbd09..3b5727e 100644
--- a/tests/integration/mail/incoming/test_incoming_mail.py
+++ b/tests/integration/mail/incoming/test_incoming_mail.py
@@ -133,10 +133,6 @@ subject: independence of cyberspace
d.addErrback(log.err)
return d
- def tearDown(self):
- d = KeyManagerWithSoledadTestCase.tearDown(self)
- return d
-
def testExtractOpenPGPHeader(self):
"""
Test the OpenPGP header key extraction