]> git.saurik.com Git - apt.git/blobdiff - test/integration/test-partial-file-support
tests: support spaces in path and TMPDIR
[apt.git] / test / integration / test-partial-file-support
index 382789e68515efed21d0b9e98b6d73ce7fb22586..8cfc3f2d3c0dc2e13ea6c28f90831fdc166ab446 100755 (executable)
@@ -1,8 +1,8 @@
 #!/bin/sh
 set -e
 
 #!/bin/sh
 set -e
 
-TESTDIR=$(readlink -f $(dirname $0))
-. $TESTDIR/framework
+TESTDIR="$(readlink -f "$(dirname "$0")")"
+. "$TESTDIR/framework"
 setupenvironment
 configarchitecture 'amd64'
 
 setupenvironment
 configarchitecture 'amd64'
 
@@ -13,23 +13,36 @@ copysource() {
        touch -d "$(stat --format '%y' "${TESTFILE}")" "$3"
 }
 
        touch -d "$(stat --format '%y' "${TESTFILE}")" "$3"
 }
 
+DOWNLOADLOG='rootdir/tmp/testdownloadfile.log'
+
 testdownloadfile() {
 testdownloadfile() {
-       local DOWNLOG='download-testfile.log'
-       rm -f "$DOWNLOG"
-       msgtest "Testing download of file $2 with" "$1"
-       if ! downloadfile "$2" "$3" > "$DOWNLOG"; then
-               cat >&2 "$DOWNLOG"
+       rm -f "$DOWNLOADLOG"
+       msgtest "Testing download of file $2 with" "$1 $5"
+       if ! downloadfile "$2" "$3" "$5" > "$DOWNLOADLOG"; then
+               cat >&2 "$DOWNLOADLOG"
                msgfail
        else
                msgpass
        fi
                msgfail
        else
                msgpass
        fi
-       cat "$DOWNLOG" | while read field hash; do
+       sed -e '/^ <- / s#%20# #g' -e '/^ <- / s#%0a#\n#g' "$DOWNLOADLOG" | grep '^.*-Hash: ' > receivedhashes.log
+       testsuccess test -s receivedhashes.log
+       local HASHES_OK=0
+       local HASHES_BAD=0
+       while read field hash; do
                local EXPECTED
                case "$field" in
                'MD5Sum-Hash:') EXPECTED="$(md5sum "$TESTFILE" | cut -d' ' -f 1)";;
                'SHA1-Hash:') EXPECTED="$(sha1sum "$TESTFILE" | cut -d' ' -f 1)";;
                'SHA256-Hash:') EXPECTED="$(sha256sum "$TESTFILE" | cut -d' ' -f 1)";;
                'SHA512-Hash:') EXPECTED="$(sha512sum "$TESTFILE" | cut -d' ' -f 1)";;
                local EXPECTED
                case "$field" in
                'MD5Sum-Hash:') EXPECTED="$(md5sum "$TESTFILE" | cut -d' ' -f 1)";;
                'SHA1-Hash:') EXPECTED="$(sha1sum "$TESTFILE" | cut -d' ' -f 1)";;
                'SHA256-Hash:') EXPECTED="$(sha256sum "$TESTFILE" | cut -d' ' -f 1)";;
                'SHA512-Hash:') EXPECTED="$(sha512sum "$TESTFILE" | cut -d' ' -f 1)";;
+               'Checksum-FileSize-Hash:')
+                       #filesize is too weak to check for !=
+                       if [ "$4" = '=' ]; then
+                               EXPECTED="$(stat -c '%s' "$TESTFILE")"
+                       else
+                               continue
+                       fi
+                       ;;
                *) continue;;
                esac
                if [ "$4" = '=' ]; then
                *) continue;;
                esac
                if [ "$4" = '=' ]; then
@@ -39,69 +52,97 @@ testdownloadfile() {
                fi
                if [ "$EXPECTED" "$4" "$hash" ]; then
                        msgpass
                fi
                if [ "$EXPECTED" "$4" "$hash" ]; then
                        msgpass
+                       HASHES_OK=$((HASHES_OK+1));
                else
                else
-                       cat >&2 "$DOWNLOG"
                        msgfail "expected: $EXPECTED ; got: $hash"
                        msgfail "expected: $EXPECTED ; got: $hash"
+                       HASHES_BAD=$((HASHES_BAD+1));
                fi
                fi
-       done
-}
-
-testwebserverlaststatuscode() {
-       local DOWNLOG='download-testfile.log'
-       rm -f "$DOWNLOG"
-       local STATUS="$(mktemp)"
-       addtrap "rm $STATUS;"
-       msgtest 'Test last status code from the webserver was' "$1"
-       downloadfile "http://localhost:8080/_config/find/aptwebserver::last-status-code" "$STATUS" > "$DOWNLOG"
-       if [ "$(cat "$STATUS")" = "$1" ]; then
-               msgpass
+       done < receivedhashes.log
+       msgtest 'At least one good hash and no bad ones'
+       if [ $HASHES_OK -eq 0 ] || [ $HASHES_BAD -ne 0 ]; then
+               cat >&2 "$DOWNLOADLOG"
+               msgfail
        else
        else
-               cat >&2 "$DOWNLOG"
-               msgfail "Status was $(cat "$STATUS")"
+               msgpass
        fi
 }
 
        fi
 }
 
-
 TESTFILE='aptarchive/testfile'
 TESTFILE='aptarchive/testfile'
-cp -a ${TESTDIR}/framework $TESTFILE
+cp -a "${TESTDIR}/framework" "$TESTFILE"
+cp -a "${TESTDIR}/framework" "${TESTFILE}2"
+
+followuprequest() {
+       local DOWN='./downloaded/testfile'
+
+       copysource $TESTFILE 1M $DOWN
+       testdownloadfile 'completely downloaded file' "${1}/testfile" "$DOWN" '='
+       testwebserverlaststatuscode '416' "$DOWNLOADLOG"
+
+       webserverconfig 'aptwebserver::support::content-range' 'false'
+       copysource $TESTFILE 1M $DOWN
+       testdownloadfile 'completely downloaded file' "${1}/testfile" "$DOWN" '=' "SHA1:$(sha1sum "$TESTFILE" | cut -d' ' -f 1)"
+       testwebserverlaststatuscode '416' "$DOWNLOADLOG"
+       webserverconfig 'aptwebserver::support::content-range' 'true'
+
+       copysource $TESTFILE 1M $DOWN
+       copysource "${TESTFILE}2" 20 "${DOWN}2"
+       msgtest 'Testing download of files with' 'completely downloaded file + partial file'
+       testsuccess --nomsg apthelper -o Debug::Acquire::${1%%:*}=1 -o Debug::pkgAcquire::Worker=1 \
+               download-file "$1/testfile" "$DOWN" '' "$1/testfile2" "${DOWN}2"
+       testwebserverlaststatuscode '206' 'rootdir/tmp/testsuccess.output'
+       testsuccess diff -u "$TESTFILE" "${DOWN}"
+       testsuccess diff -u "${DOWN}" "${DOWN}2"
+}
 
 testrun() {
        webserverconfig 'aptwebserver::support::range' 'true'
 
 testrun() {
        webserverconfig 'aptwebserver::support::range' 'true'
+       local DOWN='./downloaded/testfile'
 
 
-       copysource $TESTFILE 0 ./testfile
-       testdownloadfile 'no data' "${1}/testfile" './testfile' '='
-       testwebserverlaststatuscode '200'
+       copysource $TESTFILE 0 $DOWN
+       testdownloadfile 'no data' "${1}/testfile" "$DOWN" '='
+       testwebserverlaststatuscode '200' "$DOWNLOADLOG"
 
 
-       copysource $TESTFILE 20 ./testfile
-       testdownloadfile 'valid partial data' "${1}/testfile" './testfile' '='
-       testwebserverlaststatuscode '206'
+       copysource $TESTFILE 20 $DOWN
+       testdownloadfile 'valid partial data' "${1}/testfile" "$DOWN" '='
+       testwebserverlaststatuscode '206' "$DOWNLOADLOG"
 
 
-       copysource /dev/zero 20 ./testfile
-       testdownloadfile 'invalid partial data' "${1}/testfile" './testfile' '!='
-       testwebserverlaststatuscode '206'
+       copysource /dev/zero 20 $DOWN
+       testdownloadfile 'invalid partial data' "${1}/testfile" "$DOWN" '!='
+       testwebserverlaststatuscode '206' "$DOWNLOADLOG"
 
 
-       copysource $TESTFILE 1M ./testfile
-       testdownloadfile 'completely downloaded file' "${1}/testfile" './testfile' '='
-       testwebserverlaststatuscode '416'
+       webserverconfig 'aptwebserver::closeOnError' 'false'
+       followuprequest "$1"
+       webserverconfig 'aptwebserver::closeOnError' 'true'
+       followuprequest "$1"
+       webserverconfig 'aptwebserver::closeOnError' 'false'
 
 
-       copysource /dev/zero 1M ./testfile
-       testdownloadfile 'too-big partial file' "${1}/testfile" './testfile' '='
-       testwebserverlaststatuscode '200'
+       copysource /dev/zero 1M $DOWN
+       testdownloadfile 'too-big partial file' "${1}/testfile" "$DOWN" '='
+       testwebserverlaststatuscode '200' "$DOWNLOADLOG"
 
 
-       copysource /dev/zero 20 ./testfile
-       touch ./testfile
-       testdownloadfile 'old data' "${1}/testfile" './testfile' '='
-       testwebserverlaststatuscode '200'
+       copysource /dev/zero 20 $DOWN
+       touch $DOWN
+       testdownloadfile 'old data' "${1}/testfile" "$DOWN" '='
+       testwebserverlaststatuscode '200' "$DOWNLOADLOG"
 
        webserverconfig 'aptwebserver::support::range' 'false'
 
 
        webserverconfig 'aptwebserver::support::range' 'false'
 
-       copysource $TESTFILE 20 ./testfile
-       testdownloadfile 'no server support' "${1}/testfile" './testfile' '='
-       testwebserverlaststatuscode '200'
+       copysource $TESTFILE 20 $DOWN
+       testdownloadfile 'no server support' "${1}/testfile" "$DOWN" '='
+       testwebserverlaststatuscode '200' "$DOWNLOADLOG"
+}
+
+serverconfigs() {
+       msgmsg "${1%%:*}: Test with Content-Length"
+       webserverconfig 'aptwebserver::chunked-transfer-encoding' 'false'
+       testrun "$1"
+       msgmsg "${1%%:*}: Test with Transfer-Encoding: chunked"
+       webserverconfig 'aptwebserver::chunked-transfer-encoding' 'true'
+       testrun "$1"
 }
 
 }
 
-testrun 'http://localhost:8080'
+serverconfigs "http://localhost:${APTHTTPPORT}"
 
 changetohttpswebserver
 
 
 changetohttpswebserver
 
-testrun 'https://localhost:4433'
+serverconfigs "https://localhost:${APTHTTPSPORT}"