diff options
| author | Michael Vogt <michael.vogt@ubuntu.com> | 2012-10-17 10:08:36 +0200 |
|---|---|---|
| committer | Michael Vogt <michael.vogt@ubuntu.com> | 2012-10-17 10:08:36 +0200 |
| commit | 718409afe561f7dfc7407214685ccbfacdf31631 (patch) | |
| tree | 837b8b6e1539c1bb976137012ca2c12350dc5150 | |
| parent | 5384546c17c80b809791ef95ac357bc017be83f9 (diff) | |
| parent | 7bd938dd78ab27ec23ffd84811dbdfa5dd83593a (diff) | |
| download | python-apt-718409afe561f7dfc7407214685ccbfacdf31631.tar.gz | |
merged debian-sid branch
| -rw-r--r-- | apt/auth.py | 83 | ||||
| -rw-r--r-- | apt/debfile.py | 1 | ||||
| -rw-r--r-- | aptsources/sourceslist.py | 2 | ||||
| -rw-r--r-- | debian/changelog | 47 | ||||
| -rw-r--r-- | debian/control | 3 | ||||
| -rw-r--r-- | po/da.po | 99 | ||||
| -rw-r--r-- | python/cache.cc | 2 | ||||
| -rw-r--r-- | python/progress.cc | 2 | ||||
| -rw-r--r-- | python/string.cc | 28 | ||||
| -rw-r--r-- | python/tag.cc | 4 | ||||
| -rw-r--r-- | tests/test_aptsources.py | 14 | ||||
| -rw-r--r-- | tests/test_auth.py | 29 | ||||
| -rw-r--r-- | tests/test_size_to_str.py | 112 |
13 files changed, 341 insertions, 85 deletions
diff --git a/apt/auth.py b/apt/auth.py index e088ae85..eff13b1a 100644 --- a/apt/auth.py +++ b/apt/auth.py @@ -27,6 +27,7 @@ import atexit import os import os.path +import shutil import subprocess import sys import tempfile @@ -35,6 +36,10 @@ import apt_pkg from apt_pkg import gettext as _ +class AptKeyError(Exception): + pass + + class TrustedKey(object): """Represents a trusted key.""" @@ -79,7 +84,7 @@ def _call_apt_key_script(*args, **kwargs): output, stderr = proc.communicate(content) if proc.returncode: - raise SystemError("The apt-key script failed with return code %s:\n" + raise AptKeyError("The apt-key script failed with return code %s:\n" "%s\n" "stdout: %s\n" "stderr: %s" % (proc.returncode, " ".join(cmd), @@ -99,20 +104,86 @@ def add_key_from_file(filename): filename -- the absolute path to the public GnuPG key file """ if not os.path.abspath(filename): - raise SystemError("An absolute path is required: %s" % filename) + raise AptKeyError("An absolute path is required: %s" % filename) if not os.access(filename, os.R_OK): - raise SystemError("Key file cannot be accessed: %s" % filename) + raise AptKeyError("Key file cannot be accessed: %s" % filename) _call_apt_key_script("add", filename) def add_key_from_keyserver(keyid, keyserver): """Import a GnuPG key file to trust repositores signed by it. Keyword arguments: - keyid -- the identifier of the key, e.g. 0x0EB12DSA + keyid -- the long keyid (fingerprint) of the key, e.g. + A1BD8E9D78F7FE5C3E65D8AF8B48AD6246925553 keyserver -- the URL or hostname of the key server """ - _call_apt_key_script("adv", "--quiet", "--keyserver", keyserver, - "--recv", keyid) + tmp_keyring_dir = tempfile.mkdtemp() + try: + _add_key_from_keyserver(keyid, keyserver, tmp_keyring_dir) + except: + raise + finally: + shutil.rmtree(tmp_keyring_dir) + +def _add_key_from_keyserver(keyid, keyserver, tmp_keyring_dir): + if len(keyid) < 160/8: + raise AptKeyError("Only long keyids (v4, 160bit) are supported") + # create a temp keyring dir + tmp_secret_keyring = os.path.join(tmp_keyring_dir, "secring.gpg") + tmp_keyring = os.path.join(tmp_keyring_dir, "pubring.gpg") + # default options for gpg + gpg_default_options = [ + "gpg", + "--no-default-keyring", "--no-options", + "--homedir", tmp_keyring_dir, + ] + # download the key to a temp keyring first + res = subprocess.call(gpg_default_options + [ + "--secret-keyring", tmp_secret_keyring, + "--keyring", tmp_keyring, + "--keyserver", keyserver, + "--recv", keyid, + ]) + if res != 0: + raise AptKeyError("recv from '%s' failed for '%s'" % ( + keyserver, keyid)) + # now export again using the long key id (to ensure that there is + # really only this one key in our keyring) and not someone MITM us + tmp_export_keyring = os.path.join(tmp_keyring_dir, "export-keyring.gpg") + res = subprocess.call(gpg_default_options + [ + "--keyring", tmp_keyring, + "--output", tmp_export_keyring, + "--export", keyid, + ]) + if res != 0: + raise AptKeyError("export of '%s' failed", keyid) + # now verify the fingerprint, this is probably redundant as we + # exported by the fingerprint in the previous command but its + # still good paranoia + output = subprocess.Popen( + gpg_default_options + [ + "--keyring", tmp_export_keyring, + "--fingerprint", + "--batch", + "--with-colons", + ], + stdout=subprocess.PIPE, + universal_newlines=True).communicate()[0] + got_fingerprint=None + for line in output.splitlines(): + if line.startswith("fpr:"): + got_fingerprint = line.split(":")[9] + # stop after the first to ensure no subkey trickery + break + # strip the leading "0x" is there is one and uppercase (as this is + # what gnupg is using) + signing_key_fingerprint = keyid.replace("0x", "").upper() + if got_fingerprint != signing_key_fingerprint: + raise AptKeyError( + "Fingerprints do not match, not importing: '%s' != '%s'" % ( + signing_key_fingerprint, got_fingerprint)) + # finally add it + add_key_from_file(tmp_export_keyring) def add_key(content): """Import a GnuPG key to trust repositores signed by it. diff --git a/apt/debfile.py b/apt/debfile.py index 2eb807b8..1ebbea32 100644 --- a/apt/debfile.py +++ b/apt/debfile.py @@ -104,6 +104,7 @@ class DebPackage(object): elif self._cache.is_virtual_package(pkgname): return pkgname elif (pkgname in self._cache and + self._cache[pkgname].candidate and self._cache[pkgname].candidate.architecture == "all"): return pkgname # now do the real multiarch checking diff --git a/aptsources/sourceslist.py b/aptsources/sourceslist.py index 61b75f75..40902d84 100644 --- a/aptsources/sourceslist.py +++ b/aptsources/sourceslist.py @@ -313,7 +313,7 @@ class SourcesList(object): for source in sources: # if there is a repo with the same (type, uri, dist) just add the # components - if source.disabled and set(source.comps) == comps: + if source.disabled and set(source.comps) == set(comps): source.disabled = False return source elif not source.disabled: diff --git a/debian/changelog b/debian/changelog index 9cfaacf0..7a748e6f 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,13 +1,52 @@ -python-apt (0.8.8) UNRELEASED; urgency=low +python-apt (0.8.8.1) UNRELEASED; urgency=low + + * python/tag.cc: + - make TagSecString_FromStringAndSize, TagSecString_FromString + static, thanks to jcristau + * python/cache.cc: + - add "Codename" to PackageFile object + + -- Michael Vogt <michael.vogt@ubuntu.com> Mon, 15 Oct 2012 10:03:21 +0200 + +python-apt (0.8.8) unstable; urgency=low [ Program translation updates ] * po/pl.po: Polish (Michał Kułach) (closes: #684308) + * po/da.po: Danish (Joe Hansen) (closes: #689827) [ Michael Vogt ] - * python/cache.cc: - - add "Codename" to PackageFile object + * merged lp:~sampo555/python-apt/fix_1042916 reuse existing but + disabled sources.list entries instead of duplicating them. + Thanks to "sampo555", LP: #1042916 + * lp:~mvo/python-apt/fix-debfile-crash: + - fix crash on missing candidates in the multiarch check + * lp:~mvo/python-apt/recv-key-lp1016643: + - Only support long (v4) keyids when downloading keys and + check the keys fingerprint before importing. This avoids + man-in-the-middle attacks (LP: #1016643) + * consolidate tests/test_lp1030278.py into the new + tests/test_size_to_str.py + * apt/auth.py: + - support importing long keyids with leading 0x and mixed case + * debian/control: + - build-depend on python-unittest2 to get "with TestCase.assertRaises" + support in python2.6 + + [ Barry Warsaw ] + * python/string.cc, tests/test_lp1030278.py: Fix StrSizeToStr() so that + 1) it first checks for PyLong-ness so that in Python 3 on i386, it + will be able to convert larger numbers (via doubles rather than ints); + 2) before doing the conversions through the apt API, check to see if a + Python exception occurred, e.g. OverflowError, and return an error + condition in that case instead of masking it. (LP: #1030278) + + [ James Hunt ] + * python/cache.cc: PkgCacheGetIsMultiArch(): Return calculated + value rather than a random one. + * lp:~jamesodhunt/python-apt/test-for-size_to_str: + - add test for size_to_str() to help with finding LP: #1030278 - -- David Prévot <taffit@debian.org> Wed, 08 Aug 2012 12:05:52 -0400 + -- Michael Vogt <mvo@debian.org> Fri, 12 Oct 2012 10:47:11 +0200 python-apt (0.8.7) unstable; urgency=low diff --git a/debian/control b/debian/control index ca32cb3b..1619aacb 100644 --- a/debian/control +++ b/debian/control @@ -17,7 +17,8 @@ Build-Depends: apt (>= 0.9.6), python3-all-dbg (>= 3.1.2-6~), python-distutils-extra (>= 2.0), python-sphinx (>= 0.5), - python-debian + python-debian, + python-unittest2 Vcs-Bzr: http://bzr.debian.org/apt/python-apt/debian-sid Vcs-Browser: http://bzr.debian.org/loggerhead/apt/python-apt/debian-sid/changes @@ -1,20 +1,20 @@ # Danish translation python-apt. -# Copyright (C) 2011 python-apt & nedenstående oversætttere. +# Copyright (C) 2012 python-apt & nedenstående oversætttere. # This file is distributed under the same license as the python-apt package. # Mads Bille Lundby <lundbymads@gmail.com>, 2009. # AJenbo <anders@jenbo.dk>, 2011. # Ask, 2011. -# Joe Hansen <joedalton2@yahoo.dk>, 2011. +# Joe Hansen <joedalton2@yahoo.dk>, 2011, 2012. # msgid "" msgstr "" "Project-Id-Version: python-apt\n" "Report-Msgid-Bugs-To: \n" "POT-Creation-Date: 2012-06-25 14:31+0200\n" -"PO-Revision-Date: 2011-06-22 14:44+0200\n" +"PO-Revision-Date: 2012-10-06 14:44+0200\n" "Last-Translator: Joe Hansen <joedalton2@yahoo.dk>\n" -"Language-Team: Danish <debian-l10n-danish@lists.debian.org> \n" -"Language: \n" +"Language-Team: Danish <debian-l10n-danish@lists.debian.org>\n" +"Language: da\n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" @@ -27,103 +27,83 @@ msgstr "http://changelogs.ubuntu.com/changelogs/pool/%s/%s/%s/%s_%s/changelog" #. Description #: ../data/templates/Ubuntu.info.in:151 -#, fuzzy -#| msgid "Ubuntu 7.04 'Feisty Fawn'" msgid "Ubuntu 12.04 'Precise Pangolin'" -msgstr "Ubuntu 7.04 \"Feisty Fawn\"" +msgstr "Ubuntu 12.04 \"Precise Pangolin\"" #. Description #: ../data/templates/Ubuntu.info.in:158 -#, fuzzy -#| msgid "Cdrom with Ubuntu 7.04 'Feisty Fawn'" msgid "Cdrom with Ubuntu 12.04 'Precise Pangolin'" -msgstr "Cd-rom med Ubuntu 7.04 \"Feisty Fawn\"" +msgstr "Cd-rom med Ubuntu 12.04 \"Precise Pangolin\"" #. Description #: ../data/templates/Ubuntu.info.in:269 -#, fuzzy -#| msgid "Ubuntu 9.10 'Karmic Koala'" msgid "Ubuntu 11.10 'Oneiric Ocelot'" -msgstr "Ubuntu 9.10 \"Karmic Koala\"" +msgstr "Ubuntu 11.10 \"Oneiric Ocelot\"" #. Description #: ../data/templates/Ubuntu.info.in:276 -#, fuzzy -#| msgid "Cdrom with Ubuntu 9.10 'Karmic Koala'" msgid "Cdrom with Ubuntu 11.10 'Oneiric Ocelot'" -msgstr "Cd-rom med Ubuntu 9.10 \"Karmic Koala\"" +msgstr "Cd-rom med Ubuntu 11.10 \"Oneiric Ocelot\"" #. Description #: ../data/templates/Ubuntu.info.in:388 -#, fuzzy -#| msgid "Ubuntu 4.10 'Warty Warthog'" msgid "Ubuntu 11.04 'Natty Narwhal'" -msgstr "Ubuntu 4.10 \"Warty Warthog\"" +msgstr "Ubuntu 11.04 \"Natty Narwhal\"" #. Description #: ../data/templates/Ubuntu.info.in:395 -#, fuzzy -#| msgid "Cdrom with Ubuntu 4.10 'Warty Warthog'" msgid "Cdrom with Ubuntu 11.04 'Natty Narwhal'" -msgstr "Cd-rom med Ubuntu 4.10 \"Warty Warthog\"" +msgstr "Cd-rom med Ubuntu 11.04 \"Natty Narwhal\"" #. Description #: ../data/templates/Ubuntu.info.in:486 -#, fuzzy -#| msgid "Ubuntu 9.10 'Karmic Koala'" msgid "Ubuntu 10.10 'Maverick Meerkat'" -msgstr "Ubuntu 9.10 \"Karmic Koala\"" +msgstr "Ubuntu 10.10 \"Maverick Meerkat\"" #. Description #: ../data/templates/Ubuntu.info.in:506 -#, fuzzy -#| msgid "Cdrom with Ubuntu 9.10 'Karmic Koala'" msgid "Cdrom with Ubuntu 10.10 'Maverick Meerkat'" -msgstr "Cd-rom med Ubuntu 9.10 \"Karmic Koala\"" +msgstr "Cd-rom med Ubuntu 10.10 \"Maverick Meerkat\"" #. Description #: ../data/templates/Ubuntu.info.in:518 msgid "Canonical Partners" -msgstr "" +msgstr "Canonicalpartnere" #. CompDescription #: ../data/templates/Ubuntu.info.in:520 msgid "Software packaged by Canonical for their partners" -msgstr "" +msgstr "Programmer pakket af Canonical for deres partnere" #. CompDescriptionLong #: ../data/templates/Ubuntu.info.in:521 msgid "This software is not part of Ubuntu." -msgstr "" +msgstr "Dette program er ikke en del af Ubuntu." #. Description #: ../data/templates/Ubuntu.info.in:528 msgid "Independent" -msgstr "" +msgstr "Uafhængigt" #. CompDescription #: ../data/templates/Ubuntu.info.in:530 msgid "Provided by third-party software developers" -msgstr "" +msgstr "Tilbudt af tredjepartsprogramudviklere" #. CompDescriptionLong #: ../data/templates/Ubuntu.info.in:531 msgid "Software offered by third party developers." -msgstr "" +msgstr "Programmer tilbudt af tredjepartsudviklere." #. Description #: ../data/templates/Ubuntu.info.in:569 -#, fuzzy -#| msgid "Ubuntu 8.04 'Hardy Heron'" msgid "Ubuntu 10.04 'Lucid Lynx'" -msgstr "Ubuntu 8.04 \"Hardy Heron\"" +msgstr "Ubuntu 10.04 \"Lucid Lynx\"" #. Description #: ../data/templates/Ubuntu.info.in:589 -#, fuzzy -#| msgid "Cdrom with Ubuntu 8.04 'Hardy Heron'" msgid "Cdrom with Ubuntu 10.04 'Lucid Lynx'" -msgstr "Cd-rom med Ubuntu 8.04 \"Hardy Heron\"" +msgstr "Cd-rom med Ubuntu 10.04 \"Lucid Lynx\"" #. Description #: ../data/templates/Ubuntu.info.in:632 @@ -212,10 +192,8 @@ msgstr "Ubuntu 6.06 LTS \"Dapper Drake\"" #. CompDescriptionLong #: ../data/templates/Ubuntu.info.in:1075 -#, fuzzy -#| msgid "Canonical-supported Open Source software" msgid "Canonical-supported free and open-source software" -msgstr "Canonical-understøttet software med åben kildekode" +msgstr "Canonical-understøttede frie programmer med åben kildekode" #. CompDescription #: ../data/templates/Ubuntu.info.in:1077 @@ -224,10 +202,8 @@ msgstr "Vedligeholdt af fællesskabet (universe)" #. CompDescriptionLong #: ../data/templates/Ubuntu.info.in:1078 -#, fuzzy -#| msgid "Community-maintained Open Source software" msgid "Community-maintained free and open-source software" -msgstr "Software med åben kildekode vedligeholdt af fællesskabet" +msgstr "Fællesskabsvedligeholdt frie programmer med åben kildekode" #. CompDescription #: ../data/templates/Ubuntu.info.in:1080 @@ -382,10 +358,8 @@ msgstr "http://packages.debian.org/changelogs/pool/%s/%s/%s/%s_%s/changelog" #. Description #: ../data/templates/Debian.info.in:8 -#, fuzzy -#| msgid "Debian 6.0 'Squeeze' " msgid "Debian 7.0 'Wheezy' " -msgstr "Debian 6.0 \"Squeeze\" " +msgstr "Debian 7.0 \"Wheezy\" " #. Description #: ../data/templates/Debian.info.in:33 @@ -514,14 +488,12 @@ msgstr "" "Undersøg venligst din internetforbindelse." #: ../apt/debfile.py:82 -#, fuzzy, python-format -#| msgid "List of files for '%s'could not be read" +#, python-format msgid "List of files for '%s' could not be read" msgstr "Listen over filer for \"%s\" kunne ikke læses" #: ../apt/debfile.py:93 -#, fuzzy, python-format -#| msgid "List of files for '%s'could not be read" +#, python-format msgid "List of control files for '%s' could not be read" msgstr "Listen over filer for \"%s\" kunne ikke læses" @@ -542,6 +514,8 @@ msgid "" "Breaks existing package '%(pkgname)s' dependency %(depname)s " "(%(deprelation)s %(depversion)s)" msgstr "" +"Ødelægger eksisterende pakke \"%(pkgname)s\" afhængighed %(depname)s " +"(%(deprelation)s %(depversion)s)" #. TRANSLATORS: the first '%s' is the package that conflicts, the second the packagename that it conflicts with (so the name of the deb the user tries to install), the third is the relation (e.g. >=) and the last is the version for the relation #: ../apt/debfile.py:389 @@ -550,6 +524,8 @@ msgid "" "Breaks existing package '%(pkgname)s' conflict: %(targetpkg)s (%(comptype)s " "%(targetver)s)" msgstr "" +"Ødelægger eksisterende pakke \"%(pkgname)s\" konflikt %(targetpkg)s (%(comptype)s " +"%(targetver)s)" #: ../apt/debfile.py:399 #, python-format @@ -557,10 +533,12 @@ msgid "" "Breaks existing package '%(pkgname)s' that conflict: '%(targetpkg)s'. But " "the '%(debfile)s' provides it via: '%(provides)s'" msgstr "" +"Ødelægger eksisterende pakke \"%(pkgname)s\" som er i konflikt: \"%(targetpkg)s\". " +"Men \"%(debfile)s\" tilbyder den via: \"%(provides)s\"" #: ../apt/debfile.py:447 msgid "No Architecture field in the package" -msgstr "" +msgstr "Intet arkitekturfelt i pakken" #: ../apt/debfile.py:457 #, python-format @@ -586,15 +564,17 @@ msgid "" "Automatically decompressed:\n" "\n" msgstr "" +"Automatisk pakket ud:\n" +"\n" #: ../apt/debfile.py:599 msgid "Automatically converted to printable ascii:\n" -msgstr "" +msgstr "Automatisk konverteret til udskrivbar ascii:\n" #: ../apt/debfile.py:689 #, python-format msgid "Install Build-Dependencies for source package '%s' that builds %s\n" -msgstr "Installér bygge-afhængigheder til kildepakke \"%s\" der bygger %s\n" +msgstr "Installer byggeafhængigheder for kildepakken \"%s\" der bygger %s\n" #: ../apt/debfile.py:700 msgid "An essential package would be removed" @@ -603,7 +583,7 @@ msgstr "En nødvendig pakke vil blive fjernet" #: ../apt/progress/text.py:82 #, python-format msgid "%c%s... Done" -msgstr "%c%s... Færdig" +msgstr "%c%s ... Færdig" #: ../apt/progress/text.py:122 msgid "Hit " @@ -654,5 +634,4 @@ msgstr "Indsæt en disk i drevet og tryk retur" msgid "Building data structures" msgstr "Opbygger datastrukturer" -#~ msgid "This is not a valid DEB archive, missing '%s' member" -#~ msgstr "Dette er ikke et gyldigt DEB-arkiv, mangler \"%s-medlem\"" + diff --git a/python/cache.cc b/python/cache.cc index a1a865af..e527faba 100644 --- a/python/cache.cc +++ b/python/cache.cc @@ -286,7 +286,7 @@ static PyObject *PkgCacheGetFileList(PyObject *Self, void*) { static PyObject *PkgCacheGetIsMultiArch(PyObject *Self, void*) { pkgCache *Cache = GetCpp<pkgCache *>(Self); - PyBool_FromLong(Cache->MultiArchCache()); + return PyBool_FromLong(Cache->MultiArchCache()); } static PyGetSetDef PkgCacheGetSet[] = { diff --git a/python/progress.cc b/python/progress.cc index a7fd7ae1..9e870875 100644 --- a/python/progress.cc +++ b/python/progress.cc @@ -28,6 +28,8 @@ inline bool setattr(PyObject *object, const char *attr, const char *fmt, T arg) if (!object) return false; PyObject *value = Py_BuildValue(fmt, arg); + if (value == NULL) + return false; int result = PyObject_SetAttrString(object, attr, value); Py_DECREF(value); diff --git a/python/string.cc b/python/string.cc index 7abe2d17..62aa34e7 100644 --- a/python/string.cc +++ b/python/string.cc @@ -64,17 +64,29 @@ MkInt(StrTimeRFC1123,TimeRFC1123, long long, "L"); PyObject *StrSizeToStr(PyObject *Self,PyObject *Args) { PyObject *Obj; + double value; + if (PyArg_ParseTuple(Args,"O",&Obj) == 0) return 0; - if (PyInt_Check(Obj)) - return CppPyString(SizeToStr(PyInt_AsLong(Obj))); + // In Python 3, PyInt_Check is aliased to PyLong_Check and PyInt_AsLong is + // aliased to PyLong_AsLong. Therefore we do the actual long checks first + // so that if it is a long in Python 3, the value will be converted to a + // double rather than a long. This avoids OverflowError regressions in + // Python 3. LP: #1030278 if (PyLong_Check(Obj)) - return CppPyString(SizeToStr(PyLong_AsDouble(Obj))); - if (PyFloat_Check(Obj)) - return CppPyString(SizeToStr(PyFloat_AsDouble(Obj))); - - PyErr_SetString(PyExc_TypeError,"Only understand integers and floats"); - return 0; + value = PyLong_AsDouble(Obj); + else if (PyInt_Check(Obj)) + value = PyInt_AsLong(Obj); + else if (PyFloat_Check(Obj)) + value = PyFloat_AsDouble(Obj); + else { + PyErr_SetString(PyExc_TypeError,"Only understand integers and floats"); + return 0; + } + // Check for OverflowErrors or other exceptions during conversion. + if (PyErr_Occurred()) + return 0; + return CppPyString(SizeToStr(value)); } PyObject *StrQuoteString(PyObject *Self,PyObject *Args) diff --git a/python/tag.cc b/python/tag.cc index 248d818d..6ae439f5 100644 --- a/python/tag.cc +++ b/python/tag.cc @@ -74,7 +74,7 @@ int TagFileClear(PyObject *self) { PyString_FromStringAndSize((v), (len)) #define TagSecString_FromString(self, v) PyString_FromString(v) #else -PyObject *TagSecString_FromStringAndSize(PyObject *self, const char *v, +static PyObject *TagSecString_FromStringAndSize(PyObject *self, const char *v, Py_ssize_t len) { TagSecData *Self = (TagSecData *)self; if (Self->Bytes) @@ -85,7 +85,7 @@ PyObject *TagSecString_FromStringAndSize(PyObject *self, const char *v, return PyUnicode_FromStringAndSize(v, len); } -PyObject *TagSecString_FromString(PyObject *self, const char *v) { +static PyObject *TagSecString_FromString(PyObject *self, const char *v) { TagSecData *Self = (TagSecData *)self; if (Self->Bytes) return PyBytes_FromString(v); diff --git a/tests/test_aptsources.py b/tests/test_aptsources.py index dcfb0682..41cfabb3 100644 --- a/tests/test_aptsources.py +++ b/tests/test_aptsources.py @@ -233,6 +233,20 @@ class TestAptSources(unittest.TestCase): for key in found: self.assertEqual(found[key], 1) + def test_enable_disabled(self): + """LP: #1042916: Test enabling disabled entry.""" + apt_pkg.config.set("Dir::Etc::sourcelist", "data/aptsources/" + "sources.list") + sources = aptsources.sourceslist.SourcesList(True, self.templates) + disabled = sources.add("deb", "http://fi.archive.ubuntu.com/ubuntu/", + "precise", + ["main"]) + disabled.set_enabled(False) + enabled = sources.add("deb", "http://fi.archive.ubuntu.com/ubuntu/", + "precise", + ["main"]) + self.assertEqual(disabled, enabled) + self.assertFalse(disabled.disabled) if __name__ == "__main__": os.chdir(os.path.dirname(__file__)) 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) diff --git a/tests/test_size_to_str.py b/tests/test_size_to_str.py new file mode 100644 index 00000000..2c2c372f --- /dev/null +++ b/tests/test_size_to_str.py @@ -0,0 +1,112 @@ +#!/usr/bin/python + +__author__ = "Barry Warsaw <barry@ubuntu.com>, James Hunt, Michael Vogt" + +import sys +import unittest + +import apt_pkg + +if sys.version_info[0] == 2 and sys.version_info[1] == 6: + from unittest2 import TestCase +else: + from unittest import TestCase + + +class SizeToStrTestCase(TestCase): + """Test apt_pkg.size_to_str""" + + DATA = { + # XXX: note the trailing spaces for some of these entries! + 10 ** 1 : "10 ", + 10 ** 2 : "100 ", + 10 ** 3 : "1000 ", + 10 ** 4 : "10.0 k", + 10 ** 5 : "100 k", + 10 ** 6 : "1000 k", + 10 ** 7 : "10.0 M", + 10 ** 8 : "100 M", + 10 ** 9 : "1000 M", + 10 ** 10 : "10.0 G", + 10 ** 11 : "100 G", + 10 ** 12 : "1000 G", + 10 ** 13 : "10.0 T", + 10 ** 14 : "100 T", + 10 ** 15 : "1000 T", + 10 ** 16 : "10.0 P", + 10 ** 17 : "100 P", + 10 ** 18 : "1000 P", + 10 ** 19 : "10.0 E", + 10 ** 20 : "100 E", + 10 ** 21 : "1000 E", + 10 ** 22 : "10.0 Z", + 10 ** 23 : "100.0 Z", + 10 ** 24 : "1000 Z", +# 10 ** 25 : "10.0 Y", + 10 ** 26 : "100 Y", + 10 ** 27 : "1000 Y", + + # That's our limit :) + 10 ** 28 : "10000 Y", + + 0 : "0 ", + 1 : "1 ", + 1024 : "1024 ", + 10240 : "10.2 k", + 102400 : "102 k", + 1024000 : "1024 k", + 10240000 : "10.2 M", + 102400000 : "102 M", + 2147483647 : "2147 M", + 2147483648 : "2147 M", + 1024000000 : "1024 M", + 10240000000 : "10.2 G", + + 9 : "9 ", + 99 : "99 ", + 999 : "999 ", + 9999 : "9999 ", + 99999 : "100.0 k", + 999999 : "1000 k", + 9999999 : "10000 k", + 99999999 : "100.0 M", + 999999999 : "1000 M", + 9999999999 : "10000 M", + 99999999999 : "100.0 G", + 999999999999 : "1000 G", + 9999999999999 : "10000 G", + 99999999999999 : "100.0 T", + 999999999999999 : "1000 T", + 9999999999999999 : "10.0 P", + 99999999999999999 : "100 P", + 999999999999999999 : "1000 P", + 9999999999999999999 : "10.0 E", + 99999999999999999999 : "100 E", + 999999999999999999999 : "1000 E", + 9999999999999999999999 : "10.0 Z", + 999999999999999999999999 : "1000 Z", + } + + def test_from_data(self): + for k, v in self.DATA.items(): + size = apt_pkg.size_to_str(k) + msg = "size_to_str(%s) returned '%s', expected '%s'" % (k, size, v) + self.assertEqual(size, v, msg) + + def test_raise_on_unsupported(self): + for v in ["hello", None, {}, [], ()]: + with self.assertRaises(TypeError): + apt_pkg.size_to_str(v) + + +class RegressionTestCase(unittest.TestCase): + """Regression test for LP: #1030278""" + + def test_no_overflow_error(self): + # LP: #1030278 produces an overflow error in size_to_str() with a big + # value under Python 3. + self.assertEqual(apt_pkg.size_to_str(2147483648000000000000), '2147 E') + + +if __name__ == "__main__": + unittest.main() |
