diff options
Diffstat (limited to 'test')
-rwxr-xr-x | test/integration/skip-bug-601016-description-translation | 13 | ||||
-rwxr-xr-x | test/integration/test-apt-cli-show | 76 | ||||
-rwxr-xr-x | test/integration/test-apt-get-remove-depends | 29 | ||||
-rwxr-xr-x | test/integration/test-apt-get-satisfy | 4 | ||||
-rwxr-xr-x | test/integration/test-apt-patterns | 67 | ||||
-rwxr-xr-x | test/integration/test-apt-update-repeated-ims-hit | 75 | ||||
-rwxr-xr-x | test/integration/test-authentication-basic | 44 | ||||
-rwxr-xr-x | test/integration/test-bug-490000-search-in-all-translations | 107 | ||||
-rwxr-xr-x | test/integration/test-kernel-helper-autoremove | 12 | ||||
-rwxr-xr-x | test/integration/test-packages-require-authorization | 61 | ||||
-rwxr-xr-x | test/integration/test-provides-arch-all | 28 | ||||
-rw-r--r-- | test/libapt/CMakeLists.txt | 55 | ||||
-rw-r--r-- | test/libapt/authconf_test.cc | 81 | ||||
-rw-r--r-- | test/libapt/hashsums_test.cc | 142 | ||||
-rw-r--r-- | test/libapt/pattern_test.cc | 139 |
15 files changed, 672 insertions, 261 deletions
diff --git a/test/integration/skip-bug-601016-description-translation b/test/integration/skip-bug-601016-description-translation index fd0465acd..3f68ce2d5 100755 --- a/test/integration/skip-bug-601016-description-translation +++ b/test/integration/skip-bug-601016-description-translation @@ -47,11 +47,11 @@ Description-${LOCALE}: Mächtige Oberfläche für dpkg auf den dpkg-Paketmanager. Es beinhaltet das apt-get-Werkzeug und die APT-Dselect-Methode. Beides sind einfache und sicherere Wege, um Pakete zu installieren und Upgrades durchzuführen. -$MD5Sum" | bzip2 > aptarchive/${LOCALE}.bz2 +$MD5Sum" > "aptarchive/${LOCALE}" -# the $LOCALE translation file will not be included as it is a flat archive it came from and therefore -# its name can not be guessed correctly… (in non-flat archives the files are called Translation-*) -echo 'APT::Cache::Generate "false";' > rootdir/etc/apt/apt.conf.d/00nogenerate +# add our $LOCALE translation file explicitly to be picked up by apt-ftparchive +echo "APT::FTPArchive::Release::Patterns:: \"en\"; +APT::FTPArchive::Release::Patterns:: \"${LOCALE}\";" > rootdir/etc/apt/apt.conf.d/ftparchivepattern NOLONGSTANZA="$PACKAGESTANZA Description: Advanced front-end for dpkg @@ -90,7 +90,8 @@ testrun() { testequal "$LOCALESTANZA2" aptcache show apt:amd64 -o Test=File-${LOCALE} testequal "$NOLONGSTANZA" aptcache show apt -o Acquire::Languages="ww" -o Test=File-${LOCALE} testequal "$LOCALESTANZA" aptcache show apt -o Acquire::Languages::="ww" -o Test=File-${LOCALE} - LC_ALL=C testequal "$ENGLISHSTANZA" aptcache show apt -o Test=File-${LOCALE} + LC_ALL=C.UTF-8 testequal "$LOCALESTANZA" aptcache show apt -o Test=File-${LOCALE} + LC_ALL=C.UTF-8 testequal "$ENGLISHSTANZA" aptcache show apt -o Test=File-${LOCALE} -o Acquire::Languages="environment,${LOCALE}" export LC_ALL="" echo "Acquire::Languages { \"ww\"; \"${LOCALE}\"; \"en\"; };" > rootdir/etc/apt/apt.conf.d/00languages testequal "$LOCALESTANZA" aptcache show apt -o Test=File-ww-${LOCALE} @@ -113,7 +114,7 @@ Description-en: Advanced front-end for dpkg This is Debian's next generation front-end for the dpkg package manager. It provides the apt-get utility and APT dselect method that provides a simpler, safer way to install and upgrade packages. -$MD5Sum" | bzip2 > aptarchive/en.bz2 +$MD5Sum" > aptarchive/en ENGLISHSTANZA="$PACKAGESTANZA Description-en: Advanced front-end for dpkg diff --git a/test/integration/test-apt-cli-show b/test/integration/test-apt-cli-show index a37dbd8e6..4f9e9a16c 100755 --- a/test/integration/test-apt-cli-show +++ b/test/integration/test-apt-cli-show @@ -20,6 +20,8 @@ insertpackage 'unstable' 'bar' 'i386,amd64' '1' '' '' "$DESCR" insertpackage 'unstable' 'big' 'i386,amd64' '1' 'Installed-Size: 4129421' '' "$DESCR" insertpackage 'unstable' 'large' 'all' '1' "Provides: pkga$(generatelotsofnames)" '' "$DESCR" insertpackage 'unstable' 'large2' 'all' '1' "Provides: foobar, pkga$(generatelotsofnames)" '' "$DESCR" +insertpackage 'unstable' 'multi' 'all' '1.0' '' '' "$DESCR" +insertpackage 'unstable' 'multi' 'all' '2.0' '' '' "$DESCR" insertinstalledpackage 'foo' 'all' '1.0' setupaptarchive @@ -99,6 +101,80 @@ Description: Some description That has multiple lines " apt show large2 +# Test for multiple versions +testsuccessequal "Package: multi +Version: 2.0 +Priority: optional +Section: other +Maintainer: Joe Sixpack <joe@example.org> +Installed-Size: 43.0 kB +Download-Size: unknown +APT-Sources: file:$APTARCHIVE unstable/main all Packages +Description: Some description + That has multiple lines + +N: There is 1 additional record. Please use the '-a' switch to see it" apt show multi + +testsuccessequal "Package: multi +Version: 2.0 +Priority: optional +Section: other +Maintainer: Joe Sixpack <joe@example.org> +Installed-Size: 43.0 kB +Download-Size: unknown +APT-Sources: file:$APTARCHIVE unstable/main all Packages +Description: Some description + That has multiple lines + +Package: multi +Version: 1.0 +Priority: optional +Section: other +Maintainer: Joe Sixpack <joe@example.org> +Installed-Size: 43.0 kB +Download-Size: unknown +APT-Sources: file:$APTARCHIVE unstable/main all Packages +Description: Some description + That has multiple lines +" apt show multi -a + +# test apt info +testsuccessequal "Package: multi +Version: 2.0 +Priority: optional +Section: other +Maintainer: Joe Sixpack <joe@example.org> +Installed-Size: 43.0 kB +Download-Size: unknown +APT-Sources: file:$APTARCHIVE unstable/main all Packages +Description: Some description + That has multiple lines + +N: There is 1 additional record. Please use the '-a' switch to see it" apt info multi + +testsuccessequal "Package: multi +Version: 2.0 +Priority: optional +Section: other +Maintainer: Joe Sixpack <joe@example.org> +Installed-Size: 43.0 kB +Download-Size: unknown +APT-Sources: file:$APTARCHIVE unstable/main all Packages +Description: Some description + That has multiple lines + +Package: multi +Version: 1.0 +Priority: optional +Section: other +Maintainer: Joe Sixpack <joe@example.org> +Installed-Size: 43.0 kB +Download-Size: unknown +APT-Sources: file:$APTARCHIVE unstable/main all Packages +Description: Some description + That has multiple lines +" apt info multi -a + # this is the default, but disabled by the testcases testsuccess apt show foo -o Apt::Cmd::Disable-Script-Warning=0 cp rootdir/tmp/testsuccess.output aptshow.output diff --git a/test/integration/test-apt-get-remove-depends b/test/integration/test-apt-get-remove-depends new file mode 100755 index 000000000..2d2cf0dd6 --- /dev/null +++ b/test/integration/test-apt-get-remove-depends @@ -0,0 +1,29 @@ +#!/bin/sh +set -e + +TESTDIR="$(readlink -f "$(dirname "$0")")" +. "$TESTDIR/framework" +setupenvironment +configarchitecture 'i386' + +buildsimplenativepackage 'alpha' 'all' '1' 'unstable' 'Depends: beta' +buildsimplenativepackage 'beta' 'all' '1' 'unstable' +setupaptarchive + +testsuccess aptget install alpha -y + +cat > rootdir/var/lib/dpkg/info/alpha.prerm << EOF +#!/bin/sh +exit 42 +EOF +chmod 755 rootdir/var/lib/dpkg/info/alpha.prerm + + +testdpkginstalled 'alpha' 'beta' + + +testfailure aptget remove -y beta + +# Beta should not be removed because alpha failed to be removed and depends on it + +testdpkginstalled 'alpha' 'beta' diff --git a/test/integration/test-apt-get-satisfy b/test/integration/test-apt-get-satisfy index f2e04d789..23daf069a 100755 --- a/test/integration/test-apt-get-satisfy +++ b/test/integration/test-apt-get-satisfy @@ -70,3 +70,7 @@ testfailureequal "E: Invalid operator '>' at offset 5, did you mean '>>' or '>=' msgmsg "Unsupported dependency type" testfailureequal "E: Problem parsing dependency: Recommends: foo" aptget satisfy 'Recommends: foo' -s + + +msgmsg "Empty dependency" +testfailureequal "E: Problem parsing dependency: " aptget satisfy '' -s diff --git a/test/integration/test-apt-patterns b/test/integration/test-apt-patterns index 92c76edd1..cdba76146 100755 --- a/test/integration/test-apt-patterns +++ b/test/integration/test-apt-patterns @@ -5,15 +5,16 @@ TESTDIR="$(readlink -f "$(dirname "$0")")" setupenvironment configarchitecture 'i386' 'amd64' -insertpackage 'unstable' 'available' 'all' '1.0' +insertpackage 'unstable' 'available' 'all' '1.0' 'Section: asection' insertinstalledpackage 'manual1' 'i386' '1.0' 'Depends: automatic1' insertinstalledpackage 'manual2' 'i386' '1.0' -insertinstalledpackage 'automatic1' 'i386' '1.0' -insertinstalledpackage 'automatic2' 'i386' '1.0' +insertinstalledpackage 'automatic1' 'i386' '1.0' 'Source: automatic (0)' +insertinstalledpackage 'automatic2' 'i386' '1.0' 'Source: automatic (1)' -insertinstalledpackage 'essential' 'i386' '1.0' 'Essential: yes' +insertinstalledpackage 'essential' 'i386' '1.0' 'Essential: yes +Section: asection' insertinstalledpackage 'conf-only' 'i386' '1.0' '' '' 'deinstall ok config-files' insertinstalledpackage 'broken' 'i386' '1.0' 'Depends: does-not-exist' @@ -22,6 +23,7 @@ insertpackage 'unstable' 'not-obsolete' 'all' '2.0' insertpackage 'unstable' 'foreign' 'amd64' '2.0' +getoriginfromsuite() { echo -n 'meow'; } setupaptarchive testsuccess aptmark auto automatic1 automatic2 @@ -32,16 +34,10 @@ testfailureequal "E: input:0-14: error: Unrecognized pattern '?not-a-pattern' ?not-a-pattern ^^^^^^^^^^^^^^ N: Unable to locate package ?not-a-pattern -N: Couldn't find any package by glob '?not-a-pattern' -E: Regex compilation error - Invalid preceding regular expression -N: Couldn't find any package by regex '?not-a-pattern' E: input:0-14: error: Unrecognized pattern '?not-a-pattern' ?not-a-pattern ^^^^^^^^^^^^^^ N: Unable to locate package ?not-a-pattern -N: Couldn't find any package by glob '?not-a-pattern' -E: Regex compilation error - Invalid preceding regular expression -N: Couldn't find any package by regex '?not-a-pattern' E: No packages found" apt show '?not-a-pattern' testfailureequal "Listing... @@ -55,10 +51,7 @@ Reading state information... E: input:0-14: error: Unrecognized pattern '?not-a-pattern' ?not-a-pattern ^^^^^^^^^^^^^^ -E: Unable to locate package ?not-a-pattern -E: Couldn't find any package by glob '?not-a-pattern' -E: Regex compilation error - Invalid preceding regular expression -E: Couldn't find any package by regex '?not-a-pattern'" apt install -s '?not-a-pattern' +E: Unable to locate package ?not-a-pattern" apt install -s '?not-a-pattern' msgmsg "Ensure that argument lists are present where needed, and absent elsewhere" @@ -103,6 +96,27 @@ testsuccessequal "Listing... automatic1/now 1.0 i386 [installed,local]" apt list '?and(?name(^automatic),?name(1$))' +msgmsg "Narrow and friends" +testsuccessequal "Listing... +not-obsolete/unstable 2.0 i386 [upgradable from: 1.0] +N: There is 1 additional version. Please use the '-a' switch to see it" apt list '?and(?version(^1\.0$),?version(^2\.0$))' + +testsuccessequal "Listing..." apt list '?any-version(?and(?version(^1\.0$),?version(^2\.0$)))' +testsuccessequal "Listing..." apt list '?narrow(?version(^1\.0$),?version(^2\.0$))' + +# XXX FIXME: I guess we do want this to only show version 1.0? +testsuccessequal "Listing... +not-obsolete/unstable 2.0 i386 [upgradable from: 1.0] +N: There is 1 additional version. Please use the '-a' switch to see it" apt list '?any-version(?and(?version(^1\.0$),?name(not-obsolete)))' +testsuccessequal "Listing... +not-obsolete/unstable 2.0 i386 [upgradable from: 1.0] +N: There is 1 additional version. Please use the '-a' switch to see it" apt list '?narrow(?version(^1\.0$),?name(not-obsolete))' + + +testsuccessequal "Listing... +foreign/unstable 2.0 amd64 +not-obsolete/unstable 2.0 i386 [upgradable from: 1.0]" apt list '?not(?all-versions(?version(^1)))' + msgmsg "Package patterns" testsuccessequal "Listing... @@ -113,6 +127,11 @@ testsuccessequal "Listing..." apt list '?architecture(foreign)' testsuccessequal "Listing..." apt list '?architecture(native)' testsuccessequal "Listing... +available/unstable 1.0 all +foreign/unstable 2.0 amd64 +not-obsolete/unstable 2.0 i386 [upgradable from: 1.0]" apt list '?archive(^unstable$)' + +testsuccessequal "Listing... automatic1/now 1.0 i386 [installed,local] automatic2/now 1.0 i386 [installed,local]" apt list '?automatic' @@ -158,9 +177,29 @@ foreign/unstable 2.0 amd64 not-obsolete/unstable 2.0 i386 [upgradable from: 1.0]" apt list '?not(?obsolete)' testsuccessequal "Listing... +available/unstable 1.0 all +foreign/unstable 2.0 amd64 +not-obsolete/unstable 2.0 i386 [upgradable from: 1.0]" apt list '?origin(^meow$)' + +testsuccessequal "Listing... +available/unstable 1.0 all +essential/now 1.0 i386 [installed,local]" apt list '?section(asection)' + +testsuccessequal "Listing... +automatic1/now 1.0 i386 [installed,local] +automatic2/now 1.0 i386 [installed,local]" apt list '?source-package(^automatic$)' + +testsuccessequal "Listing... +automatic2/now 1.0 i386 [installed,local]" apt list '?source-version(^1$)' + +testsuccessequal "Listing... not-obsolete/unstable 2.0 i386 [upgradable from: 1.0] N: There is 1 additional version. Please use the '-a' switch to see it" apt list '?upgradable' +testsuccessequal "Listing... +foreign/unstable 2.0 amd64 +not-obsolete/unstable 2.0 i386 [upgradable from: 1.0]" apt list '?version(2.0)' + testsuccessequal "Package: does-not-exist State: not a real package (virtual) N: Can't select candidate version from package does-not-exist as it has no candidate diff --git a/test/integration/test-apt-update-repeated-ims-hit b/test/integration/test-apt-update-repeated-ims-hit new file mode 100755 index 000000000..74d46b31b --- /dev/null +++ b/test/integration/test-apt-update-repeated-ims-hit @@ -0,0 +1,75 @@ +#!/bin/sh +set -e + +TESTDIR="$(readlink -f "$(dirname "$0")")" +. "$TESTDIR/framework" +setupenvironment +configarchitecture 'amd64' +configcompression '.' 'bz2' + +echo 'Package: apt +Priority: important +Section: admin +Installed-Size: 5984 +Maintainer: APT Development Team <deity@lists.debian.org> +Architecture: i386 +Version: 0.8.7 +Filename: pool/main/a/apt/apt_0.8.7_i386.deb +Size: 2140230 +MD5sum: 74769bfbcef9ebc4fa74f7a5271b9c08 +Description: Advanced front-end for dpkg +Description-md5: d41ee493aa9fcc6cbc9ce4eb7069959c' > aptarchive/Packages +compressfile aptarchive/Packages + +echo "Package: apt +Description-en: Advanced front-end for dpkg + This is Debian's next generation front-end for the dpkg package manager. + It provides the apt-get utility and APT dselect method that provides a + simpler, safer way to install and upgrade packages. +$MD5Sum" > aptarchive/en +compressfile aptarchive/en + +echo "APT::FTPArchive::Release::Patterns:: \"en\"; +APT::FTPArchive::Release::Patterns:: \"en.*\";" > rootdir/etc/apt/apt.conf.d/ftparchivepattern + +export APT_DONT_SIGN='InRelease' +setupaptarchive --no-update +rm -f aptarchive/Packages aptarchive/en + +rm -f rootdir/etc/apt/trusted.gpg.d/* +sed -i -e 's#^deb #deb [trusted=yes] #' rootdir/etc/apt/sources.list.d/* + +APTARCHIVE="$(readlink -f ./aptarchive)" +GPGERROR="W: GPG error: file:$APTARCHIVE Release: The following signatures couldn't be verified because the public key is not available: NO_PUBKEY 5A90D141DBAC8DAE" + +msgmsg 'Running update again does not change result' '0' +testwarningmsg "$GPGERROR" apt update +listcurrentlistsdirectory > lists.before +testsuccess grep 'aptarchive_en$' lists.before +testsuccess grep 'aptarchive_Packages$' lists.before +testsuccess grep 'aptarchive_Release$' lists.before +testfailure grep 'aptarchive_Release.gpg$' lists.before + +for i in $(seq 1 3); do + msgmsg 'Running update again does not change result' "$i" + testwarningmsg "$GPGERROR" apt update + testfileequal lists.before "$(listcurrentlistsdirectory)" +done + +find rootdir/var/lib/apt/lists -name '*Release*' -delete +msgmsg 'Running update with a repository gaining hashsums' +testwarningmsg "$GPGERROR" apt update +testfileequal lists.before "$(listcurrentlistsdirectory)" + +changetowebserver +find aptarchive -name '*Release*' -delete +rm -rf rootdir/var/lib/apt/lists + +msgmsg 'Running update with no indexes' '0' +testsuccess apt update +listcurrentlistsdirectory > lists.before +for i in $(seq 1 3); do + msgmsg 'Running update with no indexes' "$i" + testsuccess apt update -o Debug::pkgAcquire::Worker=1 -o Debug::Acquire::Transaction=1 + testfileequal lists.before "$(listcurrentlistsdirectory)" +done diff --git a/test/integration/test-authentication-basic b/test/integration/test-authentication-basic index 211c73e35..784a00c03 100755 --- a/test/integration/test-authentication-basic +++ b/test/integration/test-authentication-basic @@ -65,35 +65,61 @@ runtest() { authfile '' testauthfailure "$1" + protocol="${1%%://*}" + # good auth - authfile 'machine localhost + authfile "machine ${protocol}://localhost login star@irc -password hunter2' +password hunter2" testauthsuccess "$1" # bad auth - authfile 'machine localhost + authfile "machine ${protocol}://localhost login anonymous -password hunter2' +password hunter2" testauthfailure "$1" # 2 stanzas: unmatching + good auth - authfile 'machine debian.org + authfile "machine ${protocol}://debian.org login debian password jessie -machine localhost +machine ${protocol}://localhost login star@irc -password hunter2' +password hunter2" testauthsuccess "$1" + # no protocol specifier + authfile "machine localhost +login star@irc +password hunter2" + if [ "$protocol" = "https" ]; then + testauthsuccess "$1" + else + testfailure apthelper download-file "${1}/bash" ./downloaded/bash + testsuccessequal "W: ${1}/bash: ${TMPWORKINGDIRECTORY}/rootdir/etc/apt/auth.conf: Credentials for localhost match, but the protocol is not encrypted. Annotate with http:// to use." grep "Credentials.*match" rootdir/tmp/testfailure.output + testauthfailure "$1" + fi + + # wrong protocol specifier + if [ "$protocol" = "https" ]; then + authfile "machine http://localhost +login star@irc +password hunter2" + else + authfile "machine https://localhost +login star@irc +password hunter2" + fi + testauthfailure "$1" + # delete file, make sure it fails; add auth.conf.d snippet, works again. rm rootdir/etc/apt/auth.conf testauthfailure "$1" - authfile 'machine localhost + authfile "machine ${protocol}://localhost login star@irc -password hunter2' rootdir/etc/apt/auth.conf.d/myauth.conf +password hunter2" rootdir/etc/apt/auth.conf.d/myauth.conf testauthsuccess "$1" rm rootdir/etc/apt/auth.conf.d/myauth.conf } diff --git a/test/integration/test-bug-490000-search-in-all-translations b/test/integration/test-bug-490000-search-in-all-translations new file mode 100755 index 000000000..3a034bc49 --- /dev/null +++ b/test/integration/test-bug-490000-search-in-all-translations @@ -0,0 +1,107 @@ +#!/bin/sh + +set -e + +TESTDIR="$(readlink -f "$(dirname "$0")")" +. "${TESTDIR}/framework" + +setupenvironment + +ARCH='amd64' +DIST='unstable' + +PKG_NAME='foo' +PKG_VERSION='1.0' + +SHORT_DESCRIPTION_EN='have you fooed today?' +LONG_DESCRIPTION_EN="${SHORT_DESCRIPTION_EN} + Where there's foo, there's fire." + +SHORT_DESCRIPTION_ZZ='bar alter ego' +LONG_DESCRIPTION_ZZ="${SHORT_DESCRIPTION_ZZ} + He who foos last foos best." + +configure_languages() +{ + { + echo '#clear Acquire::Languages;' + echo 'Acquire::Languages {' + for language in "$@" + do + echo " \"${language}\";" + done + echo '};' + } > rootdir/etc/apt/apt.conf.d/languages.conf +} + +new_translation_record() +{ + echo "Package: ${1:?Package name expected}" + echo "Description-md5: ${2:?Description-md5 expected}" + echo "Description-${3:?Language code expected}: ${4:?Package description expected}" + echo +} + +str_md5sum() +{ + echo -n "${1:?String expected}" | md5sum | cut -d ' ' -f 1 +} + +configarchitecture "${ARCH}" + +insertpackage "${DIST}" "${PKG_NAME}" "${ARCH}" "${PKG_VERSION}" '' '' "${LONG_DESCRIPTION_EN}" +# English translation was already added by insertpackage above +new_translation_record "${PKG_NAME}" "$(str_md5sum "${LONG_DESCRIPTION_EN}")" 'zz' "${LONG_DESCRIPTION_ZZ}" > "aptarchive/dists/${DIST}/main/i18n/Translation-zz" + +configure_languages en zz +setupaptarchive + +# =========================== +# +# Tests +# +# =========================== + +# ----------[ apt ]---------- + +# Test that all translations are searched, but the short +# description is in the first configured language + +configure_languages en zz +testequal "${PKG_NAME}/${DIST} ${PKG_VERSION} ${ARCH} + ${SHORT_DESCRIPTION_EN} +" apt -qq search alter ego + +configure_languages zz en +testequal "${PKG_NAME}/${DIST} ${PKG_VERSION} ${ARCH} + ${SHORT_DESCRIPTION_ZZ} +" apt -qq search you today + +# Search in configured languages only +configure_languages zz +testempty apt -qq search where fire + +# Patterns are AND-ed i.e. all must match against a single +# description translation +configure_languages en zz +testempty apt -qq search there best + +# -------[ apt-cache ]------- + +# Test that all translations are searched, but the short +# description is in the first configured language + +configure_languages en zz +testequal "${PKG_NAME} - ${SHORT_DESCRIPTION_EN}" aptcache search alter ego + +configure_languages zz en +testequal "${PKG_NAME} - ${SHORT_DESCRIPTION_ZZ}" aptcache search you today + +# Search in configured languages only +configure_languages zz +testempty aptcache search where fire + +# Patterns are AND-ed i.e. all must match against a single +# description translation +configure_languages en zz +testempty aptcache search there best diff --git a/test/integration/test-kernel-helper-autoremove b/test/integration/test-kernel-helper-autoremove index 8cde3432f..9cc978645 100755 --- a/test/integration/test-kernel-helper-autoremove +++ b/test/integration/test-kernel-helper-autoremove @@ -46,10 +46,10 @@ testprotected() { testfailure --nomsg grep '^[A-Z]: ' protected.list msgtest 'Check kernel autoremoval protection list includes' 'most recent kernel' - testsuccess --nomsg grep '^\^linux-image-100\\\.0\\\.0-1-generic\$$' protected.list + testsuccess --nomsg grep '^\^linux-.*-100\\\.0\\\.0-1-generic\$$' protected.list msgtest 'Check kernel autoremoval protection list includes' 'running kernel' - testsuccess --nomsg grep "^\\^linux-image-$(uname -r | tr '[A-Z]' '[a-z]' | sed -e 's#\.#\\\\.#g')\\\$\$" protected.list + testsuccess --nomsg grep "^\\^linux-.*-$(uname -r | tr '[A-Z]' '[a-z]' | sed -e 's#\.#\\\\.#g')\\\$\$" protected.list msgtest 'Check kernel autoremoval protection list does not include' 'metapackages' testfailure --nomsg grep -e '^\^linux-image-amd64\$$' -e '^\^linux-image-686-pae\$$' -e ':i386' protected.list @@ -115,7 +115,7 @@ Remv ${CURRENTKERNEL}-dbg [5-1]" aptget autoremove -sV msgmsg "run without parameter" testprotected msgtest 'Check kernel autoremoval protection list does not include' 'old kernel' -testfailure --nomsg grep '^\^linux-image-1\\\.0\\\.0-2-generic\$$' protected.list +testfailure --nomsg grep '^\^linux-.*-1\\\.0\\\.0-2-generic\$$' protected.list export COLUMNS=99999 testsuccessequal "Reading package lists... Building dependency tree... @@ -134,9 +134,9 @@ msgmsg "install unknown kernel" # know for sure without complicated detection mechanisms testprotected 1.0.0-2-ungeneric msgtest 'Check kernel autoremoval protection list does not include' 'old kernel' -testfailure --nomsg grep '^\^linux-image-1\\\.0\\\.0-2-generic\$$' protected.list +testfailure --nomsg grep '^\^linux-.*-1\\\.0\\\.0-2-generic\$$' protected.list msgtest 'Check kernel autoremoval protection list does include' 'unknown installed kernel' -testsuccess --nomsg grep '^\^linux-image-1\\\.0\\\.0-2-ungeneric\$$' protected.list +testsuccess --nomsg grep '^\^linux-.*-1\\\.0\\\.0-2-ungeneric\$$' protected.list export COLUMNS=9 testsuccessequal "Reading package lists... Building dependency tree... @@ -154,7 +154,7 @@ unset COLUMNS msgmsg "install an old kernel" testprotected 1.0.0-2-generic msgtest 'Check kernel autoremoval protection list includes' 'installed kernel' -testsuccess --nomsg grep '^\^linux-image-1\\\.0\\\.0-2-generic\$$' protected.list +testsuccess --nomsg grep '^\^linux-.*-1\\\.0\\\.0-2-generic\$$' protected.list export COLUMNS=9 testsuccessequal "Reading package lists... Building dependency tree... diff --git a/test/integration/test-packages-require-authorization b/test/integration/test-packages-require-authorization deleted file mode 100755 index 527497ce5..000000000 --- a/test/integration/test-packages-require-authorization +++ /dev/null @@ -1,61 +0,0 @@ -#!/bin/sh -set -e - -TESTDIR="$(readlink -f "$(dirname "$0")")" -. "$TESTDIR/framework" -setupenvironment -configarchitecture 'amd64' - -insertpackage 'unstable' 'cool' 'amd64' '1.0' - -export APT_DONT_SIGN='InRelease' -setupaptarchive --no-update -changetowebserver - -echo 'Packages-Require-Authorization: yes' >> aptarchive/dists/unstable/Release -signreleasefiles - -testsuccess aptget update -testsuccessequal "Package files: - 100 ${TMPWORKINGDIRECTORY}/rootdir/var/lib/dpkg/status - release a=now --32768 http://localhost:${APTHTTPPORT} unstable/main amd64 Packages - release a=unstable,n=sid,c=main,b=amd64 - origin localhost -Pinned packages:" aptcache policy - -mkdir rootdir/etc/apt/auth.conf.d -cat > rootdir/etc/apt/auth.conf.d/myauth.conf << EOF -machine localhost -login username -password usersPassword -EOF - - -testsuccessequal "Package files: - 100 ${TMPWORKINGDIRECTORY}/rootdir/var/lib/dpkg/status - release a=now - 500 http://localhost:${APTHTTPPORT} unstable/main amd64 Packages - release a=unstable,n=sid,c=main,b=amd64 - origin localhost -Pinned packages:" aptcache policy - - -cat > rootdir/etc/apt/preferences.d/myauth.pref << EOF -Package: * -Pin: origin localhost -Pin-Priority: 990 - -Package: cool -Pin: origin localhost -Pin-Priority: 990 -EOF - -testsuccessequal "Package files: - 100 ${TMPWORKINGDIRECTORY}/rootdir/var/lib/dpkg/status - release a=now - 990 http://localhost:${APTHTTPPORT} unstable/main amd64 Packages - release a=unstable,n=sid,c=main,b=amd64 - origin localhost -Pinned packages: - cool -> 1.0 with priority 990" aptcache policy diff --git a/test/integration/test-provides-arch-all b/test/integration/test-provides-arch-all new file mode 100755 index 000000000..f212b513c --- /dev/null +++ b/test/integration/test-provides-arch-all @@ -0,0 +1,28 @@ +#!/bin/sh +# +# In apt 1.9.6, this test would have failed, outputting: +# The following packages will be REMOVED: +# libltdl-dev +# 0 upgraded, 0 newly installed, 1 to remove and 0 not upgraded. +# Remv libltdl-dev [1] +# +# Because we started inserting groups without packages, and then could not +# properly insert the provides. + +set -e + +TESTDIR="$(readlink -f "$(dirname "$0")")" +. "$TESTDIR/framework" +setupenvironment +configarchitecture "i386" + +insertinstalledpackage 'automake' 'i386' '1' 'Provides: automake-1.16 +Source: automake-1.16 +Multi-Arch: foreign' +insertinstalledpackage 'libltdl-dev' 'i386' '1' 'Depends: automake-1.16' + +setupaptarchive + +testsuccessequal 'Reading package lists... +Building dependency tree... +0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.' aptget install -f -s diff --git a/test/libapt/CMakeLists.txt b/test/libapt/CMakeLists.txt index d44d77ad4..11d4d22c7 100644 --- a/test/libapt/CMakeLists.txt +++ b/test/libapt/CMakeLists.txt @@ -1,28 +1,35 @@ -set(PROJECT_TEST_LIBRARIES apt-private) -find_path(GTEST_ROOT src/gtest.cc - /usr/src/googletest/googletest - /usr/src/gtest -) -find_package(GTest) -set(GTEST_DEPENDENCIES) - -if(NOT GTEST_FOUND AND EXISTS ${GTEST_ROOT}) - include(ExternalProject) - ExternalProject_Add(gtest PREFIX ./gtest - SOURCE_DIR ${GTEST_ROOT} - INSTALL_COMMAND true) - - link_directories(${CMAKE_CURRENT_BINARY_DIR}/gtest/src/gtest-build) - - set(GTEST_LIBRARIES "-lgtest") - set(GTEST_DEPENDENCIES "gtest") - set(GTEST_FOUND TRUE) - find_path(GTEST_INCLUDE_DIRS NAMES gtest/gtest.h PATHS ${GTEST_ROOT}/include) - - message(STATUS "Found GTest at ${GTEST_ROOT}, headers at ${GTEST_INCLUDE_DIRS}") -endif() +if (WITH_TESTS) + set(PROJECT_TEST_LIBRARIES apt-private) + find_path(GTEST_ROOT src/gtest.cc + /usr/src/googletest/googletest + /usr/src/googletest + /usr/src/gtest + ) + find_package(GTest) + set(GTEST_DEPENDENCIES) + + if(NOT GTEST_FOUND AND EXISTS ${GTEST_ROOT}) + include(ExternalProject) + ExternalProject_Add(gtest PREFIX ./gtest + SOURCE_DIR ${GTEST_ROOT} + INSTALL_COMMAND true) + + link_directories(${CMAKE_CURRENT_BINARY_DIR}/gtest/src/gtest-build) + link_directories(${CMAKE_CURRENT_BINARY_DIR}/gtest/src/gtest-build/lib) + + set(GTEST_LIBRARIES "-lgtest") + set(GTEST_DEPENDENCIES "gtest") + set(GTEST_FOUND TRUE) + find_path(GTEST_INCLUDE_DIRS NAMES gtest/gtest.h PATHS ${GTEST_ROOT}/include) + + message(STATUS "Found GTest at ${GTEST_ROOT}, headers at ${GTEST_INCLUDE_DIRS}") + endif() + + if (NOT GTEST_FOUND) + message(FATAL_ERROR "Could not find GTest") + endif() + -if(GTEST_FOUND) # gtest produces some warnings with the set of warnings we activate, # so disable the offending warnings while compiling tests for now add_optional_compile_options(Wno-undef) diff --git a/test/libapt/authconf_test.cc b/test/libapt/authconf_test.cc index a7b2f2c98..04d54e9be 100644 --- a/test/libapt/authconf_test.cc +++ b/test/libapt/authconf_test.cc @@ -13,7 +13,7 @@ TEST(NetRCTest, Parsing) { FileFd fd; - URI U("http://file.not/open"); + URI U("https://file.not/open"); EXPECT_FALSE(MaybeAddAuth(fd, U)); EXPECT_TRUE(U.User.empty()); EXPECT_TRUE(U.Password.empty()); @@ -38,8 +38,8 @@ machine example.com/bar password pass2 login user2 unknown token machine example.com/user login user machine example.netter login unused password firstentry -machine example.last/debian login debian password rules)apt"); - U = URI("http://example.net/foo"); +machine socks5h://example.last/debian login debian password rules)apt"); + U = URI("https://example.net/foo"); EXPECT_TRUE(MaybeAddAuth(fd, U)); EXPECT_EQ("foo", U.User); EXPECT_EQ("bar", U.Password); @@ -47,7 +47,7 @@ machine example.last/debian login debian password rules)apt"); EXPECT_EQ("/foo", U.Path); EXPECT_TRUE(fd.Seek(0)); - U = URI("http://user:pass@example.net/foo"); + U = URI("https://user:pass@example.net/foo"); EXPECT_TRUE(MaybeAddAuth(fd, U)); EXPECT_EQ("user", U.User); EXPECT_EQ("pass", U.Password); @@ -55,7 +55,7 @@ machine example.last/debian login debian password rules)apt"); EXPECT_EQ("/foo", U.Path); EXPECT_TRUE(fd.Seek(0)); - U = URI("http://example.org:90/foo"); + U = URI("https://example.org:90/foo"); EXPECT_TRUE(MaybeAddAuth(fd, U)); EXPECT_EQ("apt", U.User); EXPECT_EQ("apt", U.Password); @@ -64,55 +64,55 @@ machine example.last/debian login debian password rules)apt"); EXPECT_EQ("/foo", U.Path); EXPECT_TRUE(fd.Seek(0)); - U = URI("http://example.org:8080/foo"); + U = URI("https://example.org:8080/foo"); EXPECT_TRUE(MaybeAddAuth(fd, U)); EXPECT_EQ("example", U.User); EXPECT_EQ("foobar", U.Password); EXPECT_TRUE(fd.Seek(0)); - U = URI("http://example.net:42/foo"); + U = URI("https://example.net:42/foo"); EXPECT_TRUE(MaybeAddAuth(fd, U)); EXPECT_EQ("foo", U.User); EXPECT_EQ("bar", U.Password); EXPECT_TRUE(fd.Seek(0)); - U = URI("http://example.org/foo"); + U = URI("https://example.org/foo"); EXPECT_TRUE(MaybeAddAuth(fd, U)); EXPECT_EQ("anonymous", U.User); EXPECT_EQ("pass", U.Password); EXPECT_TRUE(fd.Seek(0)); - U = URI("http://example.com/apt"); + U = URI("https://example.com/apt"); EXPECT_TRUE(MaybeAddAuth(fd, U)); EXPECT_TRUE(U.User.empty()); EXPECT_TRUE(U.Password.empty()); EXPECT_TRUE(fd.Seek(0)); - U = URI("http://example.com/foo"); + U = URI("https://example.com/foo"); EXPECT_TRUE(MaybeAddAuth(fd, U)); EXPECT_EQ("user1", U.User); EXPECT_EQ("pass1", U.Password); EXPECT_TRUE(fd.Seek(0)); - U = URI("http://example.com/fooo"); + U = URI("https://example.com/fooo"); EXPECT_TRUE(MaybeAddAuth(fd, U)); EXPECT_EQ("user1", U.User); EXPECT_EQ("pass1", U.Password); EXPECT_TRUE(fd.Seek(0)); - U = URI("http://example.com/fo"); + U = URI("https://example.com/fo"); EXPECT_TRUE(MaybeAddAuth(fd, U)); EXPECT_TRUE(U.User.empty()); EXPECT_TRUE(U.Password.empty()); EXPECT_TRUE(fd.Seek(0)); - U = URI("http://example.com/bar"); + U = URI("https://example.com/bar"); EXPECT_TRUE(MaybeAddAuth(fd, U)); EXPECT_EQ("user2", U.User); EXPECT_EQ("pass2", U.Password); EXPECT_TRUE(fd.Seek(0)); - U = URI("http://example.com/user"); + U = URI("https://example.com/user"); EXPECT_TRUE(MaybeAddAuth(fd, U)); EXPECT_EQ("user", U.User); EXPECT_TRUE(U.Password.empty()); @@ -144,7 +144,7 @@ machin example.org login foo2 password bar machine2 example.org login foo3 password bar )apt"); - URI U("http://example.org/foo"); + URI U("https://example.org/foo"); EXPECT_TRUE(MaybeAddAuth(fd, U)); EXPECT_TRUE(U.User.empty()); EXPECT_TRUE(U.Password.empty()); @@ -156,19 +156,19 @@ TEST(NetRCTest, BadFileEndsMachine) machine example.org login foo1 password bar machine)apt"); - URI U("http://example.org/foo"); + URI U("https://example.org/foo"); EXPECT_TRUE(MaybeAddAuth(fd, U)); EXPECT_EQ("foo1", U.User); EXPECT_EQ("bar", U.Password); EXPECT_TRUE(fd.Seek(0)); - U = URI("http://example.net/foo"); + U = URI("https://example.net/foo"); EXPECT_FALSE(MaybeAddAuth(fd, U)); EXPECT_TRUE(U.User.empty()); EXPECT_TRUE(U.Password.empty()); EXPECT_TRUE(fd.Seek(0)); - U = URI("http://foo:bar@example.net/foo"); + U = URI("https://foo:bar@example.net/foo"); EXPECT_TRUE(MaybeAddAuth(fd, U)); EXPECT_EQ("foo", U.User); EXPECT_EQ("bar", U.Password); @@ -180,19 +180,19 @@ TEST(NetRCTest, BadFileEndsLogin) machine example.org login foo1 password bar machine example.net login)apt"); - URI U("http://example.org/foo"); + URI U("https://example.org/foo"); EXPECT_TRUE(MaybeAddAuth(fd, U)); EXPECT_EQ("foo1", U.User); EXPECT_EQ("bar", U.Password); EXPECT_TRUE(fd.Seek(0)); - U = URI("http://example.net/foo"); + U = URI("https://example.net/foo"); EXPECT_FALSE(MaybeAddAuth(fd, U)); EXPECT_TRUE(U.User.empty()); EXPECT_TRUE(U.Password.empty()); EXPECT_TRUE(fd.Seek(0)); - U = URI("http://foo:bar@example.net/foo"); + U = URI("https://foo:bar@example.net/foo"); EXPECT_TRUE(MaybeAddAuth(fd, U)); EXPECT_EQ("foo", U.User); EXPECT_EQ("bar", U.Password); @@ -204,20 +204,53 @@ TEST(NetRCTest, BadFileEndsPassword) machine example.org login foo1 password bar machine example.net password)apt"); - URI U("http://example.org/foo"); + URI U("https://example.org/foo"); EXPECT_TRUE(MaybeAddAuth(fd, U)); EXPECT_EQ("foo1", U.User); EXPECT_EQ("bar", U.Password); EXPECT_TRUE(fd.Seek(0)); - U = URI("http://example.net/foo"); + U = URI("https://example.net/foo"); EXPECT_FALSE(MaybeAddAuth(fd, U)); EXPECT_TRUE(U.User.empty()); EXPECT_TRUE(U.Password.empty()); EXPECT_TRUE(fd.Seek(0)); - U = URI("http://foo:bar@example.net/foo"); + U = URI("https://foo:bar@example.net/foo"); EXPECT_TRUE(MaybeAddAuth(fd, U)); EXPECT_EQ("foo", U.User); EXPECT_EQ("bar", U.Password); } + +TEST(NetRCTest, MatchesOnlyHTTPS) +{ + FileFd fd; + createTemporaryFile("doublesignedfile", fd, nullptr, R"apt( +machine https.example login foo1 password bar +machine http://http.example login foo1 password bar +)apt"); + + URI U("https://https.example/foo"); + EXPECT_TRUE(MaybeAddAuth(fd, U)); + EXPECT_EQ("foo1", U.User); + EXPECT_EQ("bar", U.Password); + + EXPECT_TRUE(fd.Seek(0)); + U = URI("http://https.example/foo"); + EXPECT_TRUE(MaybeAddAuth(fd, U)); + EXPECT_TRUE(U.User.empty()); + EXPECT_TRUE(U.Password.empty()); + + EXPECT_TRUE(fd.Seek(0)); + U = URI("http://http.example/foo"); + EXPECT_TRUE(MaybeAddAuth(fd, U)); + EXPECT_EQ("foo1", U.User); + EXPECT_EQ("bar", U.Password); + + EXPECT_TRUE(fd.Seek(0)); + U = URI("https://http.example/foo"); + EXPECT_TRUE(MaybeAddAuth(fd, U)); + EXPECT_TRUE(U.User.empty()); + EXPECT_TRUE(U.Password.empty()); + +} diff --git a/test/libapt/hashsums_test.cc b/test/libapt/hashsums_test.cc index eede213cd..a8a826821 100644 --- a/test/libapt/hashsums_test.cc +++ b/test/libapt/hashsums_test.cc @@ -3,9 +3,6 @@ #include <apt-pkg/configuration.h> #include <apt-pkg/fileutl.h> #include <apt-pkg/hashes.h> -#include <apt-pkg/md5.h> -#include <apt-pkg/sha1.h> -#include <apt-pkg/sha2.h> #include <apt-pkg/strutl.h> #include <iostream> @@ -25,83 +22,6 @@ template <class T> void Test(const char *In,const char *Out) -TEST(HashSumsTest,SummationStrings) -{ -#define EXPECT_SUM(Summation, In, Out) \ - { \ - Summation Sum; \ - Sum.Add(In); \ - EXPECT_EQ(Sum.Result().Value(), Out) << #Summation << " for '" << In << "'"; \ - } - - // From FIPS PUB 180-1 - EXPECT_SUM(SHA1Summation, "","da39a3ee5e6b4b0d3255bfef95601890afd80709"); - EXPECT_SUM(SHA1Summation, "abc","a9993e364706816aba3e25717850c26c9cd0d89d"); - EXPECT_SUM(SHA1Summation, "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq", - "84983e441c3bd26ebaae4aa1f95129e5e54670f1"); - - // MD5 tests from RFC 1321 - EXPECT_SUM(MD5Summation, "","d41d8cd98f00b204e9800998ecf8427e"); - EXPECT_SUM(MD5Summation, "a","0cc175b9c0f1b6a831c399e269772661"); - EXPECT_SUM(MD5Summation, "abc","900150983cd24fb0d6963f7d28e17f72"); - EXPECT_SUM(MD5Summation, "message digest","f96b697d7cb7938d525a2f31aaf161d0"); - EXPECT_SUM(MD5Summation, "abcdefghijklmnopqrstuvwxyz","c3fcd3d76192e4007dfb496cca67e13b"); - EXPECT_SUM(MD5Summation, "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789", - "d174ab98d277d9f5a5611c2c9f419d9f"); - EXPECT_SUM(MD5Summation, "12345678901234567890123456789012345678901234567890123456789012345678901234567890", - "57edf4a22be3c955ac49da2e2107b67a"); - - // SHA-256, From FIPS 180-2 - EXPECT_SUM(SHA256Summation, "", "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"); - EXPECT_SUM(SHA256Summation, "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq", - "248d6a61d20638b8e5c026930c3e6039a33ce45964ff2167f6ecedd419db06c1"); - - // SHA-512 - EXPECT_SUM(SHA512Summation, "", - "cf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921d36ce9ce" - "47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e"); - EXPECT_SUM(SHA512Summation, "abc", - "ddaf35a193617abacc417349ae20413112e6fa4e89a97ea20a9eeee64b55d39a" - "2192992a274fc1a836ba3c23a3feebbd454d4423643ce80e2a9ac94fa54ca49f"); - - - EXPECT_SUM(MD5Summation, "The quick brown fox jumps over the lazy dog", "9e107d9d372bb6826bd81d3542a419d6"); - EXPECT_SUM(MD5Summation, "The quick brown fox jumps over the lazy dog.", "e4d909c290d0fb1ca068ffaddf22cbd0"); - EXPECT_SUM(SHA1Summation, "The quick brown fox jumps over the lazy dog", "2fd4e1c67a2d28fced849ee1bb76e7391b93eb12"); - EXPECT_SUM(SHA1Summation, "The quick brown fox jumps over the lazy cog", "de9f2c7fd25e1b3afad3e85a0bd17d9b100db4b3"); - EXPECT_SUM(SHA256Summation, "The quick brown fox jumps over the lazy dog", "d7a8fbb307d7809469ca9abcb0082e4f8d5651e46d3cdb762d02d0bf37c9e592"); - EXPECT_SUM(SHA256Summation, "The quick brown fox jumps over the lazy dog.", "ef537f25c895bfa782526529a9b63d97aa631564d5d789c2b765448c8635fb6c"); - EXPECT_SUM(SHA512Summation, "The quick brown fox jumps over the lazy dog", "07e547d9586f6a73f73fbac0435ed76951218fb7d0c8d788a309d785436bbb64" - "2e93a252a954f23912547d1e8a3b5ed6e1bfd7097821233fa0538f3db854fee6"); - EXPECT_SUM(SHA512Summation, "The quick brown fox jumps over the lazy dog.", "91ea1245f20d46ae9a037a989f54f1f790f0a47607eeb8a14d12890cea77a1bb" - "c6c7ed9cf205e67b7f2b8fd4c7dfd3a7a8617e45f3c463d481c7e586c39ac1ed"); - -#undef EXPECT_SUM -} -TEST(HashSumsTest, Mill) -{ - SHA1Summation Sum1; - - const unsigned char As[] = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; - size_t const AsCount = sizeof(As)/sizeof(As[0]) - 1; - size_t Count = 1000000; - while (Count != 0) - { - if (Count >= AsCount) - { - Sum1.Add(As, AsCount); - Count -= AsCount; - } - else - { - Sum1.Add(As,Count); - Count = 0; - } - } - - EXPECT_EQ("34aa973cd4c4daa4f61eeb2bdbad27316534016f", Sum1.Result().Value()); -} - static void getSummationString(char const * const type, std::string &sum) { /* to compare our result with an independent source we call the specific binaries @@ -146,20 +66,20 @@ TEST(HashSumsTest, FileBased) std::string summation; getSummationString("md5sum", summation); - MD5SumValue md5(summation); - EXPECT_EQ(md5.Value(), summation); + HashString md5("MD5Sum", summation); + EXPECT_EQ(md5.HashValue(), summation); getSummationString("sha1sum", summation); - SHA1SumValue sha1(summation); - EXPECT_EQ(sha1.Value(), summation); + HashString sha1("SHA1", summation); + EXPECT_EQ(sha1.HashValue(), summation); getSummationString("sha256sum", summation); - SHA256SumValue sha256(summation); - EXPECT_EQ(sha256.Value(), summation); + HashString sha256("SHA256", summation); + EXPECT_EQ(sha256.HashValue(), summation); getSummationString("sha512sum", summation); - SHA512SumValue sha512(summation); - EXPECT_EQ(sha512.Value(), summation); + HashString sha512("SHA512", summation); + EXPECT_EQ(sha512.HashValue(), summation); FileFd fd("/etc/os-release", FileFd::ReadOnly); EXPECT_TRUE(fd.IsOpen()); @@ -172,10 +92,10 @@ TEST(HashSumsTest, FileBased) HashStringList list = hashes.GetHashStringList(); EXPECT_FALSE(list.empty()); EXPECT_EQ(5u, list.size()); - EXPECT_EQ(md5.Value(), list.find("MD5Sum")->HashValue()); - EXPECT_EQ(sha1.Value(), list.find("SHA1")->HashValue()); - EXPECT_EQ(sha256.Value(), list.find("SHA256")->HashValue()); - EXPECT_EQ(sha512.Value(), list.find("SHA512")->HashValue()); + EXPECT_EQ(md5.HashValue(), list.find("MD5Sum")->HashValue()); + EXPECT_EQ(sha1.HashValue(), list.find("SHA1")->HashValue()); + EXPECT_EQ(sha256.HashValue(), list.find("SHA256")->HashValue()); + EXPECT_EQ(sha512.HashValue(), list.find("SHA512")->HashValue()); EXPECT_EQ(FileSize, list.find("Checksum-FileSize")->HashValue()); } unsigned long long sz = fd.FileSize(); @@ -186,10 +106,10 @@ TEST(HashSumsTest, FileBased) HashStringList list = hashes.GetHashStringList(); EXPECT_FALSE(list.empty()); EXPECT_EQ(5u, list.size()); - EXPECT_EQ(md5.Value(), list.find("MD5Sum")->HashValue()); - EXPECT_EQ(sha1.Value(), list.find("SHA1")->HashValue()); - EXPECT_EQ(sha256.Value(), list.find("SHA256")->HashValue()); - EXPECT_EQ(sha512.Value(), list.find("SHA512")->HashValue()); + EXPECT_EQ(md5.HashValue(), list.find("MD5Sum")->HashValue()); + EXPECT_EQ(sha1.HashValue(), list.find("SHA1")->HashValue()); + EXPECT_EQ(sha256.HashValue(), list.find("SHA256")->HashValue()); + EXPECT_EQ(sha512.HashValue(), list.find("SHA512")->HashValue()); EXPECT_EQ(FileSize, list.find("Checksum-FileSize")->HashValue()); } fd.Seek(0); @@ -199,10 +119,10 @@ TEST(HashSumsTest, FileBased) HashStringList list = hashes.GetHashStringList(); EXPECT_FALSE(list.empty()); EXPECT_EQ(3u, list.size()); - EXPECT_EQ(md5.Value(), list.find("MD5Sum")->HashValue()); + EXPECT_EQ(md5.HashValue(), list.find("MD5Sum")->HashValue()); EXPECT_EQ(NULL, list.find("SHA1")); EXPECT_EQ(NULL, list.find("SHA256")); - EXPECT_EQ(sha512.Value(), list.find("SHA512")->HashValue()); + EXPECT_EQ(sha512.HashValue(), list.find("SHA512")->HashValue()); EXPECT_EQ(FileSize, list.find("Checksum-FileSize")->HashValue()); fd.Seek(0); Hashes hashes2(list); @@ -210,39 +130,39 @@ TEST(HashSumsTest, FileBased) list = hashes2.GetHashStringList(); EXPECT_FALSE(list.empty()); EXPECT_EQ(3u, list.size()); - EXPECT_EQ(md5.Value(), list.find("MD5Sum")->HashValue()); + EXPECT_EQ(md5.HashValue(), list.find("MD5Sum")->HashValue()); EXPECT_EQ(NULL, list.find("SHA1")); EXPECT_EQ(NULL, list.find("SHA256")); - EXPECT_EQ(sha512.Value(), list.find("SHA512")->HashValue()); + EXPECT_EQ(sha512.HashValue(), list.find("SHA512")->HashValue()); EXPECT_EQ(FileSize, list.find("Checksum-FileSize")->HashValue()); } fd.Seek(0); { - MD5Summation MD5; + Hashes MD5(Hashes::MD5SUM); MD5.AddFD(fd.Fd()); - EXPECT_EQ(md5.Value(), MD5.Result().Value()); + EXPECT_EQ(md5, MD5.GetHashString(Hashes::MD5SUM)); } fd.Seek(0); { - SHA1Summation SHA1; + Hashes SHA1(Hashes::SHA1SUM); SHA1.AddFD(fd.Fd()); - EXPECT_EQ(sha1.Value(), SHA1.Result().Value()); + EXPECT_EQ(sha1, SHA1.GetHashString(Hashes::SHA1SUM)); } fd.Seek(0); { - SHA256Summation SHA2; + Hashes SHA2(Hashes::SHA256SUM); SHA2.AddFD(fd.Fd()); - EXPECT_EQ(sha256.Value(), SHA2.Result().Value()); + EXPECT_EQ(sha256, SHA2.GetHashString(Hashes::SHA256SUM)); } fd.Seek(0); { - SHA512Summation SHA2; + Hashes SHA2(Hashes::SHA512SUM); SHA2.AddFD(fd.Fd()); - EXPECT_EQ(sha512.Value(), SHA2.Result().Value()); + EXPECT_EQ(sha512, SHA2.GetHashString(Hashes::SHA512SUM)); } fd.Close(); - HashString sha2file("SHA512", sha512.Value()); + HashString sha2file("SHA512", sha512.HashValue()); EXPECT_TRUE(sha2file.VerifyFile("/etc/os-release")); HashString sha2wrong("SHA512", "00000000000"); EXPECT_FALSE(sha2wrong.VerifyFile("/etc/os-release")); @@ -251,9 +171,9 @@ TEST(HashSumsTest, FileBased) EXPECT_NE(sha2file, sha2wrong); EXPECT_TRUE(sha2file != sha2wrong); - HashString sha2big("SHA256", sha256.Value()); + HashString sha2big("SHA256", sha256.HashValue()); EXPECT_TRUE(sha2big.VerifyFile("/etc/os-release")); - HashString sha2small("sha256:" + sha256.Value()); + HashString sha2small("sha256:" + sha256.HashValue()); EXPECT_TRUE(sha2small.VerifyFile("/etc/os-release")); EXPECT_EQ(sha2big, sha2small); EXPECT_TRUE(sha2big == sha2small); diff --git a/test/libapt/pattern_test.cc b/test/libapt/pattern_test.cc index de2fbceb9..bfcaf2093 100644 --- a/test/libapt/pattern_test.cc +++ b/test/libapt/pattern_test.cc @@ -14,21 +14,53 @@ using namespace APT::Internal; +#define EXPECT_EXCEPTION(exp, exc, msg) \ + caught = false; \ + try \ + { \ + exp; \ + } \ + catch (exc & e) \ + { \ + caught = true; \ + EXPECT_TRUE(e.message.find(msg) != std::string::npos) << msg << " not in " << e.message; \ + }; \ + EXPECT_TRUE(caught) << #exp "should have thrown an exception" + +TEST(TreeParserTest, ParseInvalid) +{ + bool caught = false; + + // Not a valid pattern: Reject + EXPECT_EXCEPTION(PatternTreeParser("?").parse(), PatternTreeParser::Error, "Pattern must have a term"); + EXPECT_EXCEPTION(PatternTreeParser("?AB?").parse(), PatternTreeParser::Error, "Pattern must have a term"); + EXPECT_EXCEPTION(PatternTreeParser("~").parse(), PatternTreeParser::Error, "Unknown short pattern"); + + // Not a pattern at all: Report nullptr + EXPECT_EQ(PatternTreeParser("A?").parse(), nullptr); +} + TEST(TreeParserTest, ParseWord) { - auto node = PatternTreeParser("word").parseTop(); - auto wordNode = dynamic_cast<PatternTreeParser::WordNode *>(node.get()); + auto node = PatternTreeParser("?word(word)").parseTop(); + auto patternNode = dynamic_cast<PatternTreeParser::PatternNode *>(node.get()); - EXPECT_EQ(node.get(), wordNode); + ASSERT_EQ(patternNode->arguments.size(), 1u); + auto wordNode = dynamic_cast<PatternTreeParser::WordNode *>(patternNode->arguments[0].get()); + + EXPECT_EQ(patternNode->arguments[0].get(), wordNode); EXPECT_EQ(wordNode->word, "word"); } TEST(TreeParserTest, ParseQuotedWord) { - auto node = PatternTreeParser("\"a word\"").parseTop(); - auto wordNode = dynamic_cast<PatternTreeParser::WordNode *>(node.get()); + auto node = PatternTreeParser("?word(\"a word\")").parseTop(); + auto patternNode = dynamic_cast<PatternTreeParser::PatternNode *>(node.get()); - EXPECT_EQ(node.get(), wordNode); + ASSERT_EQ(patternNode->arguments.size(), 1u); + auto wordNode = dynamic_cast<PatternTreeParser::WordNode *>(patternNode->arguments[0].get()); + + EXPECT_EQ(patternNode->arguments[0].get(), wordNode); EXPECT_EQ(wordNode->word, "a word"); } @@ -93,3 +125,98 @@ TEST(TreeParserTest, ParseWithManyArgsWithSpacesWithTrailingComma) EXPECT_EQ(patternNode->term, "?hello"); EXPECT_EQ(2u, patternNode->arguments.size()); } + +// Helper +static bool samePattern(const std::unique_ptr<PatternTreeParser::Node> &a, const std::unique_ptr<PatternTreeParser::Node> &b) +{ + auto pa = dynamic_cast<const PatternTreeParser::PatternNode *>(a.get()); + auto pb = dynamic_cast<const PatternTreeParser::PatternNode *>(b.get()); + + if (pa && pb) + { + if (pa->term != pb->term || pa->haveArgumentList != pb->haveArgumentList || pa->arguments.size() != pb->arguments.size()) + return false; + + for (size_t i = 0; i < pa->arguments.size(); i++) + { + if (!samePattern(pa->arguments[i], pb->arguments[i])) + return false; + } + return true; + } + + auto wa = dynamic_cast<const PatternTreeParser::WordNode *>(a.get()); + auto wb = dynamic_cast<const PatternTreeParser::WordNode *>(b.get()); + if (wa && wb) + return wa->word == wb->word && wa->quoted == wb->quoted; + + return false; +} + +#define EXPECT_PATTERN_EQ(shrt, lng) \ + EXPECT_TRUE(samePattern(PatternTreeParser(shrt).parseTop(), PatternTreeParser(lng).parseTop())) +#define EXPECT_PATTERN_EQ_ATOMIC(shrt, lng) \ + EXPECT_TRUE(PatternTreeParser(shrt).parseTop()); \ + caught = false; \ + try \ + { \ + PatternTreeParser(shrt "XXX").parseTop(); \ + } \ + catch (PatternTreeParser::Error & e) \ + { \ + caught = true; \ + }; \ + EXPECT_TRUE(caught) << shrt "XXX should have thrown an exception"; \ + EXPECT_PATTERN_EQ(shrt, lng) + +TEST(TreeParserTest, ParseShortPattern) +{ + bool caught; + EXPECT_PATTERN_EQ("~ramd64", "?architecture(amd64)"); + EXPECT_PATTERN_EQ("~AanArchive", "?archive(anArchive)"); + EXPECT_PATTERN_EQ_ATOMIC("~M", "?automatic"); + EXPECT_PATTERN_EQ_ATOMIC("~b", "?broken"); + EXPECT_PATTERN_EQ_ATOMIC("~c", "?config-files"); + EXPECT_PATTERN_EQ_ATOMIC("~E", "?essential"); + EXPECT_PATTERN_EQ_ATOMIC("~F", "?false"); + EXPECT_PATTERN_EQ_ATOMIC("~g", "?garbage"); + EXPECT_PATTERN_EQ_ATOMIC("~i", "?installed"); + EXPECT_PATTERN_EQ("~napt", "?name(apt)"); + EXPECT_PATTERN_EQ_ATOMIC("~o", "?obsolete"); + EXPECT_PATTERN_EQ("~Obar", "?origin(bar)"); + EXPECT_PATTERN_EQ("~sfoo", "?section(foo)"); + EXPECT_PATTERN_EQ("~esourcename", "?source-package(sourcename)"); + EXPECT_PATTERN_EQ_ATOMIC("~T", "?true"); + EXPECT_PATTERN_EQ_ATOMIC("~U", "?upgradable"); + EXPECT_PATTERN_EQ("~Vverstr", "?version(verstr)"); + EXPECT_PATTERN_EQ_ATOMIC("~v", "?virtual"); + EXPECT_PATTERN_EQ("!?foo", "?not(?foo)"); + + caught = false; + try + { + PatternTreeParser("!x").parseTop(); + } + catch (PatternTreeParser::Error &e) + { + caught = true; + }; + EXPECT_TRUE(caught) << "!X should have thrown an exception"; + + EXPECT_PATTERN_EQ("?a?b", "?and(?a, ?b)"); + EXPECT_PATTERN_EQ("~T~F", "?and(?true, ?false)"); + EXPECT_PATTERN_EQ("~T ~F", "?and(?true, ?false)"); + EXPECT_PATTERN_EQ("~T !~F", "?and(?true, ?not(?false))"); + EXPECT_PATTERN_EQ("!~F ~T", "?and(?not(?false), ?true)"); + EXPECT_PATTERN_EQ("!~F~T", "?and(?not(?false), ?true)"); + + EXPECT_PATTERN_EQ("!~F~T | ~T", "?or(?and(?not(?false), ?true), ?true)"); + EXPECT_PATTERN_EQ("~ramd64|~rall", "?or(?architecture(amd64), ?architecture(all))"); + EXPECT_PATTERN_EQ("~ramd64 | ~rall", "?or(?architecture(amd64), ?architecture(all))"); + EXPECT_PATTERN_EQ("~ramd64?name(foo)", "?and(?architecture(amd64), ?name(foo))"); + + EXPECT_PATTERN_EQ("(?A|?B)?C", "?and(?or(?A, ?B), ?C)"); + EXPECT_PATTERN_EQ("?A|?B?C", "?or(?A, ?and(?B, ?C))"); + EXPECT_PATTERN_EQ("?A|(?B?C)", "?or(?A, ?and(?B, ?C))"); + EXPECT_PATTERN_EQ("(?B?C)|?A", "?or(?and(?B, ?C), ?A)"); +} |