]> git.saurik.com Git - apt.git/blobdiff - test/integration/framework
disable updating insecure repositories in apt by default
[apt.git] / test / integration / framework
index 83f93217fb6cf813469a74af1167e3342601fd57..f9bb2e8243c701c881bbef7c67cc2468b1309f99 100644 (file)
@@ -9,6 +9,14 @@ while [ -n "$1" ]; do
                export MSGLEVEL=4
        elif [ "$1" = '--color=no' ]; then
                export MSGCOLOR='NO'
+       elif [ "$1" = '--color=yes' ]; then
+               export MSGCOLOR='YES'
+       elif [ "$1" = '--color' ]; then
+               export MSGCOLOR="$(echo "$2" | tr 'a-z' 'A-Z')"
+               shift
+       elif [ "$1" = '--level' ]; then
+               export MSGLEVEL=$2
+               shift
        else
                echo >&2 "WARNING: Unknown parameter »$1« will be ignored"
        fi
@@ -17,7 +25,7 @@ done
 export MSGLEVEL="${MSGLEVEL:-3}"
 
 # we all like colorful messages
-if [ "$MSGCOLOR" != 'NO' ] && [ "$MSGCOLOR" != 'ALWAYS' ]; then
+if [ "${MSGCOLOR:-YES}" = 'YES' ]; then
        if [ ! -t 1 ]; then # but check that we output to a terminal
                export MSGCOLOR='NO'
        fi
@@ -380,12 +388,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
@@ -498,12 +502,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
@@ -1119,7 +1117,7 @@ redatereleasefiles() {
 }
 
 webserverconfig() {
-       local WEBSERVER="${3:-http://localhost:8080}"
+       local WEBSERVER="${3:-http://localhost:${APTHTTPPORT}}"
        local NOCHECK=false
        if [ "$1" = '--no-check' ]; then
                NOCHECK=true
@@ -1128,13 +1126,14 @@ webserverconfig() {
        local DOWNLOG='rootdir/tmp/download-testfile.log'
        local STATUS='downloaded/webserverconfig.status'
        rm -f "$STATUS" "$DOWNLOG"
+       # very very basic URI encoding
        local URI
        if [ -n "$2" ]; then
                msgtest "Set webserver config option '${1}' to" "$2"
-               URI="${WEBSERVER}/_config/set/${1}/${2}"
+               URI="${WEBSERVER}/_config/set/$(echo "${1}" | sed -e 's/\//%2f/g')/$(echo "${2}" | sed -e 's/\//%2f/g')"
        else
                msgtest 'Clear webserver config option' "${1}"
-               URI="${WEBSERVER}/_config/clear/${1}"
+               URI="${WEBSERVER}/_config/clear/$(echo "${1}" | sed -e 's/\//%2f/g')"
        fi
        if downloadfile "$URI" "$STATUS" > "$DOWNLOG"; then
                msgpass
@@ -1148,8 +1147,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:8080/#${1}#" -e "s#https://localhost:4433/#${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
 }
 
@@ -1168,28 +1170,37 @@ waitforpidfile() {
 }
 
 changetowebserver() {
+       local REWRITE='no'
        if [ "$1" != '--no-rewrite' ]; then
-               rewritesourceslist 'http://localhost:8080/'
+               REWRITE='yes'
        else
                shift
        fi
        if test -x "${APTWEBSERVERBINDIR}/aptwebserver"; then
                cd aptarchive
                local LOG="webserver.log"
-               if ! aptwebserver -o aptwebserver::fork=1 "$@" >$LOG 2>&1 ; then
+               if ! aptwebserver --port 0 -o aptwebserver::fork=1 -o aptwebserver::portfile='aptwebserver.port' "$@" >$LOG 2>&1 ; then
                        cat $LOG
                        false
                fi
-                waitforpidfile aptwebserver.pid
+               waitforpidfile aptwebserver.pid
                local PID="$(cat aptwebserver.pid)"
                if [ -z "$PID" ]; then
                        msgdie 'Could not fork aptwebserver successfully'
                fi
                addtrap "kill $PID;"
+               waitforpidfile aptwebserver.port
+               APTHTTPPORT="$(cat aptwebserver.port)"
+               if [ -z "$APTHTTPPORT" ]; then
+                       msgdie 'Could not get port for aptwebserver successfully'
+               fi
                cd - > /dev/null
        else
                msgdie 'You have to build aptwerbserver or install a webserver'
        fi
+       if [ "$REWRTE" != 'yes' ]; then
+               rewritesourceslist "http://localhost:${APTHTTPPORT}/"
+       fi
 }
 
 changetohttpswebserver() {
@@ -1204,8 +1215,8 @@ cert = ${TMPWORKINGDIRECTORY}/rootdir/etc/webserver.pem
 output = /dev/null
 
 [https]
-accept = 4433
-connect = 8080
+accept = 0
+connect = $APTHTTPPORT
 " > "${TMPWORKINGDIRECTORY}/stunnel.conf"
        stunnel4 "${TMPWORKINGDIRECTORY}/stunnel.conf"
         waitforpidfile "${TMPWORKINGDIRECTORY}/aptarchive/stunnel.pid"
@@ -1214,7 +1225,9 @@ connect = 8080
                msgdie 'Could not fork stunnel4 successfully'
        fi
        addtrap 'prefix' "kill ${PID};"
-       rewritesourceslist 'https://localhost:4433/'
+       APTHTTPSPORT="$(lsof -i | awk "/^stunnel4 / && \$2 == \"${PID}\" {print \$9; exit; }" | cut -d':' -f 2)"
+       webserverconfig 'aptwebserver::port::https' "$APTHTTPSPORT" "https://localhost:${APTHTTPSPORT}"
+       rewritesourceslist "https://localhost:${APTHTTPSPORT}/"
 }
 
 changetocdrom() {
@@ -1638,7 +1651,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
 }
@@ -1671,7 +1695,7 @@ testwebserverlaststatuscode() {
        local STATUS='downloaded/webserverstatus-statusfile.log'
        rm -f "$DOWNLOG" "$STATUS"
        msgtest 'Test last status code from the webserver was' "$1"
-       if downloadfile "http://localhost:8080/_config/find/aptwebserver::last-status-code" "$STATUS" > "$DOWNLOG" && [ "$(cat "$STATUS")" = "$1" ]; then
+       if downloadfile "http://localhost:${APTHTTPPORT}/_config/find/aptwebserver::last-status-code" "$STATUS" > "$DOWNLOG" && [ "$(cat "$STATUS")" = "$1" ]; then
                msgpass
        else
                local OUTPUT="${TMPWORKINGDIRECTORY}/rootdir/tmp/testwebserverlaststatuscode.output"