diff options
Diffstat (limited to 'test')
30 files changed, 878 insertions, 379 deletions
diff --git a/test/integration/framework b/test/integration/framework index 44dedb10b..e30fa066c 100644 --- a/test/integration/framework +++ b/test/integration/framework @@ -585,10 +585,14 @@ configdpkg() { # the arch apt treats as native might be foreign for dpkg for ARCH in ${ARCHS}; do if [ "${ARCH}" != "${DPKGARCH}" ]; then - if ! dpkg --add-architecture ${ARCH} >/dev/null 2>&1; then - # old-style used e.g. in Ubuntu-P – and as it seems travis - echo "DPKG::options:: \"--foreign-architecture\";" >> rootdir/etc/apt/apt.conf.d/00foreigndpkg - echo "DPKG::options:: \"${ARCH}\";" >> rootdir/etc/apt/apt.conf.d/00foreigndpkg + if ! dpkg --add-architecture ${ARCH} >rootdir/tmp/dpkgaddarch.output 2>&1; then + if grep -q 'pkg-config-dpkghook' rootdir/tmp/dpkgaddarch.output; then + msgwarn 'Ignoring failure of dpkg --add-architecture as it is likely due to pkg-config-dpkghook (see #824774)' + else + # old-style used e.g. in Ubuntu-P – and as it seems travis + echo "DPKG::options:: \"--foreign-architecture\";" >> rootdir/etc/apt/apt.conf.d/00foreigndpkg + echo "DPKG::options:: \"${ARCH}\";" >> rootdir/etc/apt/apt.conf.d/00foreigndpkg + fi fi fi done diff --git a/test/integration/test-bug-549968-install-depends-of-not-installed b/test/integration/test-bug-549968-install-depends-of-not-installed index fab67c4e9..90ce58a33 100755 --- a/test/integration/test-bug-549968-install-depends-of-not-installed +++ b/test/integration/test-bug-549968-install-depends-of-not-installed @@ -17,7 +17,7 @@ setupaptarchive testsuccessequal "Reading package lists... Building dependency tree... MarkInstall coolstuff:i386 < none -> 1.0 @un puN IPb > FU=1 - Ignore MarkInstall of extracoolstuff:i386 < none | 1.0 @hn puH > as its mode (Keep) is protected + coolstuff:i386 Recommends on extracoolstuff:i386 < none | 1.0 @hn puH > can't be satisfied! (dep) Package 'extracoolstuff' is not installed, so not removed Recommended packages: extracoolstuff diff --git a/test/integration/test-bug-604222-new-and-autoremove b/test/integration/test-bug-604222-new-and-autoremove index 6009ca0d2..aaeac09a8 100755 --- a/test/integration/test-bug-604222-new-and-autoremove +++ b/test/integration/test-bug-604222-new-and-autoremove @@ -59,12 +59,10 @@ The following package was automatically installed and is no longer required: libvtk5.4 Use '$AUTOREMOVE' to remove it. The following additional packages will be installed: - libavcodec52 libopenal-dev libvtk5.4 + libavcodec52 libopenal-dev The following NEW packages will be installed: dummy-archive libavcodec52 libopenal-dev -The following packages will be upgraded: - libvtk5.4 -1 upgraded, 3 newly installed, 0 to remove and 0 not upgraded. +0 upgraded, 3 newly installed, 0 to remove and 1 not upgraded. After this operation, 129 kB of additional disk space will be used. E: Trivial Only specified but this is not a trivial operation." aptget install dummy-archive --trivial-only testequal "Reading package lists... @@ -73,12 +71,10 @@ Reading state information... 1 package was automatically installed and is no longer required. Use '$AUTOREMOVE' to remove it. The following additional packages will be installed: - libavcodec52 libopenal-dev libvtk5.4 + libavcodec52 libopenal-dev The following NEW packages will be installed: dummy-archive libavcodec52 libopenal-dev -The following packages will be upgraded: - libvtk5.4 -1 upgraded, 3 newly installed, 0 to remove and 0 not upgraded. +0 upgraded, 3 newly installed, 0 to remove and 1 not upgraded. After this operation, 129 kB of additional disk space will be used. E: Trivial Only specified but this is not a trivial operation." aptget install dummy-archive --trivial-only -o APT::Get::HideAutoRemove=small @@ -88,12 +84,11 @@ rm -f rootdir/var/lib/apt/extended_states CONFLICTING='Reading package lists... Building dependency tree... MarkInstall dummy-archive:i386 < none -> 0.invalid.0 @un puN Ib > FU=1 - MarkInstall libvtk5-dev:i386 < none -> 5.4.2-8 @un uN Ib > FU=0 - MarkInstall libvtk5.4:i386 < none -> 5.4.2-8 @un uN > FU=0 - MarkKeep libvtk5-dev:i386 < none -> 5.4.2-8 @un uN > FU=0 - MarkKeep libvtk5-dev:i386 < none -> 5.4.2-8 @un uN > FU=0 + MarkInstall libavcodec52:i386 < none -> 4:0.5.2-6 @un puN > FU=0 + MarkInstall libopenal-dev:i386 < none -> 1:1.12.854-2 @un puN > FU=0 + Ignore MarkGarbage of libopenal-dev:i386 < none -> 1:1.12.854-2 @un puN > as its mode (Install) is protected Ignore MarkGarbage of libavcodec52:i386 < none -> 4:0.5.2-6 @un puN > as its mode (Install) is protected - MarkDelete libvtk5.4:i386 < none -> 5.4.2-8 @un ugN > FU=0 + Ignore MarkGarbage of libopenal-dev:i386 < none -> 1:1.12.854-2 @un puN > as its mode (Install) is protected Ignore MarkGarbage of libavcodec52:i386 < none -> 4:0.5.2-6 @un puN > as its mode (Install) is protected The following additional packages will be installed: libavcodec52 libopenal-dev diff --git a/test/integration/test-bug-618848-always-respect-user-requests b/test/integration/test-bug-618848-always-respect-user-requests index 230683a99..1e144f1ee 100755 --- a/test/integration/test-bug-618848-always-respect-user-requests +++ b/test/integration/test-bug-618848-always-respect-user-requests @@ -13,11 +13,12 @@ insertpackage 'unstable' 'exim4-daemon-heavy' 'all' '1.0' 'Depends: libdb4.8' setupaptarchive -testsuccessequal 'Reading package lists... +testsuccessequal "Reading package lists... Building dependency tree... MarkDelete libdb4.8:i386 < 1.0 @ii pmK > FU=1 MarkDelete exim4-daemon-light:i386 < 1.0 @ii mK Ib > FU=0 MarkInstall exim4-daemon-heavy:i386 < none -> 1.0 @un uN Ib > FU=0 + exim4-daemon-heavy:i386 Depends on libdb4.8:i386 < 1.0 @ii pmR > can't be satisfied! (dep) MarkDelete exim4:i386 < 1.0 @ii mK Ib > FU=0 The following packages will be REMOVED: exim4 exim4-daemon-light libdb4.8 @@ -27,4 +28,4 @@ Remv exim4 [1.0] MarkDelete exim4-daemon-light:i386 < 1.0 @ii K > FU=1 Remv exim4-daemon-light [1.0] MarkDelete libdb4.8:i386 < 1.0 @ii K > FU=1 -Remv libdb4.8 [1.0]' aptget remove libdb4.8 -s -o Debug::pkgDepCache::Marker=1 +Remv libdb4.8 [1.0]" aptget remove libdb4.8 -s -o Debug::pkgDepCache::Marker=1 diff --git a/test/integration/test-bug-735967-lib32-to-i386-unavailable b/test/integration/test-bug-735967-lib32-to-i386-unavailable index 9dbd17bfd..b836451fd 100755 --- a/test/integration/test-bug-735967-lib32-to-i386-unavailable +++ b/test/integration/test-bug-735967-lib32-to-i386-unavailable @@ -53,7 +53,7 @@ The following information may help to resolve the situation: The following packages have unmet dependencies: libfoo : Depends: libfoo-bin but it is not installable -E: Error, pkgProblemResolver::Resolve generated breaks, this may be caused by held packages.' aptget install foo -s +E: Unable to correct problems, you have held broken packages.' aptget install foo -s # activate multiarch configarchitecture 'amd64' 'i386' diff --git a/test/integration/test-bug-960705-propagate-protected-to-satisfied-conflict b/test/integration/test-bug-960705-propagate-protected-to-satisfied-conflict new file mode 100755 index 000000000..ad1501b66 --- /dev/null +++ b/test/integration/test-bug-960705-propagate-protected-to-satisfied-conflict @@ -0,0 +1,53 @@ +#!/bin/sh +set -e + +TESTDIR="$(readlink -f "$(dirname "$0")")" +. "$TESTDIR/framework" +setupenvironment +configarchitecture 'amd64' + +insertpackage 'unstable' 'runit-init' 'all' '1' 'Conflicts: systemd-sysv, sysvinit-core, runit-init' +# note how the rest do not know of runit-init +insertpackage 'unstable' 'sysvinit-core' 'all' '1' 'Conflicts: systemd-sysv, sysvinit-core' +insertpackage 'unstable,installed' 'systemd-sysv' 'all' '1' 'Conflicts: systemd-sysv, sysvinit-core' +insertpackage 'unstable,installed' 'init' 'all' '1' 'Pre-Depends: systemd-sysv | sysvinit-core +Important: yes' + +setupaptarchive + +testsuccessequal "Reading package lists... +Building dependency tree... + Removing: systemd-sysv:amd64 as upgrade is not an option for runit-init:amd64 (1) + MarkDelete systemd-sysv:amd64 < 1 @ii mK > FU=0 + MarkInstall runit-init:amd64 < none -> 1 @un puN > FU=1 +Starting pkgProblemResolver with broken count: 1 +Starting 2 pkgProblemResolver with broken count: 1 +Investigating (0) init:amd64 < 1 @ii mK Ib > +Broken init:amd64 PreDepends on systemd-sysv:amd64 < 1 @ii pmR > + Considering systemd-sysv:amd64 0 as a solution to init:amd64 5100 + Added systemd-sysv:amd64 to the remove list +Broken init:amd64 PreDepends on sysvinit-core:amd64 < none @un pH > + Considering sysvinit-core:amd64 0 as a solution to init:amd64 5100 + Ignore MarkKeep of systemd-sysv:amd64 < 1 @ii pmR > as its mode (Delete) is protected +Investigating (1) init:amd64 < 1 @ii mK Ib > +Broken init:amd64 PreDepends on systemd-sysv:amd64 < 1 @ii pmR > + Considering systemd-sysv:amd64 5100 as a solution to init:amd64 5100 +Broken init:amd64 PreDepends on sysvinit-core:amd64 < none @un pH > + Considering sysvinit-core:amd64 0 as a solution to init:amd64 5100 + Or group remove for init:amd64 + MarkDelete init:amd64 < 1 @ii mK Ib > FU=0 +Done +The following packages will be REMOVED: + init systemd-sysv +The following NEW packages will be installed: + runit-init +WARNING: The following essential packages will be removed. +This should NOT be done unless you know exactly what you are doing! + init systemd-sysv (due to init) + MarkDelete init:amd64 < 1 @ii K > FU=1 +0 upgraded, 1 newly installed, 2 to remove and 0 not upgraded. +Remv init [1] + MarkDelete systemd-sysv:amd64 < 1 | none @ii H > FU=1 +Remv systemd-sysv [1] +Inst runit-init (1 unstable [all]) +Conf runit-init (1 unstable [all])" apt install runit-init -so Debug::pkgProblemResolver=1 -o Debug::pkgDepCache::Marker=1 -o Debug::pkgDepCache::AutoInstall=1 diff --git a/test/integration/test-bug-960705-propagate-protected-to-satisfied-depends b/test/integration/test-bug-960705-propagate-protected-to-satisfied-depends new file mode 100755 index 000000000..ca6bf8d7c --- /dev/null +++ b/test/integration/test-bug-960705-propagate-protected-to-satisfied-depends @@ -0,0 +1,45 @@ +#!/bin/sh +set -e + +TESTDIR="$(readlink -f "$(dirname "$0")")" +. "$TESTDIR/framework" +setupenvironment +configarchitecture 'amd64' + +# without requires-foo it is sadly not as clear cut what should happen +insertpackage 'unstable' 'foobar' 'all' '1' 'Depends: foo | bar, requires-foo, conflicts-foo | fine-foo' +insertpackage 'unstable' 'foo' 'all' '1' 'Depends: foo-depends' +insertpackage 'unstable' 'foo-depends' 'all' '1' +insertpackage 'unstable' 'bar' 'all' '1' +insertpackage 'unstable' 'requires-foo' 'all' '1' 'Depends: foo' +insertpackage 'unstable' 'conflicts-foo' 'all' '1' 'Conflicts: foo' +insertpackage 'unstable' 'fine-foo' 'all' '1' + + +setupaptarchive + +testsuccessequal "Reading package lists... +Building dependency tree... + Installing foo:amd64 as Depends of foobar:amd64 + Installing foo-depends:amd64 as Depends of foo:amd64 + Installing requires-foo:amd64 as Depends of foobar:amd64 + Installing conflicts-foo:amd64 as Depends of foobar:amd64 + Installing fine-foo:amd64 as Depends of foobar:amd64 +Starting pkgProblemResolver with broken count: 0 +Starting 2 pkgProblemResolver with broken count: 0 +Done +The following additional packages will be installed: + fine-foo foo foo-depends requires-foo +The following NEW packages will be installed: + fine-foo foo foo-depends foobar requires-foo +0 upgraded, 5 newly installed, 0 to remove and 0 not upgraded. +Inst fine-foo (1 unstable [all]) +Inst foo-depends (1 unstable [all]) +Inst foo (1 unstable [all]) +Inst requires-foo (1 unstable [all]) +Inst foobar (1 unstable [all]) +Conf fine-foo (1 unstable [all]) +Conf foo-depends (1 unstable [all]) +Conf foo (1 unstable [all]) +Conf requires-foo (1 unstable [all]) +Conf foobar (1 unstable [all])" apt install foobar -so Debug::pkgProblemResolver=1 -o Debug::pkgDepCache::AutoInstall=1 diff --git a/test/integration/test-bug-961266-hold-means-hold b/test/integration/test-bug-961266-hold-means-hold new file mode 100755 index 000000000..89c18ba85 --- /dev/null +++ b/test/integration/test-bug-961266-hold-means-hold @@ -0,0 +1,124 @@ +#!/bin/sh +set -e + +TESTDIR="$(readlink -f "$(dirname "$0")")" +. "$TESTDIR/framework" +setupenvironment +configarchitecture 'amd64' 'i386' + +insertinstalledpackage 'git' 'amd64' '1:2.25.1-1' 'Multi-Arch: foreign' +insertinstalledpackage 'git-cvs' 'amd64' '1:2.25.1-1' 'Depends: git (>> 1:2.25.1), git (<< 1:2.25.1-.)' + + +insertpackage 'unstable' 'git' 'amd64,i386' '1:2.26.2-1' 'Multi-Arch: foreign' +insertpackage 'unstable' 'git-cvs' 'amd64,i386' '1:2.26.2-1' 'Depends: git (>> 1:2.26.2), git (<< 1:2.26.2-.)' +insertpackage 'unstable' 'git-ng' 'amd64,i386' '1:2.26.2-1' 'Depends: git (>> 1:2.26.2), git (<< 1:2.26.2-.)' + +setupaptarchive + +msgmsg 'The setup is' 'fine' +UPGRADE='Reading package lists... +Building dependency tree... +Calculating upgrade... +The following packages will be upgraded: + git git-cvs +2 upgraded, 0 newly installed, 0 to remove and 0 not upgraded. +Inst git-cvs [1:2.25.1-1] (1:2.26.2-1 unstable [amd64]) [] +Inst git [1:2.25.1-1] (1:2.26.2-1 unstable [amd64]) +Conf git-cvs (1:2.26.2-1 unstable [amd64]) +Conf git (1:2.26.2-1 unstable [amd64])' +testsuccessequal "$UPGRADE" apt upgrade -s +testsuccessequal "$UPGRADE" aptget upgrade -s +testsuccessequal "$UPGRADE" apt full-upgrade -s +testsuccessequal "$UPGRADE" aptget dist-upgrade -s + +testsuccessequal 'Reading package lists... +Building dependency tree... +The following additional packages will be installed: + git git-cvs +The following NEW packages will be installed: + git-ng +The following packages will be upgraded: + git git-cvs +2 upgraded, 1 newly installed, 0 to remove and 0 not upgraded. +Inst git-cvs [1:2.25.1-1] (1:2.26.2-1 unstable [amd64]) [] +Inst git [1:2.25.1-1] (1:2.26.2-1 unstable [amd64]) +Inst git-ng (1:2.26.2-1 unstable [amd64]) +Conf git-cvs (1:2.26.2-1 unstable [amd64]) +Conf git (1:2.26.2-1 unstable [amd64]) +Conf git-ng (1:2.26.2-1 unstable [amd64])' apt install git-ng -s + + +msgmsg 'Now mix it up by' 'holding git' +testsuccessequal 'git set on hold.' aptmark hold git +testsuccessequal 'git' aptmark showholds + +NOUPGRADE='Reading package lists... +Building dependency tree... +Calculating upgrade... +The following packages have been kept back: + git git-cvs +0 upgraded, 0 newly installed, 0 to remove and 2 not upgraded.' + +testsuccessequal "$NOUPGRADE" apt upgrade -s +testsuccessequal "$NOUPGRADE" apt full-upgrade -s +testsuccessequal "$NOUPGRADE" aptget dist-upgrade -s +testsuccessequal "$NOUPGRADE" aptget upgrade -s + +testfailureequal 'Reading package lists... +Building dependency tree... +Some packages could not be installed. This may mean that you have +requested an impossible situation or if you are using the unstable +distribution that some required packages have not yet been created +or been moved out of Incoming. +The following information may help to resolve the situation: + +The following packages have unmet dependencies: + git-ng : Depends: git (> 1:2.26.2) +E: Unable to correct problems, you have held broken packages.' apt install git-ng -s + + +msgmsg 'Now mix it up by' 'holding git-cvs' +testsuccessequal 'Canceled hold on git.' aptmark unhold git +testsuccessequal 'git-cvs set on hold.' aptmark hold git-cvs +testsuccessequal 'git-cvs' aptmark showholds + +testsuccessequal "$NOUPGRADE" apt upgrade -s +testsuccessequal "$NOUPGRADE" apt full-upgrade -s +testsuccessequal "$NOUPGRADE" aptget upgrade -s +testsuccessequal "$NOUPGRADE" aptget dist-upgrade -s + +testfailureequal 'Reading package lists... +Building dependency tree... +Some packages could not be installed. This may mean that you have +requested an impossible situation or if you are using the unstable +distribution that some required packages have not yet been created +or been moved out of Incoming. +The following information may help to resolve the situation: + +The following packages have unmet dependencies: + git-cvs : Depends: git (< 1:2.25.1-.) +E: Error, pkgProblemResolver::Resolve generated breaks, this may be caused by held packages.' apt install git-ng -s + + +msgmsg 'Now mix it up by' 'holding both' +testsuccessequal 'git set on hold.' aptmark hold git +testsuccessequal 'git +git-cvs' aptmark showholds + +testsuccessequal "$NOUPGRADE" apt upgrade -s +testsuccessequal "$NOUPGRADE" apt full-upgrade -s +testsuccessequal "$NOUPGRADE" aptget upgrade -s +testsuccessequal "$NOUPGRADE" aptget dist-upgrade -s + +testfailureequal 'Reading package lists... +Building dependency tree... +Some packages could not be installed. This may mean that you have +requested an impossible situation or if you are using the unstable +distribution that some required packages have not yet been created +or been moved out of Incoming. +The following information may help to resolve the situation: + +The following packages have unmet dependencies: + git-ng : Depends: git (> 1:2.26.2) +E: Unable to correct problems, you have held broken packages.' apt install git-ng -s diff --git a/test/integration/test-dpkg-i-apt-install-fix-broken b/test/integration/test-dpkg-i-apt-install-fix-broken new file mode 100755 index 000000000..8d800ffb7 --- /dev/null +++ b/test/integration/test-dpkg-i-apt-install-fix-broken @@ -0,0 +1,34 @@ +#!/bin/sh +set -e + +TESTDIR="$(readlink -f "$(dirname "$0")")" +. "$TESTDIR/framework" +setupenvironment +configarchitecture 'amd64' + +buildsimplenativepackage 'autopkgtest-satdep' 'amd64' '1' 'stable' 'Depends: debhelper-compat (= 12)' +buildsimplenativepackage 'debhelper' 'all' '1' 'stable' 'Provides: debhelper-compat (= 12)' + +setupaptarchive + +testfailure dpkg -i incoming/autopkgtest-*.deb +testsuccessequal 'Reading package lists... +Building dependency tree... +Correcting dependencies... MarkInstall autopkgtest-satdep:amd64 < 1 @iU mK Nb Ib > FU=0 + MarkInstall debhelper:amd64 < none -> 1 @un uN > FU=0 +Starting pkgProblemResolver with broken count: 0 +Starting 2 pkgProblemResolver with broken count: 0 +Done + Done +Starting pkgProblemResolver with broken count: 0 +Starting 2 pkgProblemResolver with broken count: 0 +Done +The following additional packages will be installed: + debhelper +The following NEW packages will be installed: + debhelper +0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded. +1 not fully installed or removed. +Inst debhelper (1 stable [all]) +Conf debhelper (1 stable [all]) +Conf autopkgtest-satdep (1 stable [amd64])' apt install -fso Debug::pkgProblemResolver=1 -o DEbug::pkgDepCache::Marker=1 diff --git a/test/integration/test-dpkg-protected b/test/integration/test-dpkg-protected new file mode 100755 index 000000000..3d0994d89 --- /dev/null +++ b/test/integration/test-dpkg-protected @@ -0,0 +1,20 @@ +#!/bin/sh +set -e + +TESTDIR="$(readlink -f "$(dirname "$0")")" +. "$TESTDIR/framework" +setupenvironment +configarchitecture 'amd64' + +insertinstalledpackage 'protected-package' 'native' '1' 'Protected: yes' + +setupaptarchive + + +if dpkg --assert-protected-field 2>/dev/null; then + testsuccess aptget remove protected-package "$@" -o Debug::pkgDpkgPm=1 -y --allow-remove-essential + cp rootdir/tmp/testsuccess.output rootdir/tmp/output + testsuccess grep -- '--force-remove-protected' rootdir/tmp/output +else + msgskip "dpkg does not support protected field" +fi diff --git a/test/integration/test-explore-or-groups-in-markinstall b/test/integration/test-explore-or-groups-in-markinstall index 5669e47b3..ba3376cf6 100755 --- a/test/integration/test-explore-or-groups-in-markinstall +++ b/test/integration/test-explore-or-groups-in-markinstall @@ -9,16 +9,17 @@ configarchitecture 'amd64' insertpackage 'unstable' 'okay' 'all' '1' insertpackage 'unstable' 'upgrade' 'all' '2' insertpackage 'unstable' 'unneeded' 'all' '1' +insertpackage 'unstable' 'unneeded2' 'all' '1' 'Depends: bad-level1' insertpackage 'unstable' 'later' 'all' '1' insertpackage 'unstable' 'bad-level0' 'all' '1' 'Depends: unneeded, unknown' insertpackage 'unstable' 'bad-level1' 'all' '1' 'Depends: bad-level0' insertpackage 'unstable' 'bad-upgrade-level0' 'all' '2' 'Depends: unneeded, unknown' -insertpackage 'unstable' 'bad-upgrade-level1' 'all' '2' 'Depends: bad-upgrade-level0 (>= 2)' +insertpackage 'unstable' 'bad-upgrade-level1' 'all' '2' 'Depends: bad-upgrade-level0 (>= 2), unneeded2' insertpackage 'unstable' 'bad-conflict-level0' 'all' '1' 'Depends: unneeded Conflicts: bad-conflict-level2' insertpackage 'unstable' 'bad-conflict-level1' 'all' '1' 'Depends: bad-conflict-level0' -insertpackage 'unstable' 'bad-conflict-level2' 'all' '1' 'Depends: bad-conflict-level1' +insertpackage 'unstable' 'bad-conflict-level2' 'all' '1' 'Depends: bad-conflict-level1, unneeded2' insertinstalledpackage 'upgrade' 'all' '1' insertinstalledpackage 'bad-upgrade' 'all' '1' @@ -41,16 +42,24 @@ insertfoos 'r' 'Recommends' setupaptarchive -testsuccessheadequal() { - msggroup 'testsuccessheadequal' +_testsuccessheadtailequal() { + local TYPE="$1" + shift + msggroup "testsuccess${TYPE}equal" local HEADLINES="$1" local CMP="$2" shift 2 testsuccesswithglobalerror 'testsuccess' 'EW' "$@" - cp "${TMPWORKINGDIRECTORY}/rootdir/tmp/testsuccess.output" "${TMPWORKINGDIRECTORY}/rootdir/tmp/testsuccessheadequal.output" - testsuccessequal "$CMP" head -n "$HEADLINES" "${TMPWORKINGDIRECTORY}/rootdir/tmp/testsuccessheadequal.output" + cp "${TMPWORKINGDIRECTORY}/rootdir/tmp/testsuccess.output" "${TMPWORKINGDIRECTORY}/rootdir/tmp/testsuccess${TYPE}equal.output" + testsuccessequal "$CMP" "${TYPE}" -n "$HEADLINES" "${TMPWORKINGDIRECTORY}/rootdir/tmp/testsuccess${TYPE}equal.output" msggroup } +testsuccessheadequal() { + _testsuccessheadtailequal 'head' "$@" +} +testsuccesstailequal() { + _testsuccessheadtailequal 'tail' "$@" +} checkfoos() { msgmsg 'Install checks with foos dependency type' "$2" for level in 0 1 2; do @@ -61,6 +70,7 @@ The following additional packages will be installed: The following NEW packages will be installed: foo-${1}-level${level} okay 0 upgraded, 2 newly installed, 0 to remove and 3 not upgraded." apt install foo-${1}-level${level} -s + if [ "$level" = '0' ]; then NOT=2; else NOT=1; fi testsuccessheadequal 9 "Reading package lists... Building dependency tree... The following additional packages will be installed: @@ -69,7 +79,7 @@ The following NEW packages will be installed: foo-${1}-upgrade-level${level} The following packages will be upgraded: upgrade -1 upgraded, 1 newly installed, 0 to remove and $((2-${level})) not upgraded." apt install foo-${1}-upgrade-level${level} -s +1 upgraded, 1 newly installed, 0 to remove and $NOT not upgraded." apt install foo-${1}-upgrade-level${level} -s done testsuccessheadequal 7 "Reading package lists... @@ -82,3 +92,58 @@ The following NEW packages will be installed: } checkfoos 'd' 'Depends' checkfoos 'r' 'Recommends' + +TEST_WITH_APTITUDE=false +msgtest 'Check if aptitude is available for additional tests' +if dpkg-checkbuilddeps -d 'aptitude' /dev/null >/dev/null 2>&1; then + TEST_WITH_APTITUDE=true + # we don't document aptitude config options + sed -i -e '/^#x-apt-configure-index/ d' "$(getaptconfig)" + msgpass +else + msgskip 'not installed' +fi + +if $TEST_WITH_APTITUDE; then + OKAYAPTITUDE='0 packages upgraded, 2 newly installed, 0 to remove and 3 not upgraded. +Need to get 0 B of archives. After unpacking 86.0 kB will be used. +Would download/install/remove packages.' + testsuccesstailequal 3 "$OKAYAPTITUDE" aptitude install foo-d-level2 -sy + testsuccesstailequal 3 "$OKAYAPTITUDE" aptitude install foo-r-level2 -sy + testsuccesstailequal 3 "$OKAYAPTITUDE" aptitude install foo-d-conflict -sy + testsuccesstailequal 3 "$OKAYAPTITUDE" aptitude install foo-r-conflict -sy +fi + +BADSOLVETEXT='Reading package lists... +Building dependency tree... +Some packages could not be installed. This may mean that you have +requested an impossible situation or if you are using the unstable +distribution that some required packages have not yet been created +or been moved out of Incoming. +The following information may help to resolve the situation: +' + +testfailureequal "$BADSOLVETEXT +The following packages have unmet dependencies: + bad-level0 : Depends: unknown but it is not installable + bad-upgrade-level0 : Depends: unknown but it is not installable +E: Unable to correct problems, you have held broken packages." apt install bad-upgrade-level1 -s +testfailureequal "$BADSOLVETEXT +The following packages have unmet dependencies: + bad-conflict-level0 : Conflicts: bad-conflict-level2 but 1 is to be installed + bad-level0 : Depends: unknown but it is not installable +E: Unable to correct problems, you have held broken packages." apt install bad-conflict-level2 -s + +if $TEST_WITH_APTITUDE; then + testsuccesstailequal 6 'The following packages have been kept back: + bad-upgrade-level1 +No packages will be installed, upgraded, or removed. +0 packages upgraded, 0 newly installed, 0 to remove and 3 not upgraded. +Need to get 0 B of archives. After unpacking 0 B will be used. +Would download/install/remove packages.' aptitude install bad-upgrade-level1 -sy + # aptitude does not show the kept back message in this case… + testsuccesstailequal 4 'No packages will be installed, upgraded, or removed. +0 packages upgraded, 0 newly installed, 0 to remove and 3 not upgraded. +Need to get 0 B of archives. After unpacking 0 B will be used. +Would download/install/remove packages.' aptitude install bad-conflict-level2 -sy +fi diff --git a/test/integration/test-external-dependency-solver-protocol b/test/integration/test-external-dependency-solver-protocol index 2c451d5f9..0091263b7 100755 --- a/test/integration/test-external-dependency-solver-protocol +++ b/test/integration/test-external-dependency-solver-protocol @@ -292,3 +292,28 @@ echo 'Error: instant-exit Message: This solver exits instantly' exit 1" 'E: External solver failed with: This solver exits instantly E: Sub-process exit1withmsg returned an error code (1)' + +configarchitecture 'amd64' 'i386' +for arch in 'amd64' 'i386' 'armel' 'armhf'; do + insertinstalledpackage "dummy-httpd-$arch" "$arch" '1' 'Provides: httpd' +done +buildsimplenativepackage 'dummy-webserver' 'all' '1' 'unstable' 'Provides: httpd +Multi-Arch: foreign' +testfailure apt install -s dummy-webserver +testsuccess apt install -s ./incoming/dummy-webserver_1_all.deb +testsuccess apt install -s ./incoming/dummy-webserver_1_all.deb --solver apt +testfailure apt install -s ./incoming/dummy-webserver_1_all.deb --solver dump + +testsuccess aptcache showpkg dummy-webserver --with-source ./incoming/dummy-webserver_1_all.deb +cp -a rootdir/tmp/testsuccess.output showpkg.output +testequal 'Reverse Depends: +Dependencies: +1 - +Provides: +1 - ./incoming/dummy-webserver_1_all.deb (= 1) httpd:armhf (= ) httpd:armel (= ) httpd:i386 (= ) httpd (= ) +Reverse Provides: ' tail -n 6 showpkg.output +testsuccessequal 'Provides: httpd +Provides: httpd +Provides: httpd +Provides: httpd +Provides: httpd' grep 'Provides:' "$APT_EDSP_DUMP_FILENAME" diff --git a/test/integration/test-github-111-invalid-armember b/test/integration/test-github-111-invalid-armember new file mode 100755 index 000000000..1e095eef3 --- /dev/null +++ b/test/integration/test-github-111-invalid-armember @@ -0,0 +1,88 @@ +#!/bin/sh +set -e + +TESTDIR="$(readlink -f "$(dirname "$0")")" +. "$TESTDIR/framework" +setupenvironment +configarchitecture "amd64" +setupaptarchive + +# this used to crash, but it should treat it as an invalid member header +touch ' ' +ar -q test.deb ' ' +testsuccessequal "E: Invalid archive member header" ${APTTESTHELPERSBINDIR}/testdeb test.deb + + +rm test.deb +touch 'x' +ar -q test.deb 'x' +testsuccessequal "E: This is not a valid DEB archive, missing 'debian-binary' member" ${APTTESTHELPERSBINDIR}/testdeb test.deb + + +# <name><size> [ other fields] - name is not nul terminated here, it ends in . +msgmsg "Unterminated ar member name" +printf '!<arch>\0120123456789ABCDE.A123456789A.01234.01234.0123456.012345678.0.' > test.deb +testsuccessequal "E: Invalid archive member header" ${APTTESTHELPERSBINDIR}/testdeb test.deb + + +# unused source code for generating $tar below +maketar() { + cat > maketar.c << EOF + #include <stdio.h> + #include <string.h> + struct tar { + char Name[100]; + char Mode[8]; + char UserID[8]; + char GroupID[8]; + char Size[12]; + char MTime[12]; + char Checksum[8]; + char LinkFlag; + char LinkName[100]; + char MagicNumber[8]; + char UserName[32]; + char GroupName[32]; + char Major[8]; + char Minor[8]; + }; + + int main(void) + { + union { + struct tar t; + char buf[512]; + } t; + for (int i = 0; i < sizeof(t.buf); i++) + t.buf[i] = '7'; + memcpy(t.t.Name, "unterminatedName", 16); + memcpy(t.t.UserName, "userName", 8); + memcpy(t.t.GroupName, "thisIsAGroupNamethisIsAGroupName", 32); + t.t.LinkFlag = 'X'; // I AM BROKEN + memcpy(t.t.Size, "000000000000", sizeof(t.t.Size)); + memset(t.t.Checksum,' ',sizeof(t.t.Checksum)); + + unsigned long sum = 0; + for (int i = 0; i < sizeof(t.buf); i++) + sum += t.buf[i]; + + int written = sprintf(t.t.Checksum, "%lo", sum); + for (int i = written; i < sizeof(t.t.Checksum); i++) + t.t.Checksum[i] = ' '; + fwrite(t.buf, sizeof(t.buf), 1, stdout); + } +EOF + + gcc maketar.c -o maketar -Wall + ./maketar +} + + +# +tar="unterminatedName77777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777700000000000077777777777773544 X777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777userName777777777777777777777777thisIsAGroupNamethisIsAGroupName777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777" +printf '%s' "$tar" | gzip > control.tar.gz +cp control.tar.gz data.tar.gz +touch debian-binary +rm test.deb +ar -q test.deb debian-binary control.tar.gz data.tar.gz +testsuccessequal "W: Unknown TAR header type 88" ${APTTESTHELPERSBINDIR}/testdeb test.deb diff --git a/test/integration/test-multiarch-allowed b/test/integration/test-multiarch-allowed index b74853993..a091635f0 100755 --- a/test/integration/test-multiarch-allowed +++ b/test/integration/test-multiarch-allowed @@ -66,13 +66,12 @@ testfailureequal "$BADPREFIX The following packages have unmet dependencies: foo : Conflicts: foo:i386 but 1 is to be installed foo:i386 : Conflicts: foo but 1 is to be installed -E: Error, pkgProblemResolver::Resolve generated breaks, this may be caused by held packages." aptget install needsfoo:i386 foo:amd64 -s +E: Unable to correct problems, you have held broken packages." aptget install needsfoo:i386 foo:amd64 -s testfailureequal "$BADPREFIX The following packages have unmet dependencies: foo : Conflicts: foo:i386 but 1 is to be installed foo:i386 : Conflicts: foo but 1 is to be installed -E: Error, pkgProblemResolver::Resolve generated breaks, this may be caused by held packages." aptget install needsfoo foo:i386 -s -exit +E: Unable to correct problems, you have held broken packages." aptget install needsfoo foo:i386 -s solveableinsinglearch1() { testsuccessequal "Reading package lists... diff --git a/test/integration/test-no-fds-leaked-to-maintainer-scripts b/test/integration/test-no-fds-leaked-to-maintainer-scripts index 85b3d0ee1..4606408fc 100755 --- a/test/integration/test-no-fds-leaked-to-maintainer-scripts +++ b/test/integration/test-no-fds-leaked-to-maintainer-scripts @@ -40,7 +40,7 @@ testsuccess aptget install -y fdleaks -qq < /dev/null checkfdleak() { msgtest 'Check if fds were not' "leaked: expect $1" - if [ "$(grep 'root root' rootdir/tmp/testsuccess.output | wc -l)" = "$1" ]; then + if [ "$(grep -e 'root root' -e "$(id -un) $(id -gn)" rootdir/tmp/testsuccess.output | wc -l)" = "$1" ]; then msgpass else echo diff --git a/test/integration/test-resolver-delays-remove-decisions b/test/integration/test-resolver-delays-remove-decisions new file mode 100755 index 000000000..d8dfd7c9a --- /dev/null +++ b/test/integration/test-resolver-delays-remove-decisions @@ -0,0 +1,107 @@ +#!/bin/sh +set -e + +TESTDIR="$(readlink -f "$(dirname "$0")")" +. "$TESTDIR/framework" +setupenvironment +configarchitecture 'amd64' 'i386' + +insertinstalledpackage 'stuff' 'all' '1' + +insertpackage 'unstable' 'foobar' 'all' '1' 'Depends: foo | bar' +insertpackage 'unstable' 'foo' 'all' '1' 'Conflicts: stuff +Depends: foo-dep' +insertpackage 'unstable' 'foo-dep' 'all' '1' 'Depends: uninstallable' + +insertpackage 'unstable' 'bar' 'all' '1' + +setupaptarchive + +# We are needlessly removing "stuff" if we don't delay its marking here +# as we do not question the remove later on +testsuccessequal "Reading package lists... +Building dependency tree... + MarkInstall foobar:amd64 < none -> 1 @un puN Ib > FU=1 + Installing foo:amd64 as Depends of foobar:amd64 + Delayed Removing: stuff:amd64 as upgrade is not an option for foo:amd64 (1) + MarkInstall foo:amd64 < none -> 1 @un uN Ib > FU=0 + Installing foo-dep:amd64 as Depends of foo:amd64 + foo-dep:amd64 Depends on uninstallable:amd64 < none @un H > can't be satisfied! + foo:amd64 Depends on foo-dep:amd64 < none @un H > can't be satisfied! (dep) + Installing bar:amd64 as Depends of foobar:amd64 + MarkInstall bar:amd64 < none -> 1 @un uN > FU=0 +Starting pkgProblemResolver with broken count: 0 +Starting 2 pkgProblemResolver with broken count: 0 +Done +The following additional packages will be installed: + bar +The following NEW packages will be installed: + bar foobar +0 upgraded, 2 newly installed, 0 to remove and 0 not upgraded. +Inst bar (1 unstable [all]) +Inst foobar (1 unstable [all]) +Conf bar (1 unstable [all]) +Conf foobar (1 unstable [all])" apt install foobar -s -o Debug::pkgProblemResolver=1 -o Debug::pkgDepCache::Marker=1 -o Debug::pkgDepCache::AutoInstall=1 + +insertinstalledpackage 'uninstallable' 'all' '1' + +testsuccessequal "Reading package lists... +Building dependency tree... + MarkInstall foobar:amd64 < none -> 1 @un puN Ib > FU=1 + Installing foo:amd64 as Depends of foobar:amd64 + Delayed Removing: stuff:amd64 as upgrade is not an option for foo:amd64 (1) + MarkInstall foo:amd64 < none -> 1 @un uN Ib > FU=0 + Installing foo-dep:amd64 as Depends of foo:amd64 + MarkInstall foo-dep:amd64 < none -> 1 @un uN > FU=0 + MarkDelete stuff:amd64 < 1 @ii mK > FU=0 +Starting pkgProblemResolver with broken count: 0 +Starting 2 pkgProblemResolver with broken count: 0 +Done +The following additional packages will be installed: + foo foo-dep +The following packages will be REMOVED: + stuff +The following NEW packages will be installed: + foo foo-dep foobar + MarkDelete stuff:amd64 < 1 @ii K > FU=1 +0 upgraded, 3 newly installed, 1 to remove and 0 not upgraded. +Remv stuff [1] +Inst foo-dep (1 unstable [all]) +Inst foo (1 unstable [all]) +Inst foobar (1 unstable [all]) +Conf foo-dep (1 unstable [all]) +Conf foo (1 unstable [all]) +Conf foobar (1 unstable [all])" apt install foobar -s -o Debug::pkgProblemResolver=1 -o Debug::pkgDepCache::Marker=1 -o Debug::pkgDepCache::AutoInstall=1 + +# Same solution but the installs are considered protected now as there is no other solution +testsuccessequal "Reading package lists... +Building dependency tree... + MarkInstall foobar:amd64 < none -> 1 @un puN Ib > FU=1 + Installing foo:amd64 as Depends of foobar:amd64 + Removing: stuff:amd64 as upgrade is not an option for foo:amd64 (1) + MarkDelete stuff:amd64 < 1 @ii mK > FU=0 + MarkInstall foo:amd64 < none -> 1 @un puN Ib > FU=0 + Installing foo-dep:amd64 as Depends of foo:amd64 + MarkInstall foo-dep:amd64 < none -> 1 @un puN > FU=0 + MarkInstall uninstallable:amd64 < 1 @ii pmK > FU=0 +Starting pkgProblemResolver with broken count: 0 +Starting 2 pkgProblemResolver with broken count: 0 +Done + Ignore MarkGarbage of foo:amd64 < none -> 1 @un puN > as its mode (Install) is protected + Ignore MarkGarbage of foo:amd64 < none -> 1 @un puN > as its mode (Install) is protected +Package 'bar' is not installed, so not removed +The following additional packages will be installed: + foo foo-dep +The following packages will be REMOVED: + stuff +The following NEW packages will be installed: + foo foo-dep foobar + MarkDelete stuff:amd64 < 1 | none @ii H > FU=1 +0 upgraded, 3 newly installed, 1 to remove and 0 not upgraded. +Remv stuff [1] +Inst foo-dep (1 unstable [all]) +Inst foo (1 unstable [all]) +Inst foobar (1 unstable [all]) +Conf foo-dep (1 unstable [all]) +Conf foo (1 unstable [all]) +Conf foobar (1 unstable [all])" apt install foobar bar- -q=0 -s -o Debug::pkgProblemResolver=1 -o Debug::pkgDepCache::Marker=1 -o Debug::pkgDepCache::AutoInstall=1 diff --git a/test/integration/test-resolver-provider-exchange b/test/integration/test-resolver-provider-exchange new file mode 100755 index 000000000..3f5310fa6 --- /dev/null +++ b/test/integration/test-resolver-provider-exchange @@ -0,0 +1,107 @@ +#!/bin/sh +set -e + +TESTDIR="$(readlink -f "$(dirname "$0")")" +. "$TESTDIR/framework" +setupenvironment +configarchitecture 'amd64' + +insertinstalledpackage 'fuse' 'all' '2' +insertpackage 'unstable' 'fuse3' 'all' '3' 'Conflicts: fuse +Provides: fuse' + +insertpackage 'unstable' 'foobar-d' 'all' '1' 'Depends: fuse' +insertpackage 'unstable' 'foobar-d2' 'all' '1' 'Depends: fuse +Conflicts: fuse3' +insertpackage 'unstable' 'foobar-d3' 'all' '1' 'Depends: fuse3' +insertpackage 'unstable' 'foobar-r' 'all' '1' 'Recommends: fuse' +insertpackage 'unstable' 'foobar-r2' 'all' '1' 'Recommends: fuse +Conflicts: fuse3' +insertpackage 'unstable' 'foobar-r3' 'all' '1' 'Recommends: fuse3' + +setupaptarchive + +installfoobars() { + testsuccessequal 'Reading package lists... +Building dependency tree... +The following NEW packages will be installed: + foobar-d +0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded. +Inst foobar-d (1 unstable [all]) +Conf foobar-d (1 unstable [all])' apt install -s foobar-d + testsuccessequal 'Reading package lists... +Building dependency tree... +The following NEW packages will be installed: + foobar-d2 +0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded. +Inst foobar-d2 (1 unstable [all]) +Conf foobar-d2 (1 unstable [all])' apt install -s foobar-d2 + testsuccessequal "Reading package lists... +Building dependency tree... +The following additional packages will be installed: + fuse3 +The following packages will be REMOVED: + fuse +The following NEW packages will be installed: + foobar-d3 fuse3 +0 upgraded, 2 newly installed, 1 to remove and 0 not upgraded. +Remv fuse [2]$1 +Inst fuse3 (3 unstable [all]) +Inst foobar-d3 (1 unstable [all]) +Conf fuse3 (3 unstable [all]) +Conf foobar-d3 (1 unstable [all])" apt install -s foobar-d3 + + testsuccessequal 'Reading package lists... +Building dependency tree... +The following NEW packages will be installed: + foobar-r +0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded. +Inst foobar-r (1 unstable [all]) +Conf foobar-r (1 unstable [all])' apt install -s foobar-r + testsuccessequal 'Reading package lists... +Building dependency tree... +The following NEW packages will be installed: + foobar-r2 +0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded. +Inst foobar-r2 (1 unstable [all]) +Conf foobar-r2 (1 unstable [all])' apt install -s foobar-r2 + if [ -z "$1" ]; then + testsuccessequal "Reading package lists... +Building dependency tree... +The following additional packages will be installed: + fuse3 +The following packages will be REMOVED: + fuse +The following NEW packages will be installed: + foobar-r3 fuse3 +0 upgraded, 2 newly installed, 1 to remove and 0 not upgraded. +Remv fuse [2]$1 +Inst foobar-r3 (1 unstable [all]) +Inst fuse3 (3 unstable [all]) +Conf foobar-r3 (1 unstable [all]) +Conf fuse3 (3 unstable [all])" apt install -s foobar-r3 + else + testsuccessequal "Reading package lists... +Building dependency tree... +The following additional packages will be installed: + fuse3 +The following packages will be REMOVED: + fuse +The following NEW packages will be installed: + foobar-r3 fuse3 +0 upgraded, 2 newly installed, 1 to remove and 0 not upgraded. +Remv fuse [2]$1 +Inst fuse3 (3 unstable [all]) +Inst foobar-r3 (1 unstable [all]) +Conf fuse3 (3 unstable [all]) +Conf foobar-r3 (1 unstable [all])" apt install -s foobar-r3 + fi +} +msgmsg 'fuse has no installed dependers' +installfoobars + +for i in $(seq 0 10); do + insertinstalledpackage "stuff$i" 'all' '1' 'Depends: fuse' +done +msgmsg 'fuse has many dependers installed' +installfoobars ' [stuff10:amd64 stuff0:amd64 stuff1:amd64 stuff2:amd64 stuff3:amd64 stuff4:amd64 stuff5:amd64 stuff6:amd64 stuff7:amd64 stuff8:amd64 stuff9:amd64 ]' diff --git a/test/libapt/authconf_test.cc b/test/libapt/authconf_test.cc index 04d54e9be..f703351cc 100644 --- a/test/libapt/authconf_test.cc +++ b/test/libapt/authconf_test.cc @@ -20,7 +20,7 @@ TEST(NetRCTest, Parsing) EXPECT_EQ("file.not", U.Host); EXPECT_EQ("/open", U.Path); - createTemporaryFile("doublesignedfile", fd, nullptr, R"apt( + openTemporaryFile("doublesignedfile", fd, R"apt( machine example.netter login bar password foo machine example.net login foo password bar @@ -138,7 +138,7 @@ machine socks5h://example.last/debian login debian password rules)apt"); TEST(NetRCTest, BadFileNoMachine) { FileFd fd; - createTemporaryFile("doublesignedfile", fd, nullptr, R"apt( + openTemporaryFile("doublesignedfile", fd, R"apt( foo example.org login foo1 password bar machin example.org login foo2 password bar machine2 example.org login foo3 password bar @@ -152,7 +152,7 @@ machine2 example.org login foo3 password bar TEST(NetRCTest, BadFileEndsMachine) { FileFd fd; - createTemporaryFile("doublesignedfile", fd, nullptr, R"apt( + openTemporaryFile("doublesignedfile", fd, R"apt( machine example.org login foo1 password bar machine)apt"); @@ -176,7 +176,7 @@ machine)apt"); TEST(NetRCTest, BadFileEndsLogin) { FileFd fd; - createTemporaryFile("doublesignedfile", fd, nullptr, R"apt( + openTemporaryFile("doublesignedfile", fd, R"apt( machine example.org login foo1 password bar machine example.net login)apt"); @@ -200,7 +200,7 @@ machine example.net login)apt"); TEST(NetRCTest, BadFileEndsPassword) { FileFd fd; - createTemporaryFile("doublesignedfile", fd, nullptr, R"apt( + openTemporaryFile("doublesignedfile", fd, R"apt( machine example.org login foo1 password bar machine example.net password)apt"); @@ -225,7 +225,7 @@ machine example.net password)apt"); TEST(NetRCTest, MatchesOnlyHTTPS) { FileFd fd; - createTemporaryFile("doublesignedfile", fd, nullptr, R"apt( + openTemporaryFile("doublesignedfile", fd, R"apt( machine https.example login foo1 password bar machine http://http.example login foo1 password bar )apt"); diff --git a/test/libapt/cdrom_test.cc b/test/libapt/cdrom_test.cc index b21492cb7..e2ec05ab8 100644 --- a/test/libapt/cdrom_test.cc +++ b/test/libapt/cdrom_test.cc @@ -91,16 +91,14 @@ TEST(CDROMTest,ReduceSourcelist) } TEST(CDROMTest, FindMountPointForDevice) { - std::string tempfile; - FileFd fd; - createTemporaryFile("mountpoints", fd, &tempfile, + auto const file = createTemporaryFile("mountpoints", "rootfs / rootfs rw 0 0\n" "sysfs /sys sysfs rw,nosuid,nodev,noexec,relatime 0 0\n" "sysfs0 /sys0 sysfs rw,nosuid,nodev,noexec,relatime 0 0\n" "/dev/disk/by-uuid/fadcbc52-6284-4874-aaaa-dcee1f05fe21 / ext4 rw,relatime,errors=remount-ro,data=ordered 0 0\n" "/dev/sda1 /boot/efi vfat rw,nosuid,nodev,noexec,relatime,fmask=0000,dmask=0000,allow_utime=0022,codepage=437,iocharset=utf8,shortname=lower,quiet,utf8,errors=remount-ro,rw,nosuid,nodev,noexec,relatime,fmask=0000,dmask=0000,allow_utime=0022,codepage=437,iocharset=utf8,shortname=lower,quiet,utf8,errors=remount-ro,rw,nosuid,nodev,noexec,relatime,fmask=0000,dmask=0000,allow_utime=0022,codepage=437,iocharset=utf8,shortname=lower,quiet,utf8,errors=remount-ro,rw,nosuid,nodev,noexec,relatime,fmask=0000,dmask=0000,allow_utime=0022,codepage=437,iocharset=utf8,shortname=lower,quiet,utf8,errors=remount-ro 0 0\n" "tmpfs /tmp tmpfs rw,nosuid,nodev,relatime 0 0\n"); - _config->Set("Dir::state::Mountpoints", tempfile); + _config->Set("Dir::state::Mountpoints", file.Name()); EXPECT_EQ("/", FindMountPointForDevice("rootfs")); EXPECT_EQ("/", FindMountPointForDevice("/dev/disk/by-uuid/fadcbc52-6284-4874-aaaa-dcee1f05fe21")); @@ -108,7 +106,4 @@ TEST(CDROMTest, FindMountPointForDevice) EXPECT_EQ("/sys0", FindMountPointForDevice("sysfs0")); EXPECT_EQ("/boot/efi", FindMountPointForDevice("/dev/sda1")); EXPECT_EQ("/tmp", FindMountPointForDevice("tmpfs")); - - if (tempfile.empty() == false) - unlink(tempfile.c_str()); } diff --git a/test/libapt/configuration_test.cc b/test/libapt/configuration_test.cc index 8d6c404b3..4d297a9f2 100644 --- a/test/libapt/configuration_test.cc +++ b/test/libapt/configuration_test.cc @@ -198,9 +198,8 @@ TEST(ConfigurationTest,Merge) TEST(ConfigurationTest, Parsing) { Configuration Cnf; - std::string tempfile; - FileFd fd; - createTemporaryFile("doublesignedfile", fd, &tempfile, R"apt( + { + auto const file = createTemporaryFile("doublesignedfile", R"apt( SimpleOption "true"; /* SimpleOption "false"; */ Answer::Simple "42"; @@ -213,9 +212,8 @@ List::Option2 { "Multi"; }; Trailing "true"; /* Commented::Out "true"; */ )apt"); - EXPECT_TRUE(ReadConfigFile(Cnf, tempfile)); - if (tempfile.empty() == false) - unlink(tempfile.c_str()); + EXPECT_TRUE(ReadConfigFile(Cnf, file.Name())); + } EXPECT_TRUE(Cnf.FindB("SimpleOption")); EXPECT_EQ(42, Cnf.FindI("Answer::Simple")); EXPECT_TRUE(Cnf.Exists("List::Option")); diff --git a/test/libapt/extracttar_test.cc b/test/libapt/extracttar_test.cc index 67e0461c2..ae74341e6 100644 --- a/test/libapt/extracttar_test.cc +++ b/test/libapt/extracttar_test.cc @@ -12,24 +12,32 @@ class Stream : public pkgDirStream public: int count; Stream () { count = 0; } - virtual bool DoItem(Item &Itm,int &Fd) { (void)Itm; (void)Fd; count++; return true; } - virtual bool Fail(Item &Itm,int Fd) { (void)Itm; (void)Fd; return true; } - virtual bool FinishedFile(Item &Itm,int Fd) { (void)Itm; (void)Fd; return true; } - virtual bool Process(Item &Itm,const unsigned char * Data, unsigned long Size,unsigned long Pos) { (void)Itm; (void) Data; (void) Size; (void) Pos; return true; } - virtual ~Stream() {} + bool DoItem(Item &Itm,int &Fd) APT_OVERRIDE { (void)Itm; (void)Fd; count++; return true; } + bool Fail(Item &Itm,int Fd) APT_OVERRIDE { (void)Itm; (void)Fd; return true; } + bool FinishedFile(Item &Itm,int Fd) APT_OVERRIDE { (void)Itm; (void)Fd; return true; } + ~Stream() {} }; TEST(ExtractTar, ExtractTar) { - EXPECT_EQ(system("tar c /etc/passwd 2>/dev/null | gzip > tar.tgz"), 0); + FileFd tgz; + ASSERT_NE(nullptr, GetTempFile("extracttar", false, &tgz)); + ASSERT_TRUE(tgz.Close()); + ASSERT_FALSE(tgz.Name().empty()); + // FIXME: We should do the right thing… but its a test and nobody will ever… + // Proposal: The first one who sees this assert fail will have to write a patch. + ASSERT_EQ(std::string::npos, tgz.Name().find('\'')); + EXPECT_EQ(0, system(("tar c /etc/passwd 2>/dev/null | gzip > " + tgz.Name()).c_str())); - FileFd fd("tar.tgz", FileFd::ReadOnly); - unlink("tar.tgz"); + FileFd fd(tgz.Name(), FileFd::ReadOnly); + RemoveFile("ExtractTarTest", tgz.Name()); + ASSERT_TRUE(fd.IsOpen()); ExtractTar tar(fd, -1, "gzip"); // Run multiple times, because we want to check not only that extraction // works, but also that it works multiple times (important for python-apt) for (int i = 0; i < 5; i++) { + SCOPED_TRACE(i); Stream stream; fd.Seek(0); tar.Go(stream); diff --git a/test/libapt/file-helpers.cc b/test/libapt/file-helpers.cc index aa16a2e30..85fc6838e 100644 --- a/test/libapt/file-helpers.cc +++ b/test/libapt/file-helpers.cc @@ -53,31 +53,31 @@ void helperCreateLink(std::string const &dir, std::string const &targetname, std link.append(linkname); ASSERT_EQ(0, symlink(target.c_str(), link.c_str())); } -void helperCreateTemporaryFile(std::string const &id, FileFd &fd, std::string * const filename, char const * const content) -{ - std::string name("apt-test-"); - name.append(id); - size_t const giventmp = name.find(".XXXXXX."); - if (giventmp == std::string::npos) - name.append(".XXXXXX"); - char * tempfile = strdup(name.c_str()); - ASSERT_STRNE(NULL, tempfile); - int tempfile_fd; - if (giventmp == std::string::npos) - tempfile_fd = mkstemp(tempfile); - else - tempfile_fd = mkstemps(tempfile, name.length() - (giventmp + 7)); - ASSERT_NE(-1, tempfile_fd); - if (filename != NULL) - *filename = tempfile; - else - unlink(tempfile); - free(tempfile); - EXPECT_TRUE(fd.OpenDescriptor(tempfile_fd, FileFd::ReadWrite, true)); - if (content != NULL) +void openTemporaryFile(std::string const &id, FileFd &fd, char const * const content, bool const ImmediateUnlink) +{ + EXPECT_NE(nullptr, GetTempFile("apt-" + id, ImmediateUnlink, &fd)); + EXPECT_TRUE(ImmediateUnlink || not fd.Name().empty()); + if (content != nullptr) { - ASSERT_TRUE(fd.Write(content, strlen(content))); + EXPECT_TRUE(fd.Write(content, strlen(content))); + EXPECT_TRUE(fd.Sync()); fd.Seek(0); } } +ScopedFileDeleter::ScopedFileDeleter(std::string const &filename) : _filename{filename} {} +ScopedFileDeleter::ScopedFileDeleter(ScopedFileDeleter &&sfd) = default; +ScopedFileDeleter& ScopedFileDeleter::operator=(ScopedFileDeleter &&sfd) = default; +ScopedFileDeleter::~ScopedFileDeleter() { + if (not _filename.empty()) + RemoveFile("ScopedFileDeleter", _filename.c_str()); +} +[[nodiscard]] ScopedFileDeleter createTemporaryFile(std::string const &id, char const * const content) +{ + FileFd fd; + openTemporaryFile(id, fd, content, false); + EXPECT_TRUE(fd.IsOpen()); + EXPECT_TRUE(fd.Close()); + EXPECT_FALSE(fd.Name().empty()); + return ScopedFileDeleter{fd.Name()}; +} diff --git a/test/libapt/file-helpers.h b/test/libapt/file-helpers.h index f639c1cbc..4ce0fb2a3 100644 --- a/test/libapt/file-helpers.h +++ b/test/libapt/file-helpers.h @@ -22,8 +22,20 @@ void helperCreateDirectory(std::string const &dir, std::string const &name); #define createLink(dir, targetname, linkname) \ ASSERT_NO_FATAL_FAILURE(helperCreateLink(dir, targetname, linkname)) void helperCreateLink(std::string const &dir, std::string const &targetname, std::string const &linkname); -#define createTemporaryFile(id, fd, filename, content) \ - ASSERT_NO_FATAL_FAILURE(helperCreateTemporaryFile(id, fd, filename, content)) -void helperCreateTemporaryFile(std::string const &id, FileFd &fd, std::string * const filename, char const * const content); + +class ScopedFileDeleter { + std::string _filename; +public: + ScopedFileDeleter(std::string const &filename); + ScopedFileDeleter(ScopedFileDeleter const &) = delete; + ScopedFileDeleter(ScopedFileDeleter &&); + ScopedFileDeleter& operator=(ScopedFileDeleter const &) = delete; + ScopedFileDeleter& operator=(ScopedFileDeleter &&); + ~ScopedFileDeleter(); + + std::string Name() const { return _filename; } +}; +void openTemporaryFile(std::string const &id, FileFd &fd, char const * const content = nullptr, bool const ImmediateUnlink = true); +ScopedFileDeleter createTemporaryFile(std::string const &id, char const * const content = nullptr); #endif diff --git a/test/libapt/fileutl_test.cc b/test/libapt/fileutl_test.cc index 788ab76b2..ecab2eb50 100644 --- a/test/libapt/fileutl_test.cc +++ b/test/libapt/fileutl_test.cc @@ -23,15 +23,12 @@ static void TestFileFd(mode_t const a_umask, mode_t const ExpectedFilePermission strprintf(trace, "TestFileFd: Compressor: %s umask: %#o permission: %#o mode: %d", compressor.Name.c_str(), a_umask, ExpectedFilePermission, filemode); SCOPED_TRACE(trace); - static const char* fname = "apt-filefd-test.txt"; - if (FileExists(fname) == true) - { - EXPECT_EQ(0, unlink(fname)); - } + auto const file = createTemporaryFile("filefd-test"); + EXPECT_TRUE(RemoveFile("TestFileFd", file.Name())); FileFd f; umask(a_umask); - EXPECT_TRUE(f.Open(fname, filemode, compressor)); + EXPECT_TRUE(f.Open(file.Name(), filemode, compressor)); EXPECT_TRUE(f.IsOpen()); EXPECT_FALSE(f.Failed()); EXPECT_EQ(umask(a_umask), a_umask); @@ -45,7 +42,7 @@ static void TestFileFd(mode_t const a_umask, mode_t const ExpectedFilePermission EXPECT_FALSE(f.IsOpen()); EXPECT_FALSE(f.Failed()); - EXPECT_TRUE(f.Open(fname, FileFd::ReadOnly, compressor)); + EXPECT_TRUE(f.Open(file.Name(), FileFd::ReadOnly, compressor)); EXPECT_TRUE(f.IsOpen()); EXPECT_FALSE(f.Failed()); EXPECT_FALSE(f.Eof()); @@ -172,8 +169,7 @@ static void TestFileFd(mode_t const a_umask, mode_t const ExpectedFilePermission // regression test for permission bug LP: #1304657 struct stat buf; - EXPECT_EQ(0, stat(fname, &buf)); - EXPECT_EQ(0, unlink(fname)); + EXPECT_EQ(0, stat(file.Name().c_str(), &buf)); EXPECT_EQ(ExpectedFilePermission, buf.st_mode & 0777); } @@ -385,24 +381,19 @@ static void TestFailingAtomicKeepsFile(char const * const label, std::string con } TEST(FileUtlTest, FailingAtomic) { - FileFd fd; - std::string filename; - createTemporaryFile("failingatomic", fd, &filename, TESTSTRING); - TestFailingAtomicKeepsFile("init", filename); + auto const file = createTemporaryFile("failingatomic", TESTSTRING); + TestFailingAtomicKeepsFile("init", file.Name()); FileFd f; - EXPECT_TRUE(f.Open(filename, FileFd::ReadWrite | FileFd::Atomic)); + EXPECT_TRUE(f.Open(file.Name(), FileFd::ReadWrite | FileFd::Atomic)); f.EraseOnFailure(); EXPECT_FALSE(f.Failed()); EXPECT_TRUE(f.IsOpen()); - TestFailingAtomicKeepsFile("before-fail", filename); + TestFailingAtomicKeepsFile("before-fail", file.Name()); EXPECT_TRUE(f.Write("Bad file write", 10)); f.OpFail(); EXPECT_TRUE(f.Failed()); - TestFailingAtomicKeepsFile("after-fail", filename); + TestFailingAtomicKeepsFile("after-fail", file.Name()); EXPECT_TRUE(f.Close()); - TestFailingAtomicKeepsFile("closed", filename); - - if (filename.empty() == false) - unlink(filename.c_str()); + TestFailingAtomicKeepsFile("closed", file.Name()); } diff --git a/test/libapt/hashsums_test.cc b/test/libapt/hashsums_test.cc index a8a826821..2d8079e5a 100644 --- a/test/libapt/hashsums_test.cc +++ b/test/libapt/hashsums_test.cc @@ -29,15 +29,10 @@ static void getSummationString(char const * const type, std::string &sum) summation is a compressor – and open the 'compressed' file later on directly to read out the summation sum calculated by it */ APT::Configuration::Compressor compress(type, ".ext", type, NULL, NULL, 99); - std::string name("apt-test-"); - name.append("hashsums").append(".XXXXXX"); - char * tempfile = strdup(name.c_str()); - int tempfile_fd = mkstemp(tempfile); - close(tempfile_fd); - ASSERT_NE(-1, tempfile_fd); FileFd fd; - ASSERT_TRUE(fd.Open(tempfile, FileFd::WriteOnly | FileFd::Empty, compress)); + auto const file = createTemporaryFile("hashsums"); + ASSERT_TRUE(fd.Open(file.Name(), FileFd::WriteOnly | FileFd::Empty, compress)); ASSERT_TRUE(fd.IsOpen()); FileFd input("/etc/os-release", FileFd::ReadOnly); ASSERT_TRUE(input.IsOpen()); @@ -48,12 +43,10 @@ static void getSummationString(char const * const type, std::string &sum) ASSERT_FALSE(fd.Failed()); input.Close(); fd.Close(); - ASSERT_TRUE(fd.Open(tempfile, FileFd::ReadOnly, FileFd::None)); + ASSERT_TRUE(fd.Open(file.Name(), FileFd::ReadOnly, FileFd::None)); ASSERT_TRUE(fd.IsOpen()); ASSERT_NE(0u, fd.FileSize()); ASSERT_FALSE(fd.Failed()); - unlink(tempfile); - free(tempfile); char readback[2000]; unsigned long long actual; ASSERT_TRUE(fd.Read(readback, sizeof(readback)/sizeof(readback[0]), &actual)); diff --git a/test/libapt/openmaybeclearsignedfile_test.cc b/test/libapt/openmaybeclearsignedfile_test.cc index 0a4d4438a..4db89679a 100644 --- a/test/libapt/openmaybeclearsignedfile_test.cc +++ b/test/libapt/openmaybeclearsignedfile_test.cc @@ -13,12 +13,21 @@ /* The test files are created with the 'Joe Sixpack' and 'Marvin Paranoid' test key included in the integration testing framework */ -TEST(OpenMaybeClearSignedFileTest,SimpleSignedFile) +static void EXPECT_SUCCESSFUL_PARSE(std::string const &tempfile) { - std::string tempfile; FileFd fd; + EXPECT_TRUE(OpenMaybeClearSignedFile(tempfile, fd)); + EXPECT_TRUE(fd.IsOpen()); + char buffer[100]; + EXPECT_TRUE(fd.ReadLine(buffer, sizeof(buffer))); + EXPECT_STREQ(buffer, "Test"); + EXPECT_TRUE(fd.Eof()); +} + +TEST(OpenMaybeClearSignedFileTest,SimpleSignedFile) +{ // Using c++11 raw-strings would be nifty, but travis doesn't support it… - createTemporaryFile("simplesignedfile", fd, &tempfile, "-----BEGIN PGP SIGNED MESSAGE-----\n" + auto const file = createTemporaryFile("simplesignedfile", "-----BEGIN PGP SIGNED MESSAGE-----\n" "Hash: SHA512\n" "\n" "Test\n" @@ -33,23 +42,14 @@ TEST(OpenMaybeClearSignedFileTest,SimpleSignedFile) "JQt/+gJCPxHUJphy8sccBKhW29CLELJIIafvU30E1nWn9szh2Xjq\n" "=TB1F\n" "-----END PGP SIGNATURE-----\n"); - EXPECT_TRUE(StartsWithGPGClearTextSignature(tempfile)); - EXPECT_TRUE(OpenMaybeClearSignedFile(tempfile, fd)); - if (tempfile.empty() == false) - unlink(tempfile.c_str()); - EXPECT_TRUE(fd.IsOpen()); - char buffer[100]; - EXPECT_TRUE(fd.ReadLine(buffer, sizeof(buffer))); - EXPECT_STREQ(buffer, "Test"); - EXPECT_TRUE(fd.Eof()); + EXPECT_TRUE(StartsWithGPGClearTextSignature(file.Name())); + EXPECT_SUCCESSFUL_PARSE(file.Name()); } TEST(OpenMaybeClearSignedFileTest,WhitespaceSignedFile) { - std::string tempfile; - FileFd fd; // no raw-string here to protect the whitespace from cleanup - createTemporaryFile("simplesignedfile", fd, &tempfile, "-----BEGIN PGP SIGNED MESSAGE----- \t \n" + auto const file = createTemporaryFile("simplesignedfile", "-----BEGIN PGP SIGNED MESSAGE----- \t \n" "Hash: SHA512 \n" " \n" "Test \n" @@ -64,22 +64,13 @@ TEST(OpenMaybeClearSignedFileTest,WhitespaceSignedFile) "JQt/+gJCPxHUJphy8sccBKhW29CLELJIIafvU30E1nWn9szh2Xjq \n" "=TB1F \n" "-----END PGP SIGNATURE-----"); - EXPECT_TRUE(StartsWithGPGClearTextSignature(tempfile)); - EXPECT_TRUE(OpenMaybeClearSignedFile(tempfile, fd)); - if (tempfile.empty() == false) - unlink(tempfile.c_str()); - EXPECT_TRUE(fd.IsOpen()); - char buffer[100]; - EXPECT_TRUE(fd.ReadLine(buffer, sizeof(buffer))); - EXPECT_STREQ(buffer, "Test"); - EXPECT_TRUE(fd.Eof()); + EXPECT_TRUE(StartsWithGPGClearTextSignature(file.Name())); + EXPECT_SUCCESSFUL_PARSE(file.Name()); } TEST(OpenMaybeClearSignedFileTest,SignedFileWithContentHeaders) { - std::string tempfile; - FileFd fd; - createTemporaryFile("headerssignedfile", fd, &tempfile, "-----BEGIN PGP SIGNED MESSAGE-----\n" + auto const file = createTemporaryFile("headerssignedfile", "-----BEGIN PGP SIGNED MESSAGE-----\n" "Version: 0.8.15~exp1\n" "Hash: SHA512\n" "Comment: I love you!\n" @@ -100,22 +91,13 @@ TEST(OpenMaybeClearSignedFileTest,SignedFileWithContentHeaders) "JQt/+gJCPxHUJphy8sccBKhW29CLELJIIafvU30E1nWn9szh2Xjq\n" "=TB1F\n" "-----END PGP SIGNATURE-----\n"); - EXPECT_TRUE(StartsWithGPGClearTextSignature(tempfile)); - EXPECT_TRUE(OpenMaybeClearSignedFile(tempfile, fd)); - if (tempfile.empty() == false) - unlink(tempfile.c_str()); - EXPECT_TRUE(fd.IsOpen()); - char buffer[100]; - EXPECT_TRUE(fd.ReadLine(buffer, sizeof(buffer))); - EXPECT_STREQ(buffer, "Test"); - EXPECT_TRUE(fd.Eof()); + EXPECT_TRUE(StartsWithGPGClearTextSignature(file.Name())); + EXPECT_SUCCESSFUL_PARSE(file.Name()); } TEST(OpenMaybeClearSignedFileTest,SignedFileWithTwoSignatures) { - std::string tempfile; - FileFd fd; - createTemporaryFile("doublesignedfile", fd, &tempfile, "-----BEGIN PGP SIGNED MESSAGE-----\n" + auto const file = createTemporaryFile("doublesignedfile", "-----BEGIN PGP SIGNED MESSAGE-----\n" "Hash: SHA512\n" "\n" "Test\n" @@ -141,23 +123,29 @@ TEST(OpenMaybeClearSignedFileTest,SignedFileWithTwoSignatures) "ASc9hsAZRG0xHuRU0F94V/XrkWw8QYAobJ/yxvs4L0EuA4optbSqawDB\n" "=CP8j\n" "-----END PGP SIGNATURE-----\n"); - EXPECT_TRUE(StartsWithGPGClearTextSignature(tempfile)); - EXPECT_TRUE(OpenMaybeClearSignedFile(tempfile, fd)); - if (tempfile.empty() == false) - unlink(tempfile.c_str()); - EXPECT_TRUE(fd.IsOpen()); - char buffer[100]; - EXPECT_TRUE(fd.ReadLine(buffer, sizeof(buffer))); - EXPECT_STREQ(buffer, "Test"); - EXPECT_TRUE(fd.Eof()); + EXPECT_TRUE(StartsWithGPGClearTextSignature(file.Name())); + EXPECT_SUCCESSFUL_PARSE(file.Name()); } -TEST(OpenMaybeClearSignedFileTest,TwoSimpleSignedFile) + +static void EXPECT_FAILED_PARSE(std::string const &tempfile, std::string const &error) { - std::string tempfile; + EXPECT_TRUE(_error->empty()); FileFd fd; + EXPECT_FALSE(OpenMaybeClearSignedFile(tempfile, fd)); + EXPECT_FALSE(_error->empty()); + EXPECT_FALSE(fd.IsOpen()); + ASSERT_TRUE(_error->PendingError()); + + std::string msg; + EXPECT_TRUE(_error->PopMessage(msg)); + EXPECT_EQ(msg, error); +} + +TEST(OpenMaybeClearSignedFileTest,TwoSimpleSignedFile) +{ // read only the first message - createTemporaryFile("twosimplesignedfile", fd, &tempfile, "-----BEGIN PGP SIGNED MESSAGE-----\n" + auto const file = createTemporaryFile("twosimplesignedfile", "-----BEGIN PGP SIGNED MESSAGE-----\n" "Hash: SHA512\n" "\n" "Test\n" @@ -188,41 +176,21 @@ TEST(OpenMaybeClearSignedFileTest,TwoSimpleSignedFile) "=TB1F\n" "-----END PGP SIGNATURE-----"); EXPECT_TRUE(_error->empty()); - EXPECT_TRUE(StartsWithGPGClearTextSignature(tempfile)); - EXPECT_FALSE(OpenMaybeClearSignedFile(tempfile, fd)); - if (tempfile.empty() == false) - unlink(tempfile.c_str()); - EXPECT_FALSE(_error->empty()); - EXPECT_FALSE(fd.IsOpen()); - + EXPECT_TRUE(StartsWithGPGClearTextSignature(file.Name())); // technically they are signed, but we just want one message - EXPECT_TRUE(_error->PendingError()); - std::string msg; - EXPECT_TRUE(_error->PopMessage(msg)); - EXPECT_EQ("Clearsigned file '" + tempfile + "' contains unsigned lines.", msg); + EXPECT_FAILED_PARSE(file.Name(), "Clearsigned file '" + file.Name() + "' contains unsigned lines."); } TEST(OpenMaybeClearSignedFileTest,UnsignedFile) { - std::string tempfile; - FileFd fd; - createTemporaryFile("unsignedfile", fd, &tempfile, "Test"); - EXPECT_FALSE(StartsWithGPGClearTextSignature(tempfile)); - EXPECT_TRUE(OpenMaybeClearSignedFile(tempfile, fd)); - if (tempfile.empty() == false) - unlink(tempfile.c_str()); - EXPECT_TRUE(fd.IsOpen()); - char buffer[100]; - EXPECT_TRUE(fd.ReadLine(buffer, sizeof(buffer))); - EXPECT_STREQ(buffer, "Test"); - EXPECT_TRUE(fd.Eof()); + auto const file = createTemporaryFile("unsignedfile", "Test"); + EXPECT_FALSE(StartsWithGPGClearTextSignature(file.Name())); + EXPECT_SUCCESSFUL_PARSE(file.Name()); } TEST(OpenMaybeClearSignedFileTest,GarbageTop) { - std::string tempfile; - FileFd fd; - createTemporaryFile("garbagetop", fd, &tempfile, "Garbage\n" + auto const file = createTemporaryFile("garbagetop", "Garbage\n" "-----BEGIN PGP SIGNED MESSAGE-----\n" "Hash: SHA512\n" "\n" @@ -238,25 +206,13 @@ TEST(OpenMaybeClearSignedFileTest,GarbageTop) "JQt/+gJCPxHUJphy8sccBKhW29CLELJIIafvU30E1nWn9szh2Xjq\n" "=TB1F\n" "-----END PGP SIGNATURE-----\n"); - EXPECT_FALSE(StartsWithGPGClearTextSignature(tempfile)); - EXPECT_TRUE(_error->empty()); - EXPECT_FALSE(OpenMaybeClearSignedFile(tempfile, fd)); - if (tempfile.empty() == false) - unlink(tempfile.c_str()); - EXPECT_FALSE(fd.IsOpen()); - ASSERT_FALSE(_error->empty()); - ASSERT_TRUE(_error->PendingError()); - - std::string msg; - EXPECT_TRUE(_error->PopMessage(msg)); - EXPECT_EQ("Clearsigned file '" + tempfile + "' does not start with a signed message block.", msg); + EXPECT_FALSE(StartsWithGPGClearTextSignature(file.Name())); + EXPECT_FAILED_PARSE(file.Name(), "Clearsigned file '" + file.Name() + "' does not start with a signed message block."); } TEST(OpenMaybeClearSignedFileTest,GarbageHeader) { - std::string tempfile; - FileFd fd; - createTemporaryFile("garbageheader", fd, &tempfile, "-----BEGIN PGP SIGNED MESSAGE----- Garbage\n" + auto const file = createTemporaryFile("garbageheader", "-----BEGIN PGP SIGNED MESSAGE----- Garbage\n" "Hash: SHA512\n" "\n" "Test\n" @@ -271,11 +227,10 @@ TEST(OpenMaybeClearSignedFileTest,GarbageHeader) "JQt/+gJCPxHUJphy8sccBKhW29CLELJIIafvU30E1nWn9szh2Xjq\n" "=TB1F\n" "-----END PGP SIGNATURE-----\n"); - EXPECT_FALSE(StartsWithGPGClearTextSignature(tempfile)); + EXPECT_FALSE(StartsWithGPGClearTextSignature(file.Name())); // beware: the file will be successfully opened as unsigned file - EXPECT_TRUE(OpenMaybeClearSignedFile(tempfile, fd)); - if (tempfile.empty() == false) - unlink(tempfile.c_str()); + FileFd fd; + EXPECT_TRUE(OpenMaybeClearSignedFile(file.Name(), fd)); EXPECT_TRUE(fd.IsOpen()); char buffer[100]; EXPECT_TRUE(fd.ReadLine(buffer, sizeof(buffer))); @@ -285,9 +240,7 @@ TEST(OpenMaybeClearSignedFileTest,GarbageHeader) TEST(OpenMaybeClearSignedFileTest,GarbageBottom) { - std::string tempfile; - FileFd fd; - createTemporaryFile("garbagebottom", fd, &tempfile, "-----BEGIN PGP SIGNED MESSAGE-----\n" + auto const file = createTemporaryFile("garbagebottom", "-----BEGIN PGP SIGNED MESSAGE-----\n" "Hash: SHA512\n" "\n" "Test\n" @@ -303,68 +256,34 @@ TEST(OpenMaybeClearSignedFileTest,GarbageBottom) "=TB1F\n" "-----END PGP SIGNATURE-----\n" "Garbage"); - EXPECT_TRUE(StartsWithGPGClearTextSignature(tempfile)); - EXPECT_TRUE(_error->empty()); - EXPECT_FALSE(OpenMaybeClearSignedFile(tempfile, fd)); - if (tempfile.empty() == false) - unlink(tempfile.c_str()); - EXPECT_FALSE(fd.IsOpen()); - ASSERT_FALSE(_error->empty()); - ASSERT_TRUE(_error->PendingError()); - - std::string msg; - EXPECT_TRUE(_error->PopMessage(msg)); - EXPECT_EQ("Clearsigned file '" + tempfile + "' contains unsigned lines.", msg); + EXPECT_TRUE(StartsWithGPGClearTextSignature(file.Name())); + EXPECT_FAILED_PARSE(file.Name(), "Clearsigned file '" + file.Name() + "' contains unsigned lines."); } TEST(OpenMaybeClearSignedFileTest,BogusNoSig) { - std::string tempfile; - FileFd fd; - createTemporaryFile("bogusnosig", fd, &tempfile, "-----BEGIN PGP SIGNED MESSAGE-----\n" + auto const file = createTemporaryFile("bogusnosig", "-----BEGIN PGP SIGNED MESSAGE-----\n" "Hash: SHA512\n" "\n" "Test"); - EXPECT_TRUE(StartsWithGPGClearTextSignature(tempfile)); - EXPECT_TRUE(_error->empty()); - EXPECT_FALSE(OpenMaybeClearSignedFile(tempfile, fd)); - if (tempfile.empty() == false) - unlink(tempfile.c_str()); - EXPECT_FALSE(_error->empty()); - EXPECT_FALSE(fd.IsOpen()); - - std::string msg; - _error->PopMessage(msg); - EXPECT_EQ("Splitting of clearsigned file " + tempfile + " failed as it doesn't contain all expected parts", msg); + EXPECT_TRUE(StartsWithGPGClearTextSignature(file.Name())); + EXPECT_FAILED_PARSE(file.Name(), "Splitting of clearsigned file " + file.Name() + " failed as it doesn't contain all expected parts"); } TEST(OpenMaybeClearSignedFileTest,BogusSigStart) { - std::string tempfile; - FileFd fd; - createTemporaryFile("bogusnosig", fd, &tempfile, "-----BEGIN PGP SIGNED MESSAGE-----\n" + auto const file = createTemporaryFile("bogusnosig", "-----BEGIN PGP SIGNED MESSAGE-----\n" "Hash: SHA512\n" "\n" "Test\n" "-----BEGIN PGP SIGNATURE-----"); - EXPECT_TRUE(StartsWithGPGClearTextSignature(tempfile)); - EXPECT_TRUE(_error->empty()); - EXPECT_FALSE(OpenMaybeClearSignedFile(tempfile, fd)); - if (tempfile.empty() == false) - unlink(tempfile.c_str()); - EXPECT_FALSE(_error->empty()); - EXPECT_FALSE(fd.IsOpen()); - - std::string msg; - _error->PopMessage(msg); - EXPECT_EQ("Signature in file " + tempfile + " wasn't closed", msg); + EXPECT_TRUE(StartsWithGPGClearTextSignature(file.Name())); + EXPECT_FAILED_PARSE(file.Name(), "Signature in file " + file.Name() + " wasn't closed"); } TEST(OpenMaybeClearSignedFileTest,DashedSignedFile) { - std::string tempfile; - FileFd fd; - createTemporaryFile("dashedsignedfile", fd, &tempfile, "-----BEGIN PGP SIGNED MESSAGE-----\n" + auto const file = createTemporaryFile("dashedsignedfile", "-----BEGIN PGP SIGNED MESSAGE-----\n" "Hash: SHA512\n" "\n" "- Test\n" @@ -379,21 +298,12 @@ TEST(OpenMaybeClearSignedFileTest,DashedSignedFile) "JQt/+gJCPxHUJphy8sccBKhW29CLELJIIafvU30E1nWn9szh2Xjq\n" "=TB1F\n" "-----END PGP SIGNATURE-----\n"); - EXPECT_TRUE(StartsWithGPGClearTextSignature(tempfile)); - EXPECT_TRUE(OpenMaybeClearSignedFile(tempfile, fd)); - if (tempfile.empty() == false) - unlink(tempfile.c_str()); - EXPECT_TRUE(fd.IsOpen()); - char buffer[100]; - EXPECT_TRUE(fd.ReadLine(buffer, sizeof(buffer))); - EXPECT_STREQ(buffer, "Test"); - EXPECT_TRUE(fd.Eof()); + EXPECT_TRUE(StartsWithGPGClearTextSignature(file.Name())); + EXPECT_SUCCESSFUL_PARSE(file.Name()); } TEST(OpenMaybeClearSignedFileTest,StrangeDashArmorFile) { - std::string tempfile; - FileFd fd; - createTemporaryFile("strangedashfile", fd, &tempfile, "-----BEGIN PGP SIGNED MESSAGE-----\n" + auto const file = createTemporaryFile("strangedashfile", "-----BEGIN PGP SIGNED MESSAGE-----\n" "Hash: SHA512\n" "-Hash: SHA512\n" "\n" @@ -409,23 +319,12 @@ TEST(OpenMaybeClearSignedFileTest,StrangeDashArmorFile) "JQt/+gJCPxHUJphy8sccBKhW29CLELJIIafvU30E1nWn9szh2Xjq\n" "=TB1F\n" "-----END PGP SIGNATURE-----\n"); - EXPECT_TRUE(StartsWithGPGClearTextSignature(tempfile)); - EXPECT_FALSE(OpenMaybeClearSignedFile(tempfile, fd)); - if (tempfile.empty() == false) - unlink(tempfile.c_str()); - EXPECT_FALSE(_error->empty()); - EXPECT_FALSE(fd.IsOpen()); - - std::string msg; - EXPECT_TRUE(_error->PendingError()); - EXPECT_TRUE(_error->PopMessage(msg)); - EXPECT_EQ("Clearsigned file '" + tempfile + "' contains unexpected line starting with a dash (armor)", msg); + EXPECT_TRUE(StartsWithGPGClearTextSignature(file.Name())); + EXPECT_FAILED_PARSE(file.Name(), "Clearsigned file '" + file.Name() + "' contains unexpected line starting with a dash (armor)"); } TEST(OpenMaybeClearSignedFileTest,StrangeDashMsgFile) { - std::string tempfile; - FileFd fd; - createTemporaryFile("strangedashfile", fd, &tempfile, "-----BEGIN PGP SIGNED MESSAGE-----\n" + auto const file = createTemporaryFile("strangedashfile", "-----BEGIN PGP SIGNED MESSAGE-----\n" "Hash: SHA512\n" "\n" "-Test\n" @@ -440,23 +339,12 @@ TEST(OpenMaybeClearSignedFileTest,StrangeDashMsgFile) "JQt/+gJCPxHUJphy8sccBKhW29CLELJIIafvU30E1nWn9szh2Xjq\n" "=TB1F\n" "-----END PGP SIGNATURE-----\n"); - EXPECT_TRUE(StartsWithGPGClearTextSignature(tempfile)); - EXPECT_FALSE(OpenMaybeClearSignedFile(tempfile, fd)); - if (tempfile.empty() == false) - unlink(tempfile.c_str()); - EXPECT_FALSE(_error->empty()); - EXPECT_FALSE(fd.IsOpen()); - - std::string msg; - EXPECT_TRUE(_error->PendingError()); - EXPECT_TRUE(_error->PopMessage(msg)); - EXPECT_EQ("Clearsigned file '" + tempfile + "' contains unexpected line starting with a dash (msg)", msg); + EXPECT_TRUE(StartsWithGPGClearTextSignature(file.Name())); + EXPECT_FAILED_PARSE(file.Name(), "Clearsigned file '" + file.Name() + "' contains unexpected line starting with a dash (msg)"); } TEST(OpenMaybeClearSignedFileTest,StrangeDashSigFile) { - std::string tempfile; - FileFd fd; - createTemporaryFile("strangedashfile", fd, &tempfile, "-----BEGIN PGP SIGNED MESSAGE-----\n" + auto const file = createTemporaryFile("strangedashfile", "-----BEGIN PGP SIGNED MESSAGE-----\n" "Hash: SHA512\n" "\n" "Test\n" @@ -471,15 +359,6 @@ TEST(OpenMaybeClearSignedFileTest,StrangeDashSigFile) "JQt/+gJCPxHUJphy8sccBKhW29CLELJIIafvU30E1nWn9szh2Xjq\n" "=TB1F\n" "-----END PGP SIGNATURE-----\n"); - EXPECT_TRUE(StartsWithGPGClearTextSignature(tempfile)); - EXPECT_FALSE(OpenMaybeClearSignedFile(tempfile, fd)); - if (tempfile.empty() == false) - unlink(tempfile.c_str()); - EXPECT_FALSE(_error->empty()); - EXPECT_FALSE(fd.IsOpen()); - - std::string msg; - EXPECT_TRUE(_error->PendingError()); - EXPECT_TRUE(_error->PopMessage(msg)); - EXPECT_EQ("Clearsigned file '" + tempfile + "' contains unexpected line starting with a dash (sig)", msg); + EXPECT_TRUE(StartsWithGPGClearTextSignature(file.Name())); + EXPECT_FAILED_PARSE(file.Name(), "Clearsigned file '" + file.Name() + "' contains unexpected line starting with a dash (sig)"); } diff --git a/test/libapt/sourcelist_test.cc b/test/libapt/sourcelist_test.cc index 9441f56be..42fab65a9 100644 --- a/test/libapt/sourcelist_test.cc +++ b/test/libapt/sourcelist_test.cc @@ -14,9 +14,7 @@ TEST(SourceListTest,ParseFileDeb822) { - FileFd fd; - std::string tempfile; - createTemporaryFile("parsefiledeb822.XXXXXX.sources", fd, &tempfile, + auto const file = createTemporaryFile("parsefiledeb822.XXXXXX.sources", "Types: deb\n" "URIs: http://ftp.debian.org/debian\n" "Suites: stable\n" @@ -28,12 +26,8 @@ TEST(SourceListTest,ParseFileDeb822) "URIs: http://ftp.debian.org/debian\n" "Suites: unstable\n" "Components: main non-free\n"); - fd.Close(); pkgSourceList sources; - EXPECT_EQ(true, sources.Read(tempfile)); + EXPECT_TRUE(sources.Read(file.Name())); EXPECT_EQ(2u, sources.size()); - - if (tempfile.empty() == false) - unlink(tempfile.c_str()); } diff --git a/test/libapt/strutil_test.cc b/test/libapt/strutil_test.cc index 5cb6cb9ff..b7132c35f 100644 --- a/test/libapt/strutil_test.cc +++ b/test/libapt/strutil_test.cc @@ -187,7 +187,7 @@ static void ReadMessagesTestWithNewLine(char const * const nl, char const * cons "Description:\n" " ccc"; - createTemporaryFile("readmessage", fd, NULL, (pkgA + nl + pkgB + nl + pkgC + nl).c_str()); + openTemporaryFile("readmessage", fd, (pkgA + nl + pkgB + nl + pkgC + nl).c_str()); std::vector<std::string> list; EXPECT_TRUE(ReadMessages(fd.Fd(), list)); EXPECT_EQ(3u, list.size()); @@ -196,7 +196,7 @@ static void ReadMessagesTestWithNewLine(char const * const nl, char const * cons EXPECT_EQ(pkgC, list[2]); size_t const msgsize = 63990; - createTemporaryFile("readmessage", fd, NULL, NULL); + openTemporaryFile("readmessage", fd); for (size_t j = 0; j < msgsize; ++j) fd.Write(ab, strlen(ab)); for (size_t i = 0; i < 21; ++i) diff --git a/test/libapt/tagfile_test.cc b/test/libapt/tagfile_test.cc index 919b46cdb..06ea01c32 100644 --- a/test/libapt/tagfile_test.cc +++ b/test/libapt/tagfile_test.cc @@ -16,7 +16,7 @@ TEST(TagFileTest,SingleField) { FileFd fd; - createTemporaryFile("singlefield", fd, NULL, "FieldA-12345678: the value of the field"); + openTemporaryFile("singlefield", fd, "FieldA-12345678: the value of the field"); pkgTagFile tfile(&fd); pkgTagSection section; @@ -41,7 +41,7 @@ TEST(TagFileTest,SingleField) EXPECT_FALSE(section.Exists("FieldA-12345678")); EXPECT_FALSE(section.Exists("FieldB-12345678")); - createTemporaryFile("emptyfile", fd, NULL, NULL); + openTemporaryFile("emptyfile", fd); ASSERT_FALSE(tfile.Step(section)); EXPECT_EQ(0u, section.Count()); } @@ -49,7 +49,7 @@ TEST(TagFileTest,SingleField) TEST(TagFileTest,MultipleSections) { FileFd fd; - createTemporaryFile("bigsection", fd, NULL, "Package: pkgA\n" + openTemporaryFile("bigsection", fd, "Package: pkgA\n" "Version: 1\n" "Size: 100\n" "Description: aaa\n" @@ -140,7 +140,7 @@ TEST(TagFileTest,BigSection) content << "Field-" << i << ": " << (2000 + i) << std::endl; FileFd fd; - createTemporaryFile("bigsection", fd, NULL, content.str().c_str()); + openTemporaryFile("bigsection", fd, content.str().c_str()); pkgTagFile tfile(&fd); pkgTagSection section; @@ -230,7 +230,7 @@ TEST(TagFileTest, SpacesEverywhere) TEST(TagFileTest, Comments) { FileFd fd; - createTemporaryFile("commentfile", fd, NULL, "# Leading comments should be ignored.\n" + openTemporaryFile("commentfile", fd, "# Leading comments should be ignored.\n" "\n" "# A wild second comment appears!\n" "\n" @@ -289,7 +289,7 @@ TEST(TagFileTest, Comments) TEST(TagFileTest, EmptyTagName) { FileFd fd; - createTemporaryFile("emptytagname", fd, NULL, "0:\n" + openTemporaryFile("emptytagname", fd, "0:\n" "PACKAGE:0\n" "\n" ":\n" diff --git a/test/libapt/tagsection_test.cc b/test/libapt/tagsection_test.cc index 3f170b25a..80cecca5b 100644 --- a/test/libapt/tagsection_test.cc +++ b/test/libapt/tagsection_test.cc @@ -16,23 +16,9 @@ std::string typoValue = "aa\n" " cc"; std::string typoRawValue = "\n " + typoValue; std::string overrideValue = "1"; -/* - std::cerr << "FILECONTENT: »"; - char buffer[3000]; - while (fd.ReadLine(buffer, sizeof(buffer))) - std::cerr << buffer; - std::cerr << "«" << std::endl;; -*/ -static void setupTestcaseStart(FileFd &fd, pkgTagSection §ion, std::string &content) +static void EXPECT_SECTION_WITH_ALL_CONTENT(pkgTagSection const §ion) { - createTemporaryFile("writesection", fd, NULL, NULL); - content = "Package: " + packageValue + "\n" - "TypoA:\n " + typoValue + "\n" - "Override: " + overrideValue + "\n" - "Override-Backup: " + overrideValue + "\n" - "\n"; - EXPECT_TRUE(section.Scan(content.c_str(), content.length(), true)); EXPECT_TRUE(section.Exists("Package")); EXPECT_TRUE(section.Exists("TypoA")); EXPECT_TRUE(section.Exists("Override")); @@ -45,6 +31,18 @@ static void setupTestcaseStart(FileFd &fd, pkgTagSection §ion, std::string & EXPECT_EQ(1, section.FindI("Override-Backup")); EXPECT_EQ(4u, section.Count()); } + +static void setupTestcaseStart(FileFd &fd, pkgTagSection §ion, std::string &content) +{ + openTemporaryFile("writesection", fd); + content = "Package: " + packageValue + "\n" + "TypoA:\n " + typoValue + "\n" + "Override: " + overrideValue + "\n" + "Override-Backup: " + overrideValue + "\n" + "\n"; + EXPECT_TRUE(section.Scan(content.c_str(), content.length(), true)); + EXPECT_SECTION_WITH_ALL_CONTENT(section); +} TEST(TagSectionTest,WriteUnmodified) { FileFd fd; @@ -55,16 +53,7 @@ TEST(TagSectionTest,WriteUnmodified) EXPECT_TRUE(fd.Seek(0)); pkgTagFile tfile(&fd); ASSERT_TRUE(tfile.Step(section)); - EXPECT_TRUE(section.Exists("Package")); - EXPECT_TRUE(section.Exists("TypoA")); - EXPECT_TRUE(section.Exists("Override")); - EXPECT_TRUE(section.Exists("Override-Backup")); - EXPECT_FALSE(section.Exists("TypoB")); - EXPECT_EQ(packageValue, section.FindS("Package")); - EXPECT_EQ(typoValue, section.FindS("TypoA")); - EXPECT_EQ(1, section.FindI("Override")); - EXPECT_EQ(1, section.FindI("Override-Backup")); - EXPECT_EQ(4u, section.Count()); + EXPECT_SECTION_WITH_ALL_CONTENT(section); } TEST(TagSectionTest,WriteUnmodifiedOrder) { @@ -77,16 +66,7 @@ TEST(TagSectionTest,WriteUnmodifiedOrder) EXPECT_TRUE(fd.Seek(0)); pkgTagFile tfile(&fd); ASSERT_TRUE(tfile.Step(section)); - EXPECT_TRUE(section.Exists("Package")); - EXPECT_TRUE(section.Exists("TypoA")); - EXPECT_TRUE(section.Exists("Override")); - EXPECT_TRUE(section.Exists("Override-Backup")); - EXPECT_FALSE(section.Exists("TypoB")); - EXPECT_EQ(packageValue, section.FindS("Package")); - EXPECT_EQ(typoValue, section.FindS("TypoA")); - EXPECT_EQ(1, section.FindI("Override")); - EXPECT_EQ(1, section.FindI("Override-Backup")); - EXPECT_EQ(4u, section.Count()); + EXPECT_SECTION_WITH_ALL_CONTENT(section); } TEST(TagSectionTest,WriteUnmodifiedOrderReversed) { @@ -99,16 +79,7 @@ TEST(TagSectionTest,WriteUnmodifiedOrderReversed) EXPECT_TRUE(fd.Seek(0)); pkgTagFile tfile(&fd); ASSERT_TRUE(tfile.Step(section)); - EXPECT_TRUE(section.Exists("Package")); - EXPECT_TRUE(section.Exists("TypoA")); - EXPECT_TRUE(section.Exists("Override")); - EXPECT_TRUE(section.Exists("Override-Backup")); - EXPECT_FALSE(section.Exists("TypoB")); - EXPECT_EQ(packageValue, section.FindS("Package")); - EXPECT_EQ(typoValue, section.FindS("TypoA")); - EXPECT_EQ(1, section.FindI("Override")); - EXPECT_EQ(1, section.FindI("Override-Backup")); - EXPECT_EQ(4u, section.Count()); + EXPECT_SECTION_WITH_ALL_CONTENT(section); } TEST(TagSectionTest,WriteUnmodifiedOrderNotAll) { @@ -121,16 +92,7 @@ TEST(TagSectionTest,WriteUnmodifiedOrderNotAll) EXPECT_TRUE(fd.Seek(0)); pkgTagFile tfile(&fd); ASSERT_TRUE(tfile.Step(section)); - EXPECT_TRUE(section.Exists("Package")); - EXPECT_TRUE(section.Exists("TypoA")); - EXPECT_TRUE(section.Exists("Override")); - EXPECT_TRUE(section.Exists("Override-Backup")); - EXPECT_FALSE(section.Exists("TypoB")); - EXPECT_EQ(packageValue, section.FindS("Package")); - EXPECT_EQ(typoValue, section.FindS("TypoA")); - EXPECT_EQ(1, section.FindI("Override")); - EXPECT_EQ(1, section.FindI("Override-Backup")); - EXPECT_EQ(4u, section.Count()); + EXPECT_SECTION_WITH_ALL_CONTENT(section); } TEST(TagSectionTest,WriteNoOrderRename) { |