diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-13 09:59:37 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-13 09:59:37 +0000 |
commit | 76e2632459410dec81337edb6a9fee33c9a660f3 (patch) | |
tree | a73345df208eede4a4daad340515c9328f34625c /test/integration/test-no-fds-leaked-to-maintainer-scripts | |
parent | Initial commit. (diff) | |
download | apt-76e2632459410dec81337edb6a9fee33c9a660f3.tar.xz apt-76e2632459410dec81337edb6a9fee33c9a660f3.zip |
Adding upstream version 2.7.12.upstream/2.7.12
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'test/integration/test-no-fds-leaked-to-maintainer-scripts')
-rwxr-xr-x | test/integration/test-no-fds-leaked-to-maintainer-scripts | 179 |
1 files changed, 179 insertions, 0 deletions
diff --git a/test/integration/test-no-fds-leaked-to-maintainer-scripts b/test/integration/test-no-fds-leaked-to-maintainer-scripts new file mode 100755 index 0000000..2b16552 --- /dev/null +++ b/test/integration/test-no-fds-leaked-to-maintainer-scripts @@ -0,0 +1,179 @@ +#!/bin/sh +set -e + +TESTDIR="$(readlink -f "$(dirname "$0")")" +. "$TESTDIR/framework" + +setupenvironment +configarchitecture 'amd64' 'i386' +configdpkgnoopchroot + +if [ ! -e /proc/self/fd ]; then + msgskip "needs /proc/self/fd" + exit 0 +fi + +setupsimplenativepackage "fdleaks" 'all' '1.0' 'unstable' +BUILDDIR="incoming/fdleaks-1.0" +for script in 'preinst' 'postinst' 'prerm' 'postrm'; do + cat > ${BUILDDIR}/debian/$script << EOF +#!/bin/sh +if [ -e '$(pwd)/rootdir/tmp/read_stdin' ]; then + read line; + echo "STDIN: -\$line-" +fi +ls -l /proc/self/fd/ +EOF +done +buildpackage "$BUILDDIR" 'unstable' 'main' 'native' +rm -rf "$BUILDDIR" + +PKGNAME='fdleaks:all' +if dpkg --compare-versions "$(dpkg_version)" 'lt' '1.16.2'; then + PKGNAME='fdleaks' +fi + +setupaptarchive + +rm -f rootdir/var/log/dpkg.log rootdir/var/log/apt/term.log +testsuccess aptget install -y fdleaks -qq < /dev/null + +checkfdleak() { + msgtest 'Check if fds were not' "leaked: expect $1" + if [ "$(grep -e 'root root' -e "$(id -un) $(id -gn)" rootdir/tmp/testsuccess.output | wc -l)" = "$1" ]; then + msgpass + else + echo + cat rootdir/tmp/testsuccess.output + msgfail + fi +} +checkinstall() { + checkfdleak 8 + + cp rootdir/tmp/testsuccess.output terminal.output + tail -n +3 rootdir/var/log/apt/term.log | head -n -1 > terminal.log + testfileequal 'terminal.log' "$(cat terminal.output)" + + testequalor2 "startup archives unpack +install $PKGNAME <none> 1.0 +status half-installed $PKGNAME 1.0 +status unpacked $PKGNAME 1.0 +startup packages configure +configure $PKGNAME 1.0 <none> +status unpacked $PKGNAME 1.0 +status half-configured $PKGNAME 1.0 +status installed $PKGNAME 1.0" "startup archives unpack +install $PKGNAME <none> 1.0 +status half-installed $PKGNAME 1.0 +status unpacked $PKGNAME 1.0 +status unpacked $PKGNAME 1.0 +startup packages configure +configure $PKGNAME 1.0 <none> +status unpacked $PKGNAME 1.0 +status half-configured $PKGNAME 1.0 +status installed $PKGNAME 1.0" cut -f 3- -d' ' rootdir/var/log/dpkg.log +} +checkinstall + +rm -f rootdir/var/log/dpkg.log rootdir/var/log/apt/term.log +testsuccess aptget purge -y fdleaks -qq +checkpurge() { + checkfdleak 12 + + cp rootdir/tmp/testsuccess.output terminal.output + tail -n +3 rootdir/var/log/apt/term.log | head -n -1 > terminal.log + testfileequal 'terminal.log' "$(cat terminal.output)" + + if dpkg --compare-versions "$(dpkg_version)" 'ge' '1.18.11'; then + testequalor2 "startup packages remove +status installed $PKGNAME 1.0 +remove $PKGNAME 1.0 <none> +status half-configured $PKGNAME 1.0 +status half-installed $PKGNAME 1.0 +status config-files $PKGNAME 1.0 +startup packages configure +startup packages purge +purge $PKGNAME 1.0 <none> +status config-files $PKGNAME 1.0 +status not-installed $PKGNAME <none> +startup packages configure" "startup packages remove +status installed $PKGNAME 1.0 +remove $PKGNAME 1.0 <none> +status half-configured $PKGNAME 1.0 +status half-installed $PKGNAME 1.0 +status config-files $PKGNAME 1.0 +status config-files $PKGNAME 1.0 +startup packages configure +startup packages purge +purge $PKGNAME 1.0 <none> +status config-files $PKGNAME 1.0 +status config-files $PKGNAME 1.0 +status config-files $PKGNAME 1.0 +status config-files $PKGNAME 1.0 +status config-files $PKGNAME 1.0 +status not-installed $PKGNAME <none> +startup packages configure" cut -f 3- -d' ' rootdir/var/log/dpkg.log + else + testequalor2 "startup packages remove +status installed $PKGNAME 1.0 +remove $PKGNAME 1.0 <none> +status half-configured $PKGNAME 1.0 +status half-installed $PKGNAME 1.0 +status config-files $PKGNAME 1.0 +startup packages configure +startup packages purge +remove $PKGNAME 1.0 <none> +purge $PKGNAME 1.0 <none> +status config-files $PKGNAME 1.0 +status not-installed $PKGNAME <none> +startup packages configure" "startup packages remove +status installed $PKGNAME 1.0 +remove $PKGNAME 1.0 <none> +status half-configured $PKGNAME 1.0 +status half-installed $PKGNAME 1.0 +status config-files $PKGNAME 1.0 +status config-files $PKGNAME 1.0 +startup packages configure +startup packages purge +remove $PKGNAME 1.0 <none> +purge $PKGNAME 1.0 <none> +status config-files $PKGNAME 1.0 +status config-files $PKGNAME 1.0 +status config-files $PKGNAME 1.0 +status config-files $PKGNAME 1.0 +status config-files $PKGNAME 1.0 +status not-installed $PKGNAME <none> +startup packages configure" cut -f 3- -d' ' rootdir/var/log/dpkg.log + fi + testequalor2 "dpkg-query: no packages found matching ${PKGNAME}" "No packages found matching ${PKGNAME}." dpkg -l "$PKGNAME" +} +checkpurge + +msgtest 'setsid provided is new enough to support' '-w' +if dpkg-checkbuilddeps -d 'util-linux (>= 2.24.2-1)' /dev/null >/dev/null 2>&1; then + msgpass +else + msgskip "$(command dpkg -l util-linux)" + exit +fi + +rm -f rootdir/var/log/dpkg.log rootdir/var/log/apt/term.log +testsuccess runapt command setsid -w "${APTCMDLINEBINDIR}/apt-get" install -y fdleaks -qq < /dev/null +checkinstall + +rm -f rootdir/var/log/dpkg.log rootdir/var/log/apt/term.log +testsuccess runapt command setsid -w "${APTCMDLINEBINDIR}/apt-get" purge -y fdleaks -qq +checkpurge + +touch rootdir/tmp/read_stdin + +rm -f rootdir/var/log/dpkg.log rootdir/var/log/apt/term.log +for i in $(seq 1 10); do echo "$i"; done | testsuccess aptget install -y fdleaks -qq +checkinstall +testequal '2' grep -c '^STDIN: ' rootdir/var/log/apt/term.log + +rm -f rootdir/var/log/dpkg.log rootdir/var/log/apt/term.log +yes '' | testsuccess runapt command setsid -w "${APTCMDLINEBINDIR}/apt-get" purge -y fdleaks -qq +checkpurge +testequal '3' grep -c '^STDIN: ' rootdir/var/log/apt/term.log |