]> git.saurik.com Git - apt.git/blobdiff - test/integration/framework
ignore lost+found in private directory cleanup
[apt.git] / test / integration / framework
index 6e3977eee439eb287ced3e5e51380044ad7d6a88..de8a65d7a74b930b7a4ac34cacd1d45f9fe7610c 100644 (file)
@@ -317,14 +317,14 @@ setupenvironment() {
        echo "Dir::state::status \"${TMPWORKINGDIRECTORY}/rootdir/var/lib/dpkg/status\";" >> aptconfig.conf
        echo "APT::Get::Show-User-Simulation-Note \"false\";" >> aptconfig.conf
        echo "Dir::Bin::Methods \"${TMPWORKINGDIRECTORY}/rootdir/usr/lib/apt/methods\";" >> aptconfig.conf
-       # store apt-key were we can access it, even if we run it as a different user
-       # destroys coverage reporting though, so just do it for root for now
+       # either store apt-key were we can access it, even if we run it as a different user
+       #cp "${BUILDDIRECTORY}/apt-key" "${TMPWORKINGDIRECTORY}/rootdir/usr/bin/"
+       #chmod o+rx "${TMPWORKINGDIRECTORY}/rootdir/usr/bin/apt-key"
+       #echo "Dir::Bin::apt-key \"${TMPWORKINGDIRECTORY}/rootdir/usr/bin/apt-key\";" >> aptconfig.conf
+       # destroys coverage reporting though, so we disable changing user for the calling gpgv
+       echo "Dir::Bin::apt-key \"${BUILDDIRECTORY}/apt-key\";" >> aptconfig.conf
        if [ "$(id -u)" = '0' ]; then
-               cp "${BUILDDIRECTORY}/apt-key" "${TMPWORKINGDIRECTORY}/rootdir/usr/bin/"
-               chmod o+rx "${TMPWORKINGDIRECTORY}/rootdir/usr/bin/apt-key"
-               echo "Dir::Bin::apt-key \"${TMPWORKINGDIRECTORY}/rootdir/usr/bin/apt-key\";" >> aptconfig.conf
-       else
-               echo "Dir::Bin::apt-key \"${BUILDDIRECTORY}/apt-key\";" >> aptconfig.conf
+               echo 'Binary::gpgv::Debug::NoDropPrivs "true";' >>aptconfig.conf
        fi
 
        cat > "${TMPWORKINGDIRECTORY}/rootdir/usr/bin/dpkg" <<EOF
@@ -361,6 +361,7 @@ EOF
                if ! command dpkg --assert-multi-arch >/dev/null 2>&1; then
                        echo "DPKG::options:: \"--force-architecture\";" # Added to test multiarch before dpkg is ready for it…
                fi
+               echo 'quiet "0";'
                echo 'quiet::NoUpdate "true";'
                echo 'quiet::NoStatistic "true";'
                # too distracting for users, but helpful to detect changes
@@ -377,6 +378,7 @@ EOF
        fi
        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
 
@@ -388,12 +390,8 @@ EOF
                TEST_DEFAULT_GROUP="$USER"
        fi
 
-        # Acquire::AllowInsecureRepositories=false is not yet the default
-        # but we want it to be the default soon
-        configallowinsecurerepositories "false";
-
        # cleanup the environment a bit
-        # prefer our apt binaries over the system apt binaries
+       # 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
        unset LANGUAGE APT_CONFIG
@@ -506,12 +504,6 @@ int execvp(const char *file, char *const argv[]) {
 EOF
        testsuccess --nomsg gcc -fPIC -shared -o noopchroot.so noopchroot.c -ldl
 }
-
-configallowinsecurerepositories() {
-    echo "Acquire::AllowInsecureRepositories \"$1\";" >  rootdir/etc/apt/apt.conf.d/allow-insecure-repositories.conf
-
-}
-
 configcompression() {
        while [ -n "$1" ]; do
                case "$1" in
@@ -784,7 +776,7 @@ EOF
        for DIST in $(find ./pool/ -maxdepth 1 -name '*.pkglist' -type f | cut -d'/' -f 3 | cut -d'.' -f 1 | sort | uniq); do
                cat <<EOF
 tree "dists/$DIST" {
-       Architectures "$ARCHS source";
+       Architectures "$ARCHS all source";
        FileList "${DIST}.\$(SECTION).pkglist";
        SourceFileList "${DIST}.\$(SECTION).srclist";
        Sections "$(find ./pool/ -maxdepth 1 -name "${DIST}.*.pkglist" -type f | cut -d'/' -f 3 | cut -d'.' -f 2 | sort | uniq | tr '\n' ' ')";
@@ -826,7 +818,7 @@ insertpackage() {
                        continue
                fi
                for arch in $(getarchitecturesfromcommalist "$ARCH"); do
-                       if [ "$arch" = 'all' -o "$arch" = 'none' ]; then
+                       if [ "$arch" = 'none' ]; then
                                ARCHS="$(getarchitectures)"
                        else
                                ARCHS="$arch"
@@ -972,6 +964,7 @@ getcodenamefromsuite() {
 getreleaseversionfromsuite() { true; }
 getlabelfromsuite() { true; }
 getoriginfromsuite() { true; }
+getarchitecturesfromreleasefile() { echo "all $(getarchitectures)"; }
 
 aptftparchiverelease() {
        aptftparchive -qq release "$@" | sed -e '/0 Release$/ d' # remove the self reference
@@ -979,29 +972,24 @@ aptftparchiverelease() {
 generatereleasefiles() {
        # $1 is the Date header and $2 is the ValidUntil header to be set
        # both should be given in notation date/touch can understand
-       msgninfo "\tGenerate Release files… "
+       local DATE="$1"
+       local VALIDUNTIL="$2"
        if [ -e aptarchive/dists ]; then
+               msgninfo "\tGenerate Release files for dists… "
                for dir in $(find ./aptarchive/dists -mindepth 1 -maxdepth 1 -type d); do
+                       local ARCHITECTURES="$(getarchitecturesfromreleasefile "$dir")"
                        local SUITE="$(echo "$dir" | cut -d'/' -f 4)"
                        local CODENAME="$(getcodenamefromsuite $SUITE)"
                        local VERSION="$(getreleaseversionfromsuite $SUITE)"
                        local LABEL="$(getlabelfromsuite $SUITE)"
                        local ORIGIN="$(getoriginfromsuite $SUITE)"
-                       if [ -n "$VERSION" ]; then
-                               VERSION="-o APT::FTPArchive::Release::Version=${VERSION}"
-                       fi
-                       if [ -n "$LABEL" ]; then
-                               LABEL="-o APT::FTPArchive::Release::Label=${LABEL}"
-                       fi
-                       if [ -n "$ORIGIN" ]; then
-                               ORIGIN="-o APT::FTPArchive::Release::Origin=${ORIGIN}"
-                       fi
                        aptftparchiverelease "$dir" \
                                -o APT::FTPArchive::Release::Suite="${SUITE}" \
                                -o APT::FTPArchive::Release::Codename="${CODENAME}" \
-                               ${LABEL} \
-                               ${ORIGIN} \
-                               ${VERSION} \
+                               -o APT::FTPArchive::Release::Architectures="${ARCHITECTURES}" \
+                               -o APT::FTPArchive::Release::Label="${LABEL}" \
+                               -o APT::FTPArchive::Release::Origin="${ORIGIN}" \
+                               -o APT::FTPArchive::Release::Version="${VERSION}" \
                                > "$dir/Release"
                        if [ "$SUITE" = "experimental" -o "$SUITE" = "experimental2" ]; then
                                sed -i '/^Date: / a\
@@ -1009,17 +997,18 @@ NotAutomatic: yes' "$dir/Release"
                        fi
                done
        else
+               msgninfo "\tGenerate Release files for flat… "
                aptftparchiverelease ./aptarchive > aptarchive/Release
        fi
-       if [ -n "$1" -a "$1" != "now" ]; then
+       if [ -n "$DATE" -a "$DATE" != "now" ]; then
                for release in $(find ./aptarchive -name 'Release'); do
-                       sed -i "s/^Date: .*$/Date: $(date -d "$1" '+%a, %d %b %Y %H:%M:%S %Z')/" "$release"
-                       touch -d "$1" "$release"
+                       sed -i "s/^Date: .*$/Date: $(date -d "$DATE" '+%a, %d %b %Y %H:%M:%S %Z')/" "$release"
+                       touch -d "$DATE" "$release"
                done
        fi
-       if [ -n "$2" ]; then
+       if [ -n "$VALIDUNTIL" ]; then
                sed -i "/^Date: / a\
-Valid-Until: $(date -d "$2" '+%a, %d %b %Y %H:%M:%S %Z')" $(find ./aptarchive -name 'Release')
+Valid-Until: $(date -d "$VALIDUNTIL" '+%a, %d %b %Y %H:%M:%S %Z')" $(find ./aptarchive -name 'Release')
        fi
        msgdone "info"
 }
@@ -1157,8 +1146,11 @@ webserverconfig() {
 
 rewritesourceslist() {
        local APTARCHIVE="file://$(readlink -f "${TMPWORKINGDIRECTORY}/aptarchive" | sed 's# #%20#g')"
+       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#http://localhost:${APTHTTPPORT}/#${1}#" -e "s#https://localhost:${APTHTTPSPORT}/#${1}#"
+               sed -i $LIST -e "s#$APTARCHIVE#${1}#" -e "s#$APTARCHIVE2#${1}#" \
+                       -e "s#http://localhost:${APTHTTPPORT}/#${1}#" \
+                       -e "s#https://localhost:${APTHTTPSPORT}/#${1}#"
        done
 }
 
@@ -1409,7 +1401,7 @@ N: No packages found"
        local ARCH="$(getarchitecture 'native')"
        echo "$VIRTUAL" | sed -e "s/:$ARCH//" -e 's/:all//' >"$COMPAREFILE"
        local OUTPUT="${TMPWORKINGDIRECTORY}/rootdir/tmp/testshowvirtual.output"
-       testoutputequal "$COMPAREFILE" aptcache show -q=0 "$PACKAGE"
+       testoutputequal "$COMPAREFILE" aptcache show "$PACKAGE"
        msggroup
 }
 
@@ -1520,19 +1512,22 @@ msgfailoutput() {
        msgfail "$MSG"
 }
 
-testsuccess() {
-       msggroup 'testsuccess'
+testsuccesswithglobalerror() {
+       local TYPE="$1"
+       local ERRORS="$2"
+       shift 2
+       msggroup "$TYPE"
        if [ "$1" = '--nomsg' ]; then
                shift
        else
                msgtest 'Test for successful execution of' "$*"
        fi
-       local OUTPUT="${TMPWORKINGDIRECTORY}/rootdir/tmp/testsuccess.output"
+       local OUTPUT="${TMPWORKINGDIRECTORY}/rootdir/tmp/${TYPE}.output"
        if "$@" >"${OUTPUT}" 2>&1; then
                if expr match "$1" '^apt.*' >/dev/null; then
                        if grep -q -E ' runtime error: ' "$OUTPUT"; then
                                msgfailoutput 'compiler detected undefined behavior' "$OUTPUT" "$@"
-                       elif grep -E '^[WE]: ' "$OUTPUT" > "${TMPWORKINGDIRECTORY}/rootdir/tmp/checkforwarnings.output" 2>&1; then
+                       elif grep -E "^[${ERRORS}]: " "$OUTPUT" > "${TMPWORKINGDIRECTORY}/rootdir/tmp/checkforwarnings.output" 2>&1; then
                                if [ "$IGNORE_PTY_NOT_MOUNTED" = '1' ]; then
                                        if echo 'E: Can not write log (Is /dev/pts mounted?) - posix_openpt (2: No such file or directory)' \
                                                | cmp - "${TMPWORKINGDIRECTORY}/rootdir/tmp/checkforwarnings.output" >/dev/null 2>&1; then
@@ -1543,6 +1538,12 @@ testsuccess() {
                                else
                                        msgfailoutput 'successful run, but output contains warnings/errors' "$OUTPUT" "$@"
                                fi
+                       elif [ "$TYPE" = 'testsuccesswithnotice' ]; then
+                               if grep -q -E "^N: " "$OUTPUT"; then
+                                       msgpass
+                               else
+                                       msgfailoutput 'successful run, but output had no notices' "$OUTPUT" "$@"
+                               fi
                        else
                                msgpass
                        fi
@@ -1553,9 +1554,15 @@ testsuccess() {
                local EXITCODE=$?
                msgfailoutput "exitcode $EXITCODE" "$OUTPUT" "$@"
        fi
-       aptautotest 'testsuccess' "$@"
+       aptautotest "$TYPE" "$@"
        msggroup
 }
+testsuccesswithnotice() {
+       testsuccesswithglobalerror 'testsuccesswithnotice' 'WE' "$@"
+}
+testsuccess() {
+       testsuccesswithglobalerror 'testsuccess' 'NWE' "$@"
+}
 testwarning() {
        msggroup 'testwarning'
        if [ "$1" = '--nomsg' ]; then
@@ -1627,22 +1634,41 @@ testfailure() {
 
 testreturnstateequal() {
        local STATE="$1"
-       msggroup "${STATE}equal"
-       if [ "$2" != '--nomsg' ]; then
-               local CMP="$2"
-               shift 2
-               "$STATE" "$@"
-               testfileequal "${TMPWORKINGDIRECTORY}/rootdir/tmp/${STATE}.output" "$CMP"
-       else
-               local CMP="$3"
+       if [ "$STATE" = 'testsuccesswithglobalerror' ]; then
+               local STATE="$2"
+               local TYPE="$3"
                shift 3
-               "$STATE" --nomsg "$@"
-               testfileequal "${TMPWORKINGDIRECTORY}/rootdir/tmp/${STATE}.output" "$CMP"
+               msggroup "${STATE}equal"
+               if [ "$1" != '--nomsg' ]; then
+                       local CMP="$1"
+                       shift
+                       testsuccesswithglobalerror "$STATE" "$TYPE" "$@"
+                       testfileequal "${TMPWORKINGDIRECTORY}/rootdir/tmp/${STATE}.output" "$CMP"
+               else
+                       local CMP="$2"
+                       shift 2
+                       testsuccesswithglobalerror "$STATE" "$TYPE" "$@"
+                       testfileequal "${TMPWORKINGDIRECTORY}/rootdir/tmp/${STATE}.output" "$CMP"
+               fi
+       else
+               msggroup "${STATE}equal"
+               if [ "$2" != '--nomsg' ]; then
+                       local CMP="$2"
+                       shift 2
+                       "$STATE" "$@"
+                       testfileequal "${TMPWORKINGDIRECTORY}/rootdir/tmp/${STATE}.output" "$CMP"
+               else
+                       local CMP="$3"
+                       shift 3
+                       "$STATE" --nomsg "$@"
+                       testfileequal "${TMPWORKINGDIRECTORY}/rootdir/tmp/${STATE}.output" "$CMP"
+               fi
        fi
        msggroup
 }
 testsuccessequal() {
-       testreturnstateequal 'testsuccess' "$@"
+       # we compare output, so we know perfectly well about N:
+       testreturnstateequal 'testsuccesswithglobalerror' 'testsuccess' 'WE' "$@"
 }
 testwarningequal() {
        testreturnstateequal 'testwarning' "$@"
@@ -1658,7 +1684,18 @@ testfailuremsg() {
        testfailure "$@"
        msgtest 'Check that the output of the previous failed command has expected' 'failures and warnings'
        local COMPAREFILE="${TMPWORKINGDIRECTORY}/rootdir/tmp/testfailuremsg.comparefile"
-       grep '^\(W\|E\):' "${TMPWORKINGDIRECTORY}/rootdir/tmp/testfailure.output" > "$COMPAREFILE" 2>&1 || true
+       grep '^\(W\|E\|N\):' "${TMPWORKINGDIRECTORY}/rootdir/tmp/testfailure.output" > "$COMPAREFILE" 2>&1 || true
+       testoutputequal "$COMPAREFILE" echo "$CMP"
+       msggroup
+}
+testwarningmsg() {
+       msggroup 'testwarningmsg'
+       local CMP="$1"
+       shift
+       testwarning "$@"
+       msgtest 'Check that the output of the previous warned command has expected' 'warnings'
+       local COMPAREFILE="${TMPWORKINGDIRECTORY}/rootdir/tmp/testwarningmsg.comparefile"
+       grep '^\(W\|E\|N\):' "${TMPWORKINGDIRECTORY}/rootdir/tmp/testwarning.output" > "$COMPAREFILE" 2>&1 || true
        testoutputequal "$COMPAREFILE" echo "$CMP"
        msggroup
 }
@@ -1729,8 +1766,8 @@ listcurrentlistsdirectory() {
 ### convenience hacks ###
 mkdir() {
        # creating some directories by hand is a tedious task, so make it look simple
-       if [ "$*" = '-p rootdir/var/lib/apt/lists' ] || [ "$*" = "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists" ] ||
-          [ "$*" = '-p rootdir/var/lib/apt/lists/partial' ] || [ "$*" = "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists/partial" ]; then
+       local PARAMS="$*"
+       if [ "$PARAMS" != "${PARAMS#*rootdir/var/lib/apt/lists}" ]; then
                # only the last directory created by mkdir is effected by the -m !
                command mkdir -m 755 -p "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt"
                command mkdir -m 755 -p "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists"