summaryrefslogtreecommitdiff
path: root/src/leap/keymanager/tests
diff options
context:
space:
mode:
authordrebs <drebs@leap.se>2014-10-09 20:12:29 -0300
committerdrebs <drebs@leap.se>2014-10-09 20:12:29 -0300
commitc4466bd5735652bff79da36a99da3f8b245d6115 (patch)
tree1a34002312d466b84ae99bc9dd130570141005e0 /src/leap/keymanager/tests
parent2c7c18b04d0435de65b58d57f22e229577189ca2 (diff)
parent2c8cfffad0cf214951628b771db2322533a8fe50 (diff)
Merge remote-tracking branch 'meskio/feature/5932_fetch_keys_uri' into develop
Diffstat (limited to 'src/leap/keymanager/tests')
-rw-r--r--src/leap/keymanager/tests/test_keymanager.py50
1 files changed, 50 insertions, 0 deletions
diff --git a/src/leap/keymanager/tests/test_keymanager.py b/src/leap/keymanager/tests/test_keymanager.py
index 39b729d8..65f8f39f 100644
--- a/src/leap/keymanager/tests/test_keymanager.py
+++ b/src/leap/keymanager/tests/test_keymanager.py
@@ -28,6 +28,7 @@ from leap.keymanager import (
KeyManager,
openpgp,
KeyNotFound,
+ KeyAttributesDiffer,
errors,
)
from leap.keymanager.openpgp import OpenPGPKey
@@ -477,6 +478,55 @@ class KeyManagerKeyManagementTestCase(KeyManagerWithSoledadTestCase):
self.assertIsInstance(key, OpenPGPKey)
self.assertEqual(ADDRESS, key.address)
+ def test_fetch_uri_ascii_key(self):
+ """
+ Test that fetch key downloads the ascii key and gets included in
+ the local storage
+ """
+ km = self._key_manager()
+
+ class Response(object):
+ ok = True
+ content = PUBLIC_KEY
+
+ km._fetcher.get = Mock(return_value=Response())
+ km.ca_cert_path = 'cacertpath'
+
+ km.fetch_key(ADDRESS, "http://site.domain/key", OpenPGPKey)
+ key = km.get_key(ADDRESS, OpenPGPKey)
+ self.assertEqual(KEY_FINGERPRINT, key.fingerprint)
+
+ def test_fetch_uri_empty_key(self):
+ """
+ Test that fetch key raises KeyNotFound if no key in the url
+ """
+ km = self._key_manager()
+
+ class Response(object):
+ ok = True
+ content = ""
+
+ km._fetcher.get = Mock(return_value=Response())
+ km.ca_cert_path = 'cacertpath'
+ self.assertRaises(KeyNotFound, km.fetch_key,
+ ADDRESS, "http://site.domain/key", OpenPGPKey)
+
+ def test_fetch_uri_address_differ(self):
+ """
+ Test that fetch key raises KeyAttributesDiffer if the address
+ don't match
+ """
+ km = self._key_manager()
+
+ class Response(object):
+ ok = True
+ content = PUBLIC_KEY
+
+ km._fetcher.get = Mock(return_value=Response())
+ km.ca_cert_path = 'cacertpath'
+ self.assertRaises(KeyAttributesDiffer, km.fetch_key,
+ ADDRESS_2, "http://site.domain/key", OpenPGPKey)
+
class KeyManagerCryptoTestCase(KeyManagerWithSoledadTestCase):