]> git.saurik.com Git - apt.git/blobdiff - test/integration/framework
test: Explicitly pass --admindir=var/lib/dpkg to dpkg
[apt.git] / test / integration / framework
index 8d124858be3daab8a29b5c347eebf4730888063f..827226b7de80766746a3af04c2c684137f4c58ca 100644 (file)
@@ -31,7 +31,6 @@ if [ "${MSGCOLOR:-YES}" = 'YES' ]; then
        fi
 fi
 
-
 if [ "$MSGCOLOR" != 'NO' ]; then
        CERROR="\033[1;31m" # red
        CWARNING="\033[1;33m" # yellow
@@ -276,8 +275,13 @@ find_project_binary_dir() {
        fi
 }
 setupenvironment() {
+       # Next check needs a gnu stat, let's figure that out early.
+       stat=stat
+       if command -v gnustat >/dev/null 2>&1; then
+               stat=gnustat
+       fi
        # privilege dropping and testing doesn't work if /tmp isn't world-writeable (as e.g. with libpam-tmpdir)
-       if [ -n "$TMPDIR" ] && [ "$(id -u)" = '0' ] && [ "$(stat --format '%a' "$TMPDIR")" != '1777' ]; then
+       if [ -n "$TMPDIR" ] && [ "$(id -u)" = '0' ] && [ "$($stat --format '%a' "$TMPDIR")" != '1777' ]; then
                unset TMPDIR
        fi
        TMPWORKINGDIRECTORY="$(mktemp -d)"
@@ -290,6 +294,18 @@ setupenvironment() {
        fi
        msgninfo "Preparing environment for ${0##*/} in ${TMPWORKINGDIRECTORY}…"
 
+       # Setup coreutils on BSD systems
+       mkdir "${TMPWORKINGDIRECTORY}/bin"
+       for prefix in gnu g; do
+                       for command in stat touch sed cp tr sha1sum sha256sum md5sum sha512sum grep date wc chmod head readlink tar expr base64; do
+                                       if command -v $prefix$command 2>/dev/null >/dev/null; then
+                                                       [ -e "${TMPWORKINGDIRECTORY}/bin/$command" ] || ln -sf $(command -v $prefix$command)  "${TMPWORKINGDIRECTORY}/bin/$command"
+                                       fi
+                       done
+       done
+       export PATH="${TMPWORKINGDIRECTORY}/bin/:$PATH"
+
+
        mkdir -m 700 "${TMPWORKINGDIRECTORY}/downloaded"
        if [ "$(id -u)" = '0' ]; then
                # relax permissions so that running as root with user switching works
@@ -352,6 +368,11 @@ setupenvironment() {
        ln -s "${TMPWORKINGDIRECTORY}/keys/joesixpack.pub" rootdir/etc/apt/trusted.gpg.d/joesixpack.gpg
 
        echo "Dir \"${TMPWORKINGDIRECTORY}/rootdir\";" >> aptconfig.conf
+       echo "Dir::Etc \"etc\";" >> aptconfig.conf
+       echo "Dir::State \"var/lib/apt\";" >> aptconfig.conf
+       echo "Dir::Cache \"var/cache/apt\";" >> aptconfig.conf
+       echo "Dir::Etc \"etc/apt\";" >> aptconfig.conf
+       echo "Dir::Log \"var/log/apt\";" >> aptconfig.conf
        echo "APT::Get::Show-User-Simulation-Note \"false\";" >> aptconfig.conf
        echo "Dir::Bin::Methods \"${TMPWORKINGDIRECTORY}/rootdir/usr/lib/apt/methods\";" >> aptconfig.conf
        # either store apt-key were we can access it, even if we run it as a different user
@@ -386,11 +407,13 @@ EOF
        cp "${TMPWORKINGDIRECTORY}/rootdir/usr/bin/dpkg" "${TMPWORKINGDIRECTORY}/rootdir/usr/bin/gdb-dpkg"
        cat >> "${TMPWORKINGDIRECTORY}/rootdir/usr/bin/dpkg" <<EOF
 exec fakeroot '${DPKG:-dpkg}' --root='${TMPWORKINGDIRECTORY}/rootdir' \\
+       --admindir="${TMPWORKINGDIRECTORY}/rootdir/var/lib/dpkg" \\
        --log='${TMPWORKINGDIRECTORY}/rootdir/var/log/dpkg.log' \\
        --force-not-root --force-bad-path "\$@"
 EOF
        cat >> "${TMPWORKINGDIRECTORY}/rootdir/usr/bin/gdb-dpkg" <<EOF
 exec fakeroot gdb --quiet -ex run '${DPKG:-dpkg}' --args '${DPKG:-dpkg}' --root='${TMPWORKINGDIRECTORY}/rootdir' \\
+       --admindir="${TMPWORKINGDIRECTORY}/rootdir/var/lib/dpkg" \\
        --log='${TMPWORKINGDIRECTORY}/rootdir/var/log/dpkg.log' \\
        --force-not-root --force-bad-path "\$@"
 EOF
@@ -437,7 +460,7 @@ EOF
        # cleanup the environment a bit
        # prefer our apt binaries over the system apt binaries
        export PATH="${BUILDDIRECTORY}:${PATH}:/usr/local/sbin:/usr/sbin:/sbin"
-       export LC_ALL=C.UTF-8
+       export LC_ALL=C
        unset LANGUAGE APT_CONFIG
        unset GREP_OPTIONS DEB_BUILD_PROFILES
        unset http_proxy HTTP_PROXY https_proxy HTTPS_PROXY no_proxy
@@ -568,7 +591,11 @@ int execvp(const char *file, char *const argv[]) {
        return func_execvp(newfile, argv);
 }
 EOF
-       testempty --nomsg gcc -Wall -Wextra -fPIC -shared -o noopchroot.so noopchroot.c -ldl
+       if cc -ldl 2>&1 | grep -q dl; then
+               testempty --nomsg cc -Wall -Wextra -fPIC -shared -o noopchroot.so noopchroot.c
+       else
+               testempty --nomsg cc -Wall -Wextra -fPIC -shared -o noopchroot.so noopchroot.c -ldl
+       fi
 }
 configcompression() {
        if [ "$1" = 'ALL' ]; then
@@ -680,13 +707,25 @@ Package: $NAME"
        echo '3.0 (native)' > "${BUILDDIR}/debian/source/format"
 }
 
+make_tiny_rules() {
+       local OUT="$1"
+       if command -v gmake >/dev/null 2>&1; then
+               [ -e ${TMPWORKINGDIRECTORY}/bin/make ] || ln -s $(command -v gmake) ${TMPWORKINGDIRECTORY}/bin/make
+               echo "#!${TMPWORKINGDIRECTORY}/bin/make -f" > "$OUT"
+       else
+               echo '#!/usr/bin/make -f' > "$OUT"
+       fi
+       echo '%:' >> "$OUT"
+       echo '  dh $@' >> "$OUT"
+}
+
 setupsimplenativepackage() {
        _setupsimplenativepackage "$@"
        local NAME="$1"
        local VERSION="$3"
        local BUILDDIR="${TMPWORKINGDIRECTORY}/incoming/${NAME}-${VERSION}"
        test -e "${BUILDDIR}/debian/compat" || echo '7' > "${BUILDDIR}/debian/compat"
-       test -e  "${BUILDDIR}/debian/rules" || cp /usr/share/doc/debhelper/examples/rules.tiny "${BUILDDIR}/debian/rules"
+       test -e  "${BUILDDIR}/debian/rules" || make_tiny_rules "${BUILDDIR}/debian/rules"
 }
 
 buildsimplenativepackage() {
@@ -1275,7 +1314,12 @@ changetowebserver() {
 }
 
 changetohttpswebserver() {
-       if ! command -v stunnel4 >/dev/null 2>&1; then
+       local stunnel4
+       if command -v stunnel4 >/dev/null 2>&1; then
+               stunnel4=stunnel4
+       elif command -v stunnel >/dev/null 2>&1; then
+               stunnel4=stunnel
+       else
                msgdie 'You need to install stunnel4 for https testcases'
        fi
        if [ ! -e "${TMPWORKINGDIRECTORY}/aptarchive/aptwebserver.pid" ]; then
@@ -1289,14 +1333,14 @@ output = /dev/null
 accept = 0
 connect = $APTHTTPPORT
 " > "${TMPWORKINGDIRECTORY}/stunnel.conf"
-       stunnel4 "${TMPWORKINGDIRECTORY}/stunnel.conf"
+       $stunnel4 "${TMPWORKINGDIRECTORY}/stunnel.conf"
         waitforpidfile "${TMPWORKINGDIRECTORY}/aptarchive/stunnel.pid"
        local PID="$(cat "${TMPWORKINGDIRECTORY}/aptarchive/stunnel.pid")"
         if [ -z "$PID" ]; then
-               msgdie 'Could not fork stunnel4 successfully'
+               msgdie 'Could not fork $stunnel4 successfully'
        fi
        addtrap 'prefix' "kill ${PID};"
-       APTHTTPSPORT="$(lsof -i -n | awk "/^stunnel4 / && \$2 == \"${PID}\" {print \$9; exit; }" | cut -d':' -f 2)"
+       APTHTTPSPORT="$(lsof -i -n | awk "/^$stunnel4 / && \$2 == \"${PID}\" {print \$9; exit; }" | cut -d':' -f 2)"
        webserverconfig 'aptwebserver::port::https' "$APTHTTPSPORT" "https://localhost:${APTHTTPSPORT}"
        rewritesourceslist "https://localhost:${APTHTTPSPORT}/"
 }
@@ -1856,49 +1900,24 @@ testwebserverlaststatuscode() {
        msggroup
 }
 
-createlistofkeys() {
-       local OUTPUT="$1"
-       shift
+mapkeynametokeyid() {
        while [ -n "$1" ]; do
-               # gpg 2.1.something starts printing [SC] at some point
-               if grep -q ' rsa2048/' "$OUTPUT" && grep -qF '[SC]' "$OUTPUT"; then
-                       case "$1" in
-                               *Joe*|*Sixpack*) echo 'pub   rsa2048/DBAC8DAE 2010-08-18 [SC]';;
-                               *Rex*|*Expired*) echo 'pub   rsa2048/27CE74F9 2013-07-12 [SC] [expired: 2013-07-13]';;
-                               *Marvin*|*Paranoid*) echo 'pub   rsa2048/528144E2 2011-01-16 [SC]';;
-                               oldarchive) echo 'pub   rsa1024/F68C85A3 2013-12-19 [SC]';;
-                               newarchive) echo 'pub   rsa2048/DBAC8DAE 2010-08-18 [SC]';;
-                               *) echo 'UNKNOWN KEY';;
-                       esac
-               # gpg 2.1 has a slightly different output format
-               elif grep -q ' rsa2048/' "$OUTPUT"; then
-                       case "$1" in
-                               *Joe*|*Sixpack*) echo 'pub   rsa2048/DBAC8DAE 2010-08-18';;
-                               *Rex*|*Expired*) echo 'pub   rsa2048/27CE74F9 2013-07-12 [expired: 2013-07-13]';;
-                               *Marvin*|*Paranoid*) echo 'pub   rsa2048/528144E2 2011-01-16';;
-                               oldarchive) echo 'pub   rsa1024/F68C85A3 2013-12-19';;
-                               newarchive) echo 'pub   rsa2048/DBAC8DAE 2010-08-18';;
-                               *) echo 'UNKNOWN KEY';;
-                       esac
-               else
-                       case "$1" in
-                               *Joe*|*Sixpack*) echo 'pub   2048R/DBAC8DAE 2010-08-18';;
-                               *Rex*|*Expired*) echo 'pub   2048R/27CE74F9 2013-07-12 [expired: 2013-07-13]';;
-                               *Marvin*|*Paranoid*) echo 'pub   2048R/528144E2 2011-01-16';;
-                               oldarchive) echo 'pub   1024R/F68C85A3 2013-12-19';;
-                               newarchive) echo 'pub   2048R/DBAC8DAE 2010-08-18';;
-                               *) echo 'UNKNOWN KEY';;
-                       esac
-               fi
+               case "$1" in
+                       *Joe*|*Sixpack*|newarchive) echo '5A90D141DBAC8DAE';;
+                       *Rex*|*Expired*) echo '4BC0A39C27CE74F9';;
+                       *Marvin*|*Paranoid*) echo 'E8525D47528144E2';;
+                       oldarchive) echo 'FDD2DB85F68C85A3';;
+                       *) echo 'UNKNOWN KEY';;
+               esac
                shift
        done
 }
 testaptkeys() {
        local OUTPUT="${TMPWORKINGDIRECTORY}/rootdir/tmp/aptkeylist.output"
-       if ! aptkey list | grep '^pub' > "$OUTPUT"; then
+       if ! aptkey list --with-colon | grep '^pub' | cut -d':' -f 5 > "$OUTPUT"; then
                echo -n > "$OUTPUT"
        fi
-       testfileequal "$OUTPUT" "$(createlistofkeys "$OUTPUT" "$@")"
+       testfileequal "$OUTPUT" "$(mapkeynametokeyid "$@")"
 }
 
 pause() {