]> git.saurik.com Git - apt.git/blobdiff - test/integration/framework
zh_TW.po: remove several fuzzy tags after review
[apt.git] / test / integration / framework
index e2d545ec232b7831a753786a32322b3e5abf6da2..a68209326ab5f623f32f513ccafafe599f3f81f5 100644 (file)
@@ -95,7 +95,7 @@ msgfail() {
        if [ $# -gt 0 ] && [ -n "$1" ]; then printf "${CFAIL}FAIL: $*${CNORMAL}\n" >&2;
        else printf "${CFAIL}FAIL${CNORMAL}\n" >&2; fi
        if [ -n "$APT_DEBUG_TESTS" ]; then
-               APT_CONFIG="$(getaptconfig)" LD_LIBRARY_PATH="${LIBRARYPATH}:${LD_LIBRARY_PATH}" $SHELL
+               runapt $SHELL
        fi
        EXIT_CODE=$((EXIT_CODE+1));
 }
@@ -173,8 +173,9 @@ runapt() {
        sh|aptitude|*/*|command) ;;
        *) CMD="${BUILDDIRECTORY}/$CMD";;
        esac
-       MALLOC_PERTURB_=21 MALLOC_CHECK_=2 APT_CONFIG="$(getaptconfig)" LD_LIBRARY_PATH=${LIBRARYPATH} "$CMD" "$@"
+       MALLOC_PERTURB_=21 MALLOC_CHECK_=2 APT_CONFIG="$(getaptconfig)" LD_LIBRARY_PATH="${LIBRARYPATH}:${LD_LIBRARY_PATH}" "$CMD" "$@"
 }
+runpython3() { runapt command python3 "$@"; }
 aptconfig() { runapt apt-config "$@"; }
 aptcache() { runapt apt-cache "$@"; }
 aptcdrom() { runapt apt-cdrom "$@"; }
@@ -216,6 +217,12 @@ gdb() {
        fi
        runapt command gdb --quiet -ex run "$CMD" --args "$CMD" "$@"
 }
+lastmodification() {
+       date -u -d "@$(stat -c '%Y' "${TMPWORKINGDIRECTORY}/$1")" '+%a, %d %b %Y %H:%M:%S GMT'
+}
+releasefiledate() {
+       grep "^${2:-Date}:" "$1" | cut -d' ' -f 2- | sed -e 's#UTC#GMT#'
+}
 
 exitwithstatus() {
         # error if we about to overflow, but ...
@@ -389,8 +396,9 @@ EOF
        echo "Acquire::https::CaInfo \"${TMPWORKINGDIRECTORY}/rootdir/etc/webserver.pem\";" > rootdir/etc/apt/apt.conf.d/99https
        echo "Apt::Cmd::Disable-Script-Warning \"1\";" > rootdir/etc/apt/apt.conf.d/apt-binary
        echo 'Acquire::Connect::AddrConfig "false";' > rootdir/etc/apt/apt.conf.d/connect-addrconfig
+
        configcompression '.' 'gz' #'bz2' 'lzma' 'xz'
-       confighashes 'SHA1' # these are tests, not security best-practices
+       confighashes 'SHA256' # these are tests, not security best-practices
 
        # create some files in /tmp and look at user/group to get what this means
        TEST_DEFAULT_USER="$(id -un)"
@@ -407,6 +415,12 @@ EOF
        unset LANGUAGE APT_CONFIG
        unset GREP_OPTIONS DEB_BUILD_PROFILES
        unset http_proxy HTTP_PROXY https_proxy HTTPS_PROXY no_proxy
+
+       # If gpgv supports --weak-digest, pass it to make sure we can disable SHA1
+       if aptkey verify --weak-digest SHA1 --help 2>/dev/null >/dev/null; then
+               echo 'Acquire::gpgv::Options { "--weak-digest"; "sha1"; };' > rootdir/etc/apt/apt.conf.d/no-sha1
+       fi
+
        msgdone "info"
 }
 
@@ -517,16 +531,16 @@ int execvp(const char *file, char *const argv[]) {
        return func_execvp(newfile, argv);
 }
 EOF
-       testsuccess --nomsg gcc -Wall -fPIC -shared -o noopchroot.so noopchroot.c -ldl
+       testempty --nomsg gcc -Wall -Wextra -fPIC -shared -o noopchroot.so noopchroot.c -ldl
 }
 configcompression() {
+       local CMD='apthelper cat-file -C'
        while [ -n "$1" ]; do
                case "$1" in
                '.') printf ".\t.\tcat\n";;
-               'gz') printf "gzip\tgz\tgzip\n";;
-               'bz2') printf "bzip2\tbz2\tbzip2\n";;
-               'lzma') printf "lzma\tlzma\txz --format=lzma\n";;
-               *) printf "$1\t$1\t$1\n";;
+               'gz') printf "gzip\tgz\t$CMD $1\n";;
+               'bz2') printf "bzip2\tbz2\t$CMD $1\n";;
+               *) printf "$1\t$1\t$CMD $1\n";;
                esac
                shift
        done > "${TMPWORKINGDIRECTORY}/rootdir/etc/testcase-compressor.conf"
@@ -550,7 +564,7 @@ confighashes() {
 forcecompressor() {
        COMPRESSOR="$1"
        COMPRESS="$1"
-       COMPRESSOR_CMD="$1"
+       COMPRESSOR_CMD="apthelper cat-file -C $1"
        case $COMPRESSOR in
        gzip) COMPRESS='gz';;
        bzip2) COMPRESS='bz2';;
@@ -558,20 +572,11 @@ forcecompressor() {
        local CONFFILE="${TMPWORKINGDIRECTORY}/rootdir/etc/apt/apt.conf.d/00force-compressor"
        echo "Acquire::CompressionTypes::Order { \"${COMPRESS}\"; };
 Dir::Bin::uncompressed \"/does/not/exist\";" > "$CONFFILE"
-       for COMP in $(aptconfig dump APT::Compressor --format '%t %v%n' | sed -n 's#^Name \([^.].\+\)$#\1#p'); do
-               echo "Dir::Bin::${COMP} \"/does/not/exist\";"
-       done >> "$CONFFILE"
-       if [ -e "/bin/${COMPRESSOR}" ]; then
-               echo "Dir::Bin::${COMPRESSOR} \"/bin/${COMPRESSOR}\";" >> "$CONFFILE"
-       elif [ -e "/usr/bin/${COMPRESSOR}" ]; then
-               echo "Dir::Bin::${COMPRESSOR} \"/usr/bin/${COMPRESSOR}\";" >> "$CONFFILE"
-       elif [ "${COMPRESSOR}" = 'lzma' ]; then
-               echo 'Dir::Bin::xz "/usr/bin/xz";' >> "$CONFFILE"
-               COMPRESSOR_CMD='xz --format=lzma'
-       else
-               msgtest 'Test for availability of compressor' "${COMPRESSOR}"
-               msgfail "${COMPRESSOR} not available"
-       fi
+       for COMP in $(aptconfig dump 'APT::Compressor' --format '%f%n' | cut -d':' -f 5 | uniq); do
+               if [ -z "$COMP" -o "$COMP" = '.' -o "$COMP" = "$COMPRESSOR" ]; then continue; fi
+               echo "Dir::Bin::${COMP} \"/does/not/exist\";" >> "$CONFFILE"
+               echo "APT::Compressor::${COMP}::Name \"${COMP}-disabled\";" >> "$CONFFILE"
+       done
 }
 
 setupsimplenativepackage() {
@@ -596,12 +601,12 @@ setupsimplenativepackage() {
        mkdir -p ${BUILDDIR}/debian/source
        cd ${BUILDDIR}
        echo "* most suckless software product ever" > FEATURES
-       test -e debian/copyright || echo "Copyleft by Joe Sixpack $(date +%Y)" > debian/copyright
+       test -e debian/copyright || echo "Copyleft by Joe Sixpack $(date -u +%Y)" > debian/copyright
        test -e debian/changelog || echo "$NAME ($VERSION) $RELEASE; urgency=low
 
   * Initial release
 
- -- Joe Sixpack <joe@example.org>  $(date -R)" > debian/changelog
+ -- Joe Sixpack <joe@example.org>  $(date -u -R)" > debian/changelog
        test -e debian/control || echo "Source: $NAME
 Section: $SECTION
 Priority: optional
@@ -659,12 +664,12 @@ buildsimplenativepackage() {
        echo "#!/bin/sh
 echo '$NAME says \"Hello!\"'" > "${BUILDDIR}/${NAME}"
 
-       echo "Copyleft by Joe Sixpack $(date +%Y)" > "${BUILDDIR}/debian/copyright"
+       echo "Copyleft by Joe Sixpack $(date -u +%Y)" > "${BUILDDIR}/debian/copyright"
        echo "$NAME ($VERSION) $RELEASE; urgency=low
 
   * Initial release
 
- -- Joe Sixpack <joe@example.org>  $(date -R)" > "${BUILDDIR}/debian/changelog"
+ -- Joe Sixpack <joe@example.org>  $(date -u -R)" > "${BUILDDIR}/debian/changelog"
        {
                echo "Source: $NAME
 Priority: $PRIORITY
@@ -863,31 +868,33 @@ Description-en: $DESCRIPTION
 }
 
 insertsource() {
-       local RELEASE="$1"
+       local RELEASES="$1"
        local NAME="$2"
        local ARCH="$3"
        local VERSION="$4"
        local DEPENDENCIES="$5"
-        local BINARY="${6:-$NAME}"
+       local BINARY="${6:-$NAME}"
        local ARCHS=""
-       local SPATH="aptarchive/dists/${RELEASE}/main/source"
-       mkdir -p $SPATH
-       local FILE="${SPATH}/Sources"
-       local DSCFILE="${NAME}_${VERSION}.dsc"
-       local TARFILE="${NAME}_${VERSION}.tar.gz"
-       echo "Package: $NAME
+       for RELEASE in $(printf '%s' "$RELEASES" | tr ',' '\n'); do
+               local SPATH="aptarchive/dists/${RELEASE}/main/source"
+               mkdir -p $SPATH
+               local FILE="${SPATH}/Sources"
+               local DSCFILE="${NAME}_${VERSION}.dsc"
+               local TARFILE="${NAME}_${VERSION}.tar.gz"
+               echo "Package: $NAME
 Binary: $BINARY
 Version: $VERSION
 Maintainer: Joe Sixpack <joe@example.org>
 Architecture: $ARCH" >> $FILE
-       test -z "$DEPENDENCIES" || echo "$DEPENDENCIES" >> "$FILE"
-       echo "Files:
+               test -z "$DEPENDENCIES" || echo "$DEPENDENCIES" >> "$FILE"
+               echo "Files:
  $(echo -n "$DSCFILE" | md5sum | cut -d' ' -f 1) $(echo -n "$DSCFILE" | wc -c) "$DSCFILE"
  $(echo -n "$TARFILE" | md5sum | cut -d' ' -f 1) $(echo -n "$TARFILE" | wc -c) "$TARFILE"
 Checksums-Sha256:
  $(echo -n "$DSCFILE" | sha256sum | cut -d' ' -f 1) $(echo -n "$DSCFILE" | wc -c) "$DSCFILE"
  $(echo -n "$TARFILE" | sha256sum | cut -d' ' -f 1) $(echo -n "$TARFILE" | wc -c) "$TARFILE"
 " >> "$FILE"
+       done
 }
 
 insertinstalledpackage() {
@@ -1013,13 +1020,13 @@ NotAutomatic: yes' "$dir/Release"
        fi
        if [ -n "$DATE" -a "$DATE" != "now" ]; then
                for release in $(find ./aptarchive -name 'Release'); do
-                       sed -i "s/^Date: .*$/Date: $(date -d "$DATE" '+%a, %d %b %Y %H:%M:%S %Z')/" "$release"
+                       sed -i "s/^Date: .*$/Date: $(date -u -d "$DATE" '+%a, %d %b %Y %H:%M:%S %Z')/" "$release"
                        touch -d "$DATE" "$release"
                done
        fi
        if [ -n "$VALIDUNTIL" ]; then
                sed -i "/^Date: / a\
-Valid-Until: $(date -d "$VALIDUNTIL" '+%a, %d %b %Y %H:%M:%S %Z')" $(find ./aptarchive -name 'Release')
+Valid-Until: $(date -u -d "$VALIDUNTIL" '+%a, %d %b %Y %H:%M:%S %Z')" $(find ./aptarchive -name 'Release')
        fi
        msgdone "info"
 }
@@ -1078,7 +1085,7 @@ signreleasefiles() {
        local SIGNER="${1:-Joe Sixpack}"
        local REPODIR="${2:-aptarchive}"
        local KEY="keys/$(echo "$SIGNER" | tr 'A-Z' 'a-z' | sed 's# ##g')"
-       local GPG="aptkey --quiet --keyring ${KEY}.pub --secret-keyring ${KEY}.sec --readonly adv --batch --yes"
+       local GPG="aptkey --quiet --keyring ${KEY}.pub --secret-keyring ${KEY}.sec --readonly adv --batch --yes --digest-algo ${APT_TESTS_DIGEST_ALGO:-SHA512}"
        msgninfo "\tSign archive with $SIGNER key $KEY… "
        local REXKEY='keys/rexexpired'
        local SECEXPIREBAK="${REXKEY}.sec.bak"
@@ -1118,7 +1125,7 @@ signreleasefiles() {
 }
 
 redatereleasefiles() {
-       local DATE="$(date -d "$1" '+%a, %d %b %Y %H:%M:%S %Z')"
+       local DATE="$(date -u -d "$1" '+%a, %d %b %Y %H:%M:%S %Z')"
        for release in $(find aptarchive/ -name 'Release'); do
                sed -i "s/^Date: .*$/Date: ${DATE}/" "$release"
                touch -d "$DATE" "$release"
@@ -1160,8 +1167,8 @@ rewritesourceslist() {
        local APTARCHIVE2="copy://$(readlink -f "${TMPWORKINGDIRECTORY}/aptarchive" | sed 's# #%20#g')"
        for LIST in $(find rootdir/etc/apt/sources.list.d/ -name 'apt-test-*.list'); do
                sed -i $LIST -e "s#$APTARCHIVE#${1}#" -e "s#$APTARCHIVE2#${1}#" \
-                       -e "s#http://localhost:${APTHTTPPORT}/#${1}#" \
-                       -e "s#https://localhost:${APTHTTPSPORT}/#${1}#"
+                       -e "s#http://[^@]*@\?localhost:${APTHTTPPORT}/\?#${1}#" \
+                       -e "s#https://[^@]*@\?localhost:${APTHTTPSPORT}/\?#${1}#"
        done
 }
 
@@ -1235,7 +1242,7 @@ connect = $APTHTTPPORT
                msgdie 'Could not fork stunnel4 successfully'
        fi
        addtrap 'prefix' "kill ${PID};"
-       APTHTTPSPORT="$(lsof -i | 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}/"
 }
@@ -1325,9 +1332,13 @@ testfileequal() {
 
 testempty() {
        msggroup 'testempty'
-       msgtest "Test for no output of" "$*"
+       if [ "$1" = '--nomsg' ]; then
+               shift
+       else
+               msgtest "Test for no output of" "$*"
+       fi
        local COMPAREFILE="${TMPWORKINGDIRECTORY}/rootdir/tmp/testempty.comparefile"
-       if ("$@" >"$COMPAREFILE" 2>&1 || true) && test ! -s "$COMPAREFILE"; then
+       if "$@" >"$COMPAREFILE" 2>&1 && test ! -s "$COMPAREFILE"; then
                msgpass
        else
                msgfailoutput '' "$COMPAREFILE" "$@"
@@ -1500,6 +1511,14 @@ testmarkedmanual() {
        msggroup
 }
 
+catfile() {
+       if [ "${1##*.}" = 'deb' ]; then
+               stat >&2 "$1" || true
+               file >&2 "$1" || true
+       else
+               cat >&2 "$1" || true
+       fi
+}
 msgfailoutput() {
        msgreportheader 'msgfailoutput'
        local MSG="$1"
@@ -1509,7 +1528,7 @@ msgfailoutput() {
                echo >&2
                while [ -n "$2" ]; do shift; done
                echo "#### Complete file: $1 ####"
-               cat >&2 "$1" || true
+               catfile "$1"
                echo '#### grep output ####'
        elif [ "$1" = 'test' ]; then
                echo >&2
@@ -1524,7 +1543,7 @@ msgfailoutput() {
                                        ls >&2 "$2" || true
                                elif test -e "$2"; then
                                        echo "#### Complete file: $2 ####"
-                                       cat >&2 "$2" || true
+                                       catfile "$2"
                                fi
                        fi
                }
@@ -1534,8 +1553,16 @@ msgfailoutput() {
                        msgfailoutputstatfile "$2" "$3"
                done
                echo '#### test output ####'
+       elif [ "$1" = 'cmp' ]; then
+               echo >&2
+               while [ -n "$2" ]; do
+                       echo "#### Complete file: $2 ####"
+                       catfile "$2"
+                       shift
+               done
+               echo '#### cmp output ####'
        fi
-       cat >&2 "$OUTPUT"
+       catfile "$OUTPUT"
        msgfail "$MSG"
 }
 
@@ -1777,8 +1804,18 @@ createlistofkeys() {
        local OUTPUT="$1"
        shift
        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
-               if grep -q ' rsa2048/' "$OUTPUT"; then
+               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]';;
@@ -1825,8 +1862,9 @@ listcurrentlistsdirectory() {
        } | sort
 }
 forallsupportedcompressors() {
+       rm -f "${TMPWORKINGDIRECTORY}/rootdir/etc/apt/apt.conf.d/00force-compressor"
        for COMP in $(aptconfig dump 'APT::Compressor' --format '%f%n' | cut -d':' -f 5 | uniq); do
-               if [ -z "$COMP" -o "$COMP" = '.' -o "$COMP" = 'lz4' ]; then continue; fi
+               if [ -z "$COMP" -o "$COMP" = '.' ]; then continue; fi
                "$@" "$COMP"
        done
 }
@@ -1856,7 +1894,7 @@ aptautotest() {
        local TESTCALL="$1"
        local CMD="$2"
        local FIRSTOPT="$3"
-       local AUTOTEST="aptautotest_$(echo "${CMD##*/}_${FIRSTOPT}" | tr -d '-')"
+       local AUTOTEST="aptautotest_$(echo "${CMD##*/}_${FIRSTOPT}" | tr -d -c 'A-za-z0-9')"
        if command -v $AUTOTEST >/dev/null; then
                shift 3
                # save and restore the *.output files from other tests