From 002bfd6cfe5ff869a264e35a97f73b36840d901f Mon Sep 17 00:00:00 2001 From: Sebastian Heinlein Date: Fri, 1 Jun 2012 07:48:11 +0200 Subject: Add test cases --- tests/test_auth.py | 210 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 210 insertions(+) create mode 100644 tests/test_auth.py (limited to 'tests/test_auth.py') diff --git a/tests/test_auth.py b/tests/test_auth.py new file mode 100644 index 00000000..f63d57f3 --- /dev/null +++ b/tests/test_auth.py @@ -0,0 +1,210 @@ +#!/usr/bin/env python + +import os +import shutil +import sys +import tempfile +import time +import unittest + +if sys.version_info.major > 2: + from http.server import HTTPServer + from http.server import SimpleHTTPRequestHandler as HTTPRequestHandler +else: + from SimpleHTTPServer import BaseHTTPServer as HTTPServer + from SimpleHTTPServer import SimpleHTTPRequestHandler as HTTPRequestHandler + +from test_all import get_library_dir +sys.path.insert(0, get_library_dir()) + +import apt_pkg +import apt.auth + +WHEEZY_KEY = """-----BEGIN PGP PUBLIC KEY BLOCK----- +Version: GnuPG v1.4.12 (GNU/Linux) + +mQINBE+a7rUBEADQiEKtLOgqiq8YY/p7IFODMqGPR+o1vtXaksie8iTOh3Vxab38 +cA3kK1iB5XYElbZ5b/x3vWiufHK2semOpn5MG2GRJUwmKxZbt3HLZiHtAadkby2l +rnMxeIzfxcTxloxsQ02TMRalq89Xvy6P7lgedcW5ujcMR6JbE6uL1c/jNlkIPNuN +9paZsNJWXnZ03R+NrAJLjOPUZKZRPYgIwEci2sVNA/autsJL+HuW6X8PfldvMe5h +SdWelOoXMsZMX04JP8Efq8a09yIgKBfuXjoHJbtK0rTr9tjFKt/VM6MejLdJf4Dl +r6Zhx2ygmjcvj+FlWFoxDlPHdqfZ6mGsKR4eWDRu3bZtalDNvhZKvecwf0KaAWVU +M+GxkR+Ol3TsQ0tLbjbwZhWMioipR8Lsp6kZ1tLUjM0aOR3Mw/csyFJYKFiCo3GR +QSGY0++cDrfhQRwOJ9s2eeGGS1/I95vJZA5zZn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Vw +SUo6KX8xBmRoo1W32pk5t9I8uMWMVc3cVh4QhqlKmcjtTJkRIVCNCXZl5JN2Uw8q +uP6thFNCsJx6g8UwaHRXJZNKyANfe8CFGuNO0/9i8sMP/lRxmhxb5+CgZQKmCBjq +eL/TOavRJVXbilVsU4j9OFlqx9ptGHfPlfjnIq2Bf9VWJQyS6E64ecqaqc+yqaVf +hd0FMz9hq067VITuG50JeVnmSJK/EVjSgMvxWlSNinMgUjNetrkQTO9OQ0caAGFq +DHcut3Yey8o= +=id4q +-----END PGP PUBLIC KEY BLOCK-----""" + + +class TestAuthKeys(unittest.TestCase): + + """Test handling of keys for signed repositories.""" + + def setUp(self): + self.tmpdir = tempfile.mkdtemp() + apt_pkg.init() + apt_pkg.config.set("Dir", self.tmpdir) + apt_pkg.config.set("Dir::Etc", "etc/apt/") + trustedparts_dir = apt_pkg.config.find_dir("Dir::Etc::Trustedparts") + self.assertTrue(trustedparts_dir.startswith(self.tmpdir)) + os.makedirs(trustedparts_dir) + + def cleanUp(self): + shutil.rmtree(self.tmpdir) + + def testAddAndExportKey(self): + """Add an example key.""" + apt.auth.add_key(WHEEZY_KEY) + self.assertEqual(apt.auth.export_key("46925553"), + WHEEZY_KEY) + + def testAddAndListKey(self): + """Add an example key and test if it is correctly returned by + list_keys() + """ + apt.auth.add_key(WHEEZY_KEY) + ret = apt.auth.list_keys() + self.assertEqual(len(ret), 1) + key = ret[0] + self.assertEqual(key.name, + "Debian Archive Automatic Signing Key (7.0/wheezy) " + "") + self.assertEqual(key.keyid, "46925553") + self.assertEqual(key.date, "2012-04-27") + + def testAddKeyFromFile(self): + """Test adding a key from file.""" + keyfd, keyname = tempfile.mkstemp() + self.addCleanup(os.close, keyfd) + os.write(keyfd, WHEEZY_KEY) + + apt.auth.add_key_from_file(keyname) + + ret = apt.auth.list_keys() + self.assertEqual(len(ret), 1) + key = ret[0] + self.assertEqual(key.name, + "Debian Archive Automatic Signing Key (7.0/wheezy) " + "") + self.assertEqual(key.keyid, "46925553") + self.assertEqual(key.date, "2012-04-27") + + 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") + + ret = apt.auth.list_keys() + self.assertEqual(len(ret), 1) + key = ret[0] + self.assertEqual(key.name, + "Debian Archive Automatic Signing Key (7.0/wheezy) " + "") + self.assertEqual(key.keyid, "46925553") + self.assertEqual(key.date, "2012-04-27") + + def _start_keyserver(self): + """Start a fake keyserver on http://localhost:19191 + Thanks pitti. + """ + dir = tempfile.mkdtemp() + self.addCleanup(shutil.rmtree, dir) + os.mkdir(os.path.join(dir, "pks")) + with open(os.path.join(dir, "pks", "lookup"), "w") as key_file: + key_file.write(WHEEZY_KEY) + + self.keyserver_pid = os.fork() + if self.keyserver_pid == 0: + # quiesce server log + os.dup2(os.open('/dev/null', os.O_WRONLY), sys.stderr.fileno()) + os.chdir(dir) + httpd = HTTPServer.HTTPServer(('localhost', 19191), + HTTPRequestHandler) + httpd.serve_forever() + os._exit(0) + + # wait a bit until server is ready + time.sleep(0.5) + + def _stop_keyserver(self): + '''Stop fake keyserver''' + assert self.keyserver_pid + + os.kill(self.keyserver_pid, 15) + os.wait() + + +if __name__ == "__main__": + unittest.main() -- cgit v1.2.3 From cc9c9e8e252b311439cec84a99d84707b84e619f Mon Sep 17 00:00:00 2001 From: Sebastian Heinlein Date: Fri, 1 Jun 2012 08:15:34 +0200 Subject: Python3 fixes and restore apt configuration afterwards --- tests/test_auth.py | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) (limited to 'tests/test_auth.py') diff --git a/tests/test_auth.py b/tests/test_auth.py index f63d57f3..4c71d413 100644 --- a/tests/test_auth.py +++ b/tests/test_auth.py @@ -11,7 +11,7 @@ if sys.version_info.major > 2: from http.server import HTTPServer from http.server import SimpleHTTPRequestHandler as HTTPRequestHandler else: - from SimpleHTTPServer import BaseHTTPServer as HTTPServer + from BaseHTTPServer import HTTPServer from SimpleHTTPServer import SimpleHTTPRequestHandler as HTTPRequestHandler from test_all import get_library_dir @@ -111,16 +111,26 @@ class TestAuthKeys(unittest.TestCase): """Test handling of keys for signed repositories.""" def setUp(self): + # reset any config manipulations done in the individual tests + apt_pkg.init_config() + # save the apt config to restore later + cnf = {} + for item in apt_pkg.config.keys(): + cnf[item] = apt_pkg.config.find(item) + self.addCleanup(self._restore_apt_config, cnf) + self.tmpdir = tempfile.mkdtemp() - apt_pkg.init() + self.addCleanup(shutil.rmtree, self.tmpdir) apt_pkg.config.set("Dir", self.tmpdir) apt_pkg.config.set("Dir::Etc", "etc/apt/") trustedparts_dir = apt_pkg.config.find_dir("Dir::Etc::Trustedparts") self.assertTrue(trustedparts_dir.startswith(self.tmpdir)) os.makedirs(trustedparts_dir) - def cleanUp(self): - shutil.rmtree(self.tmpdir) + def _restore_apt_config(self, cnf): + """Restore previous apt configuration.""" + for item in cnf: + apt_pkg.config.set(item, cnf[item]) def testAddAndExportKey(self): """Add an example key.""" @@ -146,7 +156,7 @@ class TestAuthKeys(unittest.TestCase): """Test adding a key from file.""" keyfd, keyname = tempfile.mkstemp() self.addCleanup(os.close, keyfd) - os.write(keyfd, WHEEZY_KEY) + os.write(keyfd, WHEEZY_KEY.encode("UTF-8")) apt.auth.add_key_from_file(keyname) @@ -190,8 +200,7 @@ class TestAuthKeys(unittest.TestCase): # quiesce server log os.dup2(os.open('/dev/null', os.O_WRONLY), sys.stderr.fileno()) os.chdir(dir) - httpd = HTTPServer.HTTPServer(('localhost', 19191), - HTTPRequestHandler) + httpd = HTTPServer(('localhost', 19191), HTTPRequestHandler) httpd.serve_forever() os._exit(0) -- cgit v1.2.3 From 56be4293b0e639b58904d1d86dd46f8767d36728 Mon Sep 17 00:00:00 2001 From: Sebastian Heinlein Date: Fri, 1 Jun 2012 08:26:30 +0200 Subject: Remove importing of the library dir. This is handled by test_all --- tests/test_auth.py | 3 --- 1 file changed, 3 deletions(-) (limited to 'tests/test_auth.py') diff --git a/tests/test_auth.py b/tests/test_auth.py index 4c71d413..e9906f56 100644 --- a/tests/test_auth.py +++ b/tests/test_auth.py @@ -14,9 +14,6 @@ else: from BaseHTTPServer import HTTPServer from SimpleHTTPServer import SimpleHTTPRequestHandler as HTTPRequestHandler -from test_all import get_library_dir -sys.path.insert(0, get_library_dir()) - import apt_pkg import apt.auth -- cgit v1.2.3 From 621372f543a4d0547f3637889da11665b628df14 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Tue, 5 Jun 2012 11:39:40 +0200 Subject: pep8 fixes --- apt/auth.py | 14 +++++++++++--- tests/test_auth.py | 6 +++--- 2 files changed, 14 insertions(+), 6 deletions(-) (limited to 'tests/test_auth.py') diff --git a/apt/auth.py b/apt/auth.py index 024f01da..04aae908 100644 --- a/apt/auth.py +++ b/apt/auth.py @@ -7,11 +7,11 @@ # Author: Michael Vogt # Sebastian Heinlein # -# This program is free software; you can redistribute it and/or -# modify it under the terms of the GNU General Public License as +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License as # published by the Free Software Foundation; either version 2 of the # License, or (at your option) any later version. -# +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the @@ -84,6 +84,7 @@ def _get_gpg_command(keyring=None): "--trustdb-name", os.path.join(_TMPDIR, "trustdb.gpg")]) return cmd + def _wait_and_raise(proc): """Wait until the given subprocess is completed and raise a SystemError if it failed. @@ -92,6 +93,7 @@ def _wait_and_raise(proc): output = proc.stdout.read() raise SystemError("GnuPG command failed: %s" % output) + def add_key_from_file(filename, wait=True): """Import a GnuPG key file to trust repositores signed by it. @@ -115,6 +117,7 @@ def add_key_from_file(filename, wait=True): else: return proc + def add_key_from_keyserver(keyid, keyserver, wait=True): """Import a GnuPG key file to trust repositores signed by it. @@ -137,6 +140,7 @@ def add_key_from_keyserver(keyid, keyserver, wait=True): else: return proc + def add_key(content, wait=True): """Import a GnuPG key to trust repositores signed by it. @@ -159,6 +163,7 @@ def add_key(content, wait=True): else: return proc + def remove_key(fingerprint, wait=True): """Remove a GnuPG key to no longer trust repositores signed by it. @@ -178,6 +183,7 @@ def remove_key(fingerprint, wait=True): else: return proc + def export_key(fingerprint, wait=True): """Return the GnuPG key in text format. @@ -198,6 +204,7 @@ def export_key(fingerprint, wait=True): else: return proc + def list_keys(): """Returns a list of TrustedKey instances for each key which is used to trust repositories. @@ -216,6 +223,7 @@ def list_keys(): res.append(key) return res + if __name__ == "__main__": # Add some known keys we would like to see translated so that they get # picked up by gettext diff --git a/tests/test_auth.py b/tests/test_auth.py index e9906f56..7ecebb7b 100644 --- a/tests/test_auth.py +++ b/tests/test_auth.py @@ -125,9 +125,9 @@ class TestAuthKeys(unittest.TestCase): os.makedirs(trustedparts_dir) def _restore_apt_config(self, cnf): - """Restore previous apt configuration.""" - for item in cnf: - apt_pkg.config.set(item, cnf[item]) + """Restore previous apt configuration.""" + for item in cnf: + apt_pkg.config.set(item, cnf[item]) def testAddAndExportKey(self): """Add an example key.""" -- cgit v1.2.3 From 01e32f901a8125d840cbf501ee935f0bba483234 Mon Sep 17 00:00:00 2001 From: Sebastian Heinlein Date: Wed, 6 Jun 2012 12:18:46 +0200 Subject: Create the config dir in the tests --- tests/test_auth.py | 2 ++ 1 file changed, 2 insertions(+) (limited to 'tests/test_auth.py') diff --git a/tests/test_auth.py b/tests/test_auth.py index 7ecebb7b..6965dfed 100644 --- a/tests/test_auth.py +++ b/tests/test_auth.py @@ -121,8 +121,10 @@ class TestAuthKeys(unittest.TestCase): apt_pkg.config.set("Dir", self.tmpdir) apt_pkg.config.set("Dir::Etc", "etc/apt/") trustedparts_dir = apt_pkg.config.find_dir("Dir::Etc::Trustedparts") + confparts_dir = apt_pkg.config.find_dir("Dir::Etc::parts") self.assertTrue(trustedparts_dir.startswith(self.tmpdir)) os.makedirs(trustedparts_dir) + os.makedirs(confparts_dir) def _restore_apt_config(self, cnf): """Restore previous apt configuration.""" -- cgit v1.2.3 From 6f8b10fe939609a1afc8de057813e1d43bc47558 Mon Sep 17 00:00:00 2001 From: Sebastian Heinlein Date: Wed, 6 Jun 2012 12:53:44 +0200 Subject: Add a fakeroot wrapper for apt-key --- tests/fakeroot-apt-key | 2 ++ tests/test_auth.py | 2 ++ 2 files changed, 4 insertions(+) create mode 100755 tests/fakeroot-apt-key (limited to 'tests/test_auth.py') diff --git a/tests/fakeroot-apt-key b/tests/fakeroot-apt-key new file mode 100755 index 00000000..7be99711 --- /dev/null +++ b/tests/fakeroot-apt-key @@ -0,0 +1,2 @@ +#!/bin/sh +fakeroot /usr/bin/apt-key $* diff --git a/tests/test_auth.py b/tests/test_auth.py index 6965dfed..fc37830d 100644 --- a/tests/test_auth.py +++ b/tests/test_auth.py @@ -119,12 +119,14 @@ class TestAuthKeys(unittest.TestCase): self.tmpdir = tempfile.mkdtemp() self.addCleanup(shutil.rmtree, self.tmpdir) apt_pkg.config.set("Dir", self.tmpdir) + apt_pkg.config.set("Dir::Bin::Apt-key", "fakeroot-apt-key") apt_pkg.config.set("Dir::Etc", "etc/apt/") trustedparts_dir = apt_pkg.config.find_dir("Dir::Etc::Trustedparts") confparts_dir = apt_pkg.config.find_dir("Dir::Etc::parts") self.assertTrue(trustedparts_dir.startswith(self.tmpdir)) os.makedirs(trustedparts_dir) os.makedirs(confparts_dir) + shutil.copy("fakeroot-apt-key", self.tmpdir) def _restore_apt_config(self, cnf): """Restore previous apt configuration.""" -- cgit v1.2.3 From 5d16e033da495dd835d9a870b82f77a6486b4f14 Mon Sep 17 00:00:00 2001 From: Sebastian Heinlein Date: Wed, 6 Jun 2012 12:58:43 +0200 Subject: Don't compare the headers in the export test --- tests/test_auth.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'tests/test_auth.py') diff --git a/tests/test_auth.py b/tests/test_auth.py index fc37830d..f975c670 100644 --- a/tests/test_auth.py +++ b/tests/test_auth.py @@ -136,8 +136,11 @@ class TestAuthKeys(unittest.TestCase): def testAddAndExportKey(self): """Add an example key.""" apt.auth.add_key(WHEEZY_KEY) - self.assertEqual(apt.auth.export_key("46925553"), - WHEEZY_KEY) + # Strip the headers from the keys to avoid test errors because + # the exported key used a differenct GnuPG version than the + # original example key + self.assertEqual(apt.auth.export_key("46925553").split("\n")[2:], + WHEEZY_KEY.split("\n")[2:]) def testAddAndListKey(self): """Add an example key and test if it is correctly returned by -- cgit v1.2.3 From 653444b666238fb1a991821e8b0cce1a9cb2513f Mon Sep 17 00:00:00 2001 From: Julian Andres Klode Date: Fri, 22 Jun 2012 10:36:30 +0200 Subject: * tests: - Fix new tests from Sebastian to work with Python 2.6 --- debian/changelog | 2 ++ tests/test_auth.py | 14 +++++++++++++- tests/test_lp659438.py | 4 ++-- 3 files changed, 17 insertions(+), 3 deletions(-) (limited to 'tests/test_auth.py') diff --git a/debian/changelog b/debian/changelog index 5833d94c..5f368b3a 100644 --- a/debian/changelog +++ b/debian/changelog @@ -62,6 +62,8 @@ python-apt (0.8.5) UNRELEASED; urgency=low - Set Standards-Version to 3.9.3 * utils/get_ubuntu_mirrors_from_lp.py: - Revert move to Python 3, python3-feedparser is not in the archive yet + * tests: + - Fix new tests from Sebastian to work with Python 2.6 -- Michael Vogt Tue, 17 Apr 2012 14:09:24 +0200 diff --git a/tests/test_auth.py b/tests/test_auth.py index f975c670..99c40db5 100644 --- a/tests/test_auth.py +++ b/tests/test_auth.py @@ -7,7 +7,7 @@ import tempfile import time import unittest -if sys.version_info.major > 2: +if sys.version_info[0] > 2: from http.server import HTTPServer from http.server import SimpleHTTPRequestHandler as HTTPRequestHandler else: @@ -107,6 +107,18 @@ class TestAuthKeys(unittest.TestCase): """Test handling of keys for signed repositories.""" + if sys.version_info[0] == 2 and sys.version_info[1] < 7: + def addCleanup(self, function, *args, **kwds): + try: + self.cleanup.append(lambda: function(*args, **kwds)) + except AttributeError: + self.cleanup = [lambda: function(*args, **kwds)] + + def tearDown(self): + for f in self.cleanup: + f() + self.cleanup = [] + def setUp(self): # reset any config manipulations done in the individual tests apt_pkg.init_config() diff --git a/tests/test_lp659438.py b/tests/test_lp659438.py index 01edf3bd..4564f0f6 100644 --- a/tests/test_lp659438.py +++ b/tests/test_lp659438.py @@ -39,8 +39,7 @@ class RegressionTestCase(unittest.TestCase): def setUp(self): apt_pkg.init_config() - chroot_path = tempfile.mkdtemp() - self.addCleanup(lambda: shutil.rmtree(chroot_path)) + self.chroot_path = chroot_path = tempfile.mkdtemp() # Create a damaged status file self.cache = apt.cache.Cache(rootdir=chroot_path) with open(apt_pkg.config.find_file("Dir::State::status"), @@ -62,6 +61,7 @@ Version: 3.6.9+build1+nobinonly-0ubuntu1""") # this resets the rootdir apt_pkg.config to ensure it does not # "pollute" the later tests cache = apt.cache.Cache(rootdir="/") + shutil.rmtree(self.chroot_path) def test_survive_reqreinst(self): """Test that we survive a package in require reinstallation state""" -- cgit v1.2.3