summaryrefslogtreecommitdiff
path: root/tests/test_auth.py
diff options
context:
space:
mode:
authorMichael Vogt <michael.vogt@ubuntu.com>2012-10-15 10:58:42 +0200
committerMichael Vogt <michael.vogt@ubuntu.com>2012-10-15 10:58:42 +0200
commit2e754964b0570ff72c82aa012142adf504e01f0e (patch)
treea6cf324f43fe5fd11a5651c6f8186a987a1da922 /tests/test_auth.py
parent43d87e1b14719750585412ab1d15fc30e280b7d0 (diff)
parent7bd938dd78ab27ec23ffd84811dbdfa5dd83593a (diff)
downloadpython-apt-2e754964b0570ff72c82aa012142adf504e01f0e.tar.gz
merge from the debian-sid branch
Diffstat (limited to 'tests/test_auth.py')
-rw-r--r--tests/test_auth.py29
1 files changed, 27 insertions, 2 deletions
diff --git a/tests/test_auth.py b/tests/test_auth.py
index 99c40db5..2b524d28 100644
--- a/tests/test_auth.py
+++ b/tests/test_auth.py
@@ -14,6 +14,13 @@ else:
from BaseHTTPServer import HTTPServer
from SimpleHTTPServer import SimpleHTTPRequestHandler as HTTPRequestHandler
+
+if sys.version_info[0] == 2 and sys.version_info[1] == 6:
+ from unittest2 import TestCase
+else:
+ from unittest import TestCase
+
+
import apt_pkg
import apt.auth
@@ -103,7 +110,7 @@ DHcut3Yey8o=
-----END PGP PUBLIC KEY BLOCK-----"""
-class TestAuthKeys(unittest.TestCase):
+class TestAuthKeys(TestCase):
"""Test handling of keys for signed repositories."""
@@ -185,12 +192,30 @@ class TestAuthKeys(unittest.TestCase):
self.assertEqual(key.keyid, "46925553")
self.assertEqual(key.date, "2012-04-27")
+ def test_add_key_from_keyserver_too_short(self):
+ """Ensure that short keyids are not imported"""
+ with self.assertRaises(apt.auth.AptKeyError):
+ apt.auth.add_key_from_keyserver("46925553", "hkp://localhost:19191")
+
+ def test_add_key_from_server_mitm(self):
+ """Verify that the key fingerprint is verified after download"""
+ self._start_keyserver()
+ self.addCleanup(self._stop_keyserver)
+ with self.assertRaises(apt.auth.AptKeyError) as cm:
+ apt.auth.add_key_from_keyserver(
+ "0101010178F7FE5C3E65D8AF8B48AD6246925553",
+ "hkp://localhost:19191")
+ self.assertTrue(
+ str(cm.exception).startswith("Fingerprints do not match"))
+
def testAddKeyFromServer(self):
"""Install a GnuPG key from a remote server."""
self._start_keyserver()
self.addCleanup(self._stop_keyserver)
- apt.auth.add_key_from_keyserver("46925553", "hkp://localhost:19191")
+ apt.auth.add_key_from_keyserver(
+ "0xa1bD8E9D78F7FE5C3E65D8AF8B48AD6246925553",
+ "hkp://localhost:19191")
ret = apt.auth.list_keys()
self.assertEqual(len(ret), 1)