This allows running tests in parallel.
Git-Dch: Ignore
Tests: run-tests
Restrictions: allow-stderr
-Depends: @, @builddeps@, fakeroot, wget, stunnel4, db-util, gnupg, gnupg2
+Depends: @, @builddeps@, fakeroot, wget, stunnel4, lsof, db-util, gnupg, gnupg2
}
webserverconfig() {
- local WEBSERVER="${3:-http://localhost:8080}"
+ local WEBSERVER="${3:-http://localhost:${APTHTTPPORT}}"
local NOCHECK=false
if [ "$1" = '--no-check' ]; then
NOCHECK=true
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
rewritesourceslist() {
local APTARCHIVE="file://$(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#http://localhost:${APTHTTPPORT}/#${1}#" -e "s#https://localhost:${APTHTTPSPORT}/#${1}#"
done
}
}
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() {
output = /dev/null
[https]
-accept = 4433
-connect = 8080
+accept = 0
+connect = $APTHTTPPORT
" > "${TMPWORKINGDIRECTORY}/stunnel.conf"
stunnel4 "${TMPWORKINGDIRECTORY}/stunnel.conf"
waitforpidfile "${TMPWORKINGDIRECTORY}/aptarchive/stunnel.pid"
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() {
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"
filedown() {
msgtest 'Downloading the same URI twice over file' "$1"
- testsuccess --nomsg apthelper download-file "file:///$APTARCHIVE/foo" ./downloaded/foo1 '' "file:///$APTARCHIVE/foo" ./downloaded/foo2 '' -o Debug::pkgAcquire::Worker=1
+ testsuccess --nomsg apthelper download-file "file:///$APTARCHIVE/foo" './downloaded/foo1' '' \
+ "file:///$APTARCHIVE/foo" './downloaded/foo2' '' -o Debug::pkgAcquire::Worker=1
cp rootdir/tmp/testsuccess.output download.log
testsuccess cmp "$TESTFILE" ./downloaded/foo1
testsuccess cmp ./downloaded/foo1 ./downloaded/foo2
httpdown() {
msgtest 'Downloading the same URI to different files' 'twice over http'
- testsuccess --nomsg apthelper download-file http://localhost:8080/foo ./downloaded/foo1 '' http://localhost:8080/foo ./downloaded/foo2 '' -o Debug::pkgAcquire::Worker=1 -o Debug::Acquire::http=1
+ testsuccess --nomsg apthelper download-file "http://localhost:${APTHTTPPORT}/foo" "./downloaded/foo1" '' \
+ "http://localhost:${APTHTTPPORT}/foo" './downloaded/foo2' '' -o Debug::pkgAcquire::Worker=1 -o Debug::Acquire::http=1
cp rootdir/tmp/testsuccess.output download.log
testsuccess cmp "$TESTDIR/framework" ./downloaded/foo1
testsuccess cmp ./downloaded/foo1 ./downloaded/foo2
httpredirectdown() {
msgtest 'Redirect leads' 'first URI to the second URI'
- testsuccess --nomsg apthelper download-file http://localhost:8080/foo2 ./downloaded/foo1 '' http://localhost:8080/foo ./downloaded/foo2 '' -o Debug::pkgAcquire::Worker=1 -o Debug::Acquire::http=1
+ testsuccess --nomsg apthelper download-file "http://localhost:${APTHTTPPORT}/foo2" "./downloaded/foo1" '' \
+ "http://localhost:${APTHTTPPORT}/foo" './downloaded/foo2' '' -o Debug::pkgAcquire::Worker=1 -o Debug::Acquire::http=1
cp rootdir/tmp/testsuccess.output download.log
testsuccess cmp "$TESTDIR/framework" ./downloaded/foo1
testsuccess cmp ./downloaded/foo1 ./downloaded/foo2
httpsamedown() {
msgtest 'Downloading two files via the same URI to' 'the same file'
- testsuccess --nomsg apthelper download-file http://localhost:8080/foo ./downloaded/foo1 '' http://localhost:8080/foo ./downloaded/foo1 '' -o Debug::pkgAcquire::Worker=1
+ testsuccess --nomsg apthelper download-file "http://localhost:${APTHTTPPORT}/foo" "./downloaded/foo1" '' \
+ "http://localhost:${APTHTTPPORT}/foo" './downloaded/foo1' '' -o Debug::pkgAcquire::Worker=1
cp rootdir/tmp/testsuccess.output download.log
testsuccess cmp "$TESTDIR/framework" ./downloaded/foo1
testequal '1' grep -c '200%20URI%20Start' ./download.log
changetowebserver
-tworepos 'http' '//localhost:8080' 'no partial'
+tworepos 'http' "//localhost:${APTHTTPPORT}" 'no partial'
testequal '10' grep -c '200%20URI%20Start' ./download.log
testequal '10' grep -c '201%20URI%20Done' ./download.log
testequal '6' grep -c '^ @ Queue: Action combined' ./download.log
-tworepos 'http' '//localhost:8080' 'hit'
+tworepos 'http' "//localhost:${APTHTTPPORT}" 'hit'
testequal '2' grep -c '200%20URI%20Start' ./download.log
testequal '4' grep -c '201%20URI%20Done' ./download.log
testequal '0' grep -c '^ @ Queue: Action combined' ./download.log
setupaptarchive --no-update
changetowebserver
-testequal "'http://localhost:8080/dists/unstable/InRelease' localhost:8080_dists_unstable_InRelease 0
-'http://localhost:8080/dists/unstable/main/source/Sources.xz' localhost:8080_dists_unstable_main_source_Sources 0
-'http://localhost:8080/dists/unstable/main/binary-amd64/Packages.xz' localhost:8080_dists_unstable_main_binary-amd64_Packages 0
-'http://localhost:8080/dists/unstable/main/i18n/Translation-en.xz' localhost:8080_dists_unstable_main_i18n_Translation-en 0 " aptget update --print-uris
-
-testsuccessequal "Get:1 http://localhost:8080 unstable InRelease [$(stat -c%s aptarchive/dists/unstable/InRelease) B]
-Get:2 http://localhost:8080 unstable/main Sources [$(stat -c%s aptarchive/dists/unstable/main/source/Sources.gz) B]
-Get:3 http://localhost:8080 unstable/main amd64 Packages [$(stat -c%s aptarchive/dists/unstable/main/binary-amd64/Packages.gz) B]
-Get:4 http://localhost:8080 unstable/main Translation-en [$(stat -c%s aptarchive/dists/unstable/main/i18n/Translation-en.gz) B]
+testequal "'http://localhost:${APTHTTPPORT}/dists/unstable/InRelease' localhost:${APTHTTPPORT}_dists_unstable_InRelease 0
+'http://localhost:${APTHTTPPORT}/dists/unstable/main/source/Sources.xz' localhost:${APTHTTPPORT}_dists_unstable_main_source_Sources 0
+'http://localhost:${APTHTTPPORT}/dists/unstable/main/binary-amd64/Packages.xz' localhost:${APTHTTPPORT}_dists_unstable_main_binary-amd64_Packages 0
+'http://localhost:${APTHTTPPORT}/dists/unstable/main/i18n/Translation-en.xz' localhost:${APTHTTPPORT}_dists_unstable_main_i18n_Translation-en 0 " aptget update --print-uris
+
+testsuccessequal "Get:1 http://localhost:${APTHTTPPORT} unstable InRelease [$(stat -c%s aptarchive/dists/unstable/InRelease) B]
+Get:2 http://localhost:${APTHTTPPORT} unstable/main Sources [$(stat -c%s aptarchive/dists/unstable/main/source/Sources.gz) B]
+Get:3 http://localhost:${APTHTTPPORT} unstable/main amd64 Packages [$(stat -c%s aptarchive/dists/unstable/main/binary-amd64/Packages.gz) B]
+Get:4 http://localhost:${APTHTTPPORT} unstable/main Translation-en [$(stat -c%s aptarchive/dists/unstable/main/i18n/Translation-en.gz) B]
Reading package lists..." aptget update
testempty find rootdir/var/lib/apt/lists -name '*Contents*'
};
EOF
-testequal "$(readlink -f ./rootdir/var/lib/apt/lists/localhost:8080_dists_unstable_main_Contents-amd64)" aptget indextargets --no-release-info --format '$(FILENAME)' 'Created-By: Contents'
+testequal "$(readlink -f ./rootdir/var/lib/apt/lists/localhost:${APTHTTPPORT}_dists_unstable_main_Contents-amd64)" aptget indextargets --no-release-info --format '$(FILENAME)' 'Created-By: Contents'
testempty aptget indextargets --format '$(FILENAME)' 'Created-By: Contents'
# lets fake the existence of a compressed Contents file
-touch ./rootdir/var/lib/apt/lists/localhost:8080_dists_unstable_main_Contents-amd64.gz
-testequal "$(readlink -f ./rootdir/var/lib/apt/lists/localhost:8080_dists_unstable_main_Contents-amd64.gz)" aptget indextargets --format '$(FILENAME)' 'Created-By: Contents'
+touch ./rootdir/var/lib/apt/lists/localhost:${APTHTTPPORT}_dists_unstable_main_Contents-amd64.gz
+testequal "$(readlink -f ./rootdir/var/lib/apt/lists/localhost:${APTHTTPPORT}_dists_unstable_main_Contents-amd64.gz)" aptget indextargets --format '$(FILENAME)' 'Created-By: Contents'
-testequal "'http://localhost:8080/dists/unstable/InRelease' localhost:8080_dists_unstable_InRelease 0
-'http://localhost:8080/dists/unstable/main/source/Sources.xz' localhost:8080_dists_unstable_main_source_Sources 0
-'http://localhost:8080/dists/unstable/main/binary-amd64/Packages.xz' localhost:8080_dists_unstable_main_binary-amd64_Packages 0
-'http://localhost:8080/dists/unstable/main/i18n/Translation-en.xz' localhost:8080_dists_unstable_main_i18n_Translation-en 0
-'http://localhost:8080/dists/unstable/main/Contents-amd64.xz' localhost:8080_dists_unstable_main_Contents-amd64 0 " aptget update --print-uris
+testequal "'http://localhost:${APTHTTPPORT}/dists/unstable/InRelease' localhost:${APTHTTPPORT}_dists_unstable_InRelease 0
+'http://localhost:${APTHTTPPORT}/dists/unstable/main/source/Sources.xz' localhost:${APTHTTPPORT}_dists_unstable_main_source_Sources 0
+'http://localhost:${APTHTTPPORT}/dists/unstable/main/binary-amd64/Packages.xz' localhost:${APTHTTPPORT}_dists_unstable_main_binary-amd64_Packages 0
+'http://localhost:${APTHTTPPORT}/dists/unstable/main/i18n/Translation-en.xz' localhost:${APTHTTPPORT}_dists_unstable_main_i18n_Translation-en 0
+'http://localhost:${APTHTTPPORT}/dists/unstable/main/Contents-amd64.xz' localhost:${APTHTTPPORT}_dists_unstable_main_Contents-amd64 0 " aptget update --print-uris
-testsuccessequal "Hit:1 http://localhost:8080 unstable InRelease
-Get:2 http://localhost:8080 unstable/main amd64 Contents [$(stat -c%s aptarchive/dists/unstable/main/Contents-amd64.gz) B]
+testsuccessequal "Hit:1 http://localhost:${APTHTTPPORT} unstable InRelease
+Get:2 http://localhost:${APTHTTPPORT} unstable/main amd64 Contents [$(stat -c%s aptarchive/dists/unstable/main/Contents-amd64.gz) B]
Reading package lists..." aptget update
-testequal 'rootdir/var/lib/apt/lists/localhost:8080_dists_unstable_main_Contents-amd64' find rootdir/var/lib/apt/lists -name '*Contents*'
-testequal "$(readlink -f ./rootdir/var/lib/apt/lists/localhost:8080_dists_unstable_main_Contents-amd64)" aptget indextargets --format '$(FILENAME)' 'Created-By: Contents'
-testsuccess cmp 'rootdir/var/lib/apt/lists/localhost:8080_dists_unstable_main_Contents-amd64' 'aptarchive/dists/unstable/main/Contents-amd64'
+testequal "rootdir/var/lib/apt/lists/localhost:${APTHTTPPORT}_dists_unstable_main_Contents-amd64" find rootdir/var/lib/apt/lists -name '*Contents*'
+testequal "$(readlink -f ./rootdir/var/lib/apt/lists/localhost:${APTHTTPPORT}_dists_unstable_main_Contents-amd64)" aptget indextargets --format '$(FILENAME)' 'Created-By: Contents'
+testsuccess cmp "rootdir/var/lib/apt/lists/localhost:${APTHTTPPORT}_dists_unstable_main_Contents-amd64" 'aptarchive/dists/unstable/main/Contents-amd64'
-rm ./rootdir/var/lib/apt/lists/localhost:8080_dists_unstable_main_Contents-amd64
+rm ./rootdir/var/lib/apt/lists/localhost:${APTHTTPPORT}_dists_unstable_main_Contents-amd64
testempty aptget indextargets --format '$(FILENAME)' 'Created-By: Contents'
# if we asked for keeping it compressed, keep it
echo 'Acquire::IndexTargets::deb::Contents::KeepCompressed "true";' >> rootdir/etc/apt/apt.conf.d/content-target.conf
-testsuccessequal "Hit:1 http://localhost:8080 unstable InRelease
-Get:2 http://localhost:8080 unstable/main amd64 Contents [$(stat -c%s aptarchive/dists/unstable/main/Contents-amd64.gz) B]
+testsuccessequal "Hit:1 http://localhost:${APTHTTPPORT} unstable InRelease
+Get:2 http://localhost:${APTHTTPPORT} unstable/main amd64 Contents [$(stat -c%s aptarchive/dists/unstable/main/Contents-amd64.gz) B]
Reading package lists..." aptget update
-testequal 'rootdir/var/lib/apt/lists/localhost:8080_dists_unstable_main_Contents-amd64.gz' find rootdir/var/lib/apt/lists -name '*Contents*'
-testequal "$(readlink -f ./rootdir/var/lib/apt/lists/localhost:8080_dists_unstable_main_Contents-amd64.gz)" aptget indextargets --format '$(FILENAME)' 'Created-By: Contents'
-testsuccess cmp 'rootdir/var/lib/apt/lists/localhost:8080_dists_unstable_main_Contents-amd64.gz' 'aptarchive/dists/unstable/main/Contents-amd64.gz'
+testequal "rootdir/var/lib/apt/lists/localhost:${APTHTTPPORT}_dists_unstable_main_Contents-amd64.gz" find rootdir/var/lib/apt/lists -name '*Contents*'
+testequal "$(readlink -f ./rootdir/var/lib/apt/lists/localhost:${APTHTTPPORT}_dists_unstable_main_Contents-amd64.gz)" aptget indextargets --format '$(FILENAME)' 'Created-By: Contents'
+testsuccess cmp "rootdir/var/lib/apt/lists/localhost:${APTHTTPPORT}_dists_unstable_main_Contents-amd64.gz" 'aptarchive/dists/unstable/main/Contents-amd64.gz'
-rm ./rootdir/var/lib/apt/lists/localhost:8080_dists_unstable_main_Contents-amd64.gz
+rm ./rootdir/var/lib/apt/lists/localhost:${APTHTTPPORT}_dists_unstable_main_Contents-amd64.gz
testempty aptget indextargets --format '$(FILENAME)' 'Created-By: Contents'
# and no automatic uncompress based on the name please,
EOF
# the last line is utter bogus of course, but how should apt know…
-testequal "'http://localhost:8080/dists/unstable/InRelease' localhost:8080_dists_unstable_InRelease 0
-'http://localhost:8080/dists/unstable/main/source/Sources.xz' localhost:8080_dists_unstable_main_source_Sources 0
-'http://localhost:8080/dists/unstable/main/binary-amd64/Packages.xz' localhost:8080_dists_unstable_main_binary-amd64_Packages 0
-'http://localhost:8080/dists/unstable/main/i18n/Translation-en.xz' localhost:8080_dists_unstable_main_i18n_Translation-en 0
-'http://localhost:8080/dists/unstable/main/Contents-amd64.gz.xz' localhost:8080_dists_unstable_main_Contents-amd64.gz 0 " aptget update --print-uris
-
-testsuccessequal "Hit:1 http://localhost:8080 unstable InRelease
-Get:2 http://localhost:8080 unstable/main amd64 Contents.gz [$(stat -c%s aptarchive/dists/unstable/main/Contents-amd64.gz) B]
+testequal "'http://localhost:${APTHTTPPORT}/dists/unstable/InRelease' localhost:${APTHTTPPORT}_dists_unstable_InRelease 0
+'http://localhost:${APTHTTPPORT}/dists/unstable/main/source/Sources.xz' localhost:${APTHTTPPORT}_dists_unstable_main_source_Sources 0
+'http://localhost:${APTHTTPPORT}/dists/unstable/main/binary-amd64/Packages.xz' localhost:${APTHTTPPORT}_dists_unstable_main_binary-amd64_Packages 0
+'http://localhost:${APTHTTPPORT}/dists/unstable/main/i18n/Translation-en.xz' localhost:${APTHTTPPORT}_dists_unstable_main_i18n_Translation-en 0
+'http://localhost:${APTHTTPPORT}/dists/unstable/main/Contents-amd64.gz.xz' localhost:${APTHTTPPORT}_dists_unstable_main_Contents-amd64.gz 0 " aptget update --print-uris
+
+testsuccessequal "Hit:1 http://localhost:${APTHTTPPORT} unstable InRelease
+Get:2 http://localhost:${APTHTTPPORT} unstable/main amd64 Contents.gz [$(stat -c%s aptarchive/dists/unstable/main/Contents-amd64.gz) B]
Reading package lists..." aptget update
-testequal 'rootdir/var/lib/apt/lists/localhost:8080_dists_unstable_main_Contents-amd64.gz' find rootdir/var/lib/apt/lists -name '*Contents*'
-testequal "$(readlink -f ./rootdir/var/lib/apt/lists/localhost:8080_dists_unstable_main_Contents-amd64.gz)" aptget indextargets --format '$(FILENAME)' 'Created-By: Contents'
-testsuccess cmp 'rootdir/var/lib/apt/lists/localhost:8080_dists_unstable_main_Contents-amd64.gz' 'aptarchive/dists/unstable/main/Contents-amd64.gz'
+testequal "rootdir/var/lib/apt/lists/localhost:${APTHTTPPORT}_dists_unstable_main_Contents-amd64.gz" find rootdir/var/lib/apt/lists -name '*Contents*'
+testequal "$(readlink -f ./rootdir/var/lib/apt/lists/localhost:${APTHTTPPORT}_dists_unstable_main_Contents-amd64.gz)" aptget indextargets --format '$(FILENAME)' 'Created-By: Contents'
+testsuccess cmp "rootdir/var/lib/apt/lists/localhost:${APTHTTPPORT}_dists_unstable_main_Contents-amd64.gz" 'aptarchive/dists/unstable/main/Contents-amd64.gz'
rm -f rootdir/etc/apt/apt.conf.d/content-target.conf
-testequal "'http://localhost:8080/dists/unstable/InRelease' localhost:8080_dists_unstable_InRelease 0
-'http://localhost:8080/dists/unstable/main/source/Sources.xz' localhost:8080_dists_unstable_main_source_Sources 0
-'http://localhost:8080/dists/unstable/main/binary-amd64/Packages.xz' localhost:8080_dists_unstable_main_binary-amd64_Packages 0
-'http://localhost:8080/dists/unstable/main/i18n/Translation-en.xz' localhost:8080_dists_unstable_main_i18n_Translation-en 0 " aptget update --print-uris
+testequal "'http://localhost:${APTHTTPPORT}/dists/unstable/InRelease' localhost:${APTHTTPPORT}_dists_unstable_InRelease 0
+'http://localhost:${APTHTTPPORT}/dists/unstable/main/source/Sources.xz' localhost:${APTHTTPPORT}_dists_unstable_main_source_Sources 0
+'http://localhost:${APTHTTPPORT}/dists/unstable/main/binary-amd64/Packages.xz' localhost:${APTHTTPPORT}_dists_unstable_main_binary-amd64_Packages 0
+'http://localhost:${APTHTTPPORT}/dists/unstable/main/i18n/Translation-en.xz' localhost:${APTHTTPPORT}_dists_unstable_main_i18n_Translation-en 0 " aptget update --print-uris
-testsuccessequal "Hit:1 http://localhost:8080 unstable InRelease
+testsuccessequal "Hit:1 http://localhost:${APTHTTPPORT} unstable InRelease
Reading package lists..." aptget update
testempty find rootdir/var/lib/apt/lists -name '*Contents*'
msgtest 'download progress works via' 'http'
exec 3> apt-progress.log
-testsuccess --nomsg apthelper download-file "http://localhost:8080/$TESTFILE" ./downloaded/http-$TESTFILE $OPT -o Acquire::http::Dl-Limit=800
+testsuccess --nomsg apthelper download-file "http://localhost:${APTHTTPPORT}/$TESTFILE" ./downloaded/http-$TESTFILE $OPT -o Acquire::http::Dl-Limit=800
assertprogress apt-progress.log
msgtest 'download progress works via' 'https'
exec 3> apt-progress.log
-testsuccess --nomsg apthelper download-file "https://localhost:4433/$TESTFILE" ./downloaded/https-$TESTFILE $OPT -o Acquire::https::Dl-Limit=800
+testsuccess --nomsg apthelper download-file "https://localhost:${APTHTTPSPORT}/$TESTFILE" ./downloaded/https-$TESTFILE $OPT -o Acquire::https::Dl-Limit=800
assertprogress apt-progress.log
# cleanup
testsuccessequal "'http://changelogs.ubuntu.com/changelogs/pool/main/f/foo/foo_1.0/changelog' foo.changelog
'http://changelogs.ubuntu.com/changelogs/pool/main/libb/libbar/libbar_1.0/changelog' libbar.changelog" aptget changelog foo libbar --print-uris
-testsuccessequal "'http://localhost:8080/main/f/foo/foo_1.0.changelog' foo.changelog
-'http://localhost:8080/main/libb/libbar/libbar_1.0.changelog' libbar.changelog" aptget changelog foo libbar --print-uris -o Acquire::Changelogs::URI::Label::Debian='http://localhost:8080/CHANGEPATH.changelog'
+testsuccessequal "'http://localhost:${APTHTTPPORT}/main/f/foo/foo_1.0.changelog' foo.changelog
+'http://localhost:${APTHTTPPORT}/main/libb/libbar/libbar_1.0.changelog' libbar.changelog" aptget changelog foo libbar --print-uris -o Acquire::Changelogs::URI::Label::Debian="http://localhost:${APTHTTPPORT}/CHANGEPATH.changelog"
sed -i '/^Origin: / a\
Changelogs: http://example.org/CHANGEPATH-changelog' $(find rootdir/var/lib/apt/lists -name '*Release')
rm -f rootdir/var/cache/apt/*.bin
testsuccessequal "'http://example.org/main/f/foo/foo_1.0-changelog' foo.changelog
-'http://example.org/main/libb/libbar/libbar_1.0-changelog' libbar.changelog" aptget changelog foo libbar --print-uris -o Acquire::Changelogs::URI::Label::Debian='http://localhost:8080/CHANGEPATH.changelog'
+'http://example.org/main/libb/libbar/libbar_1.0-changelog' libbar.changelog" aptget changelog foo libbar --print-uris -o Acquire::Changelogs::URI::Label::Debian="http://localhost:${APTHTTPPORT}/CHANGEPATH.changelog"
-testsuccessequal "'http://localhost:8080/main/f/foo/foo_1.0.changelog' foo.changelog
-'http://localhost:8080/main/libb/libbar/libbar_1.0.changelog' libbar.changelog" aptget changelog foo libbar --print-uris -o Acquire::Changelogs::URI::Override::Label::Debian='http://localhost:8080/CHANGEPATH.changelog'
+testsuccessequal "'http://localhost:${APTHTTPPORT}/main/f/foo/foo_1.0.changelog' foo.changelog
+'http://localhost:${APTHTTPPORT}/main/libb/libbar/libbar_1.0.changelog' libbar.changelog" aptget changelog foo libbar --print-uris -o Acquire::Changelogs::URI::Override::Label::Debian="http://localhost:${APTHTTPPORT}/CHANGEPATH.changelog"
releasechanger 'Changelogs' 'no'
if [ "$(id -u)" = '0' ]; then
sed -i '/^Changelogs: / d' $(find rootdir/var/lib/apt/lists -name '*Release')
releasechanger 'Label' 'Testcases'
-echo 'Acquire::Changelogs::URI::Label::Testcases "http://localhost:8080/CHANGEPATH/change.txt";' > rootdir/etc/apt/apt.conf.d/changelog.conf
-testsuccessequal "'http://localhost:8080/main/f/foo/foo_1.0/change.txt' foo.changelog
-'http://localhost:8080/main/libb/libbar/libbar_1.0/change.txt' libbar.changelog" aptget changelog foo libbar --print-uris
+echo "Acquire::Changelogs::URI::Label::Testcases \"http://localhost:${APTHTTPPORT}/CHANGEPATH/change.txt\";" > rootdir/etc/apt/apt.conf.d/changelog.conf
+testsuccessequal "'http://localhost:${APTHTTPPORT}/main/f/foo/foo_1.0/change.txt' foo.changelog
+'http://localhost:${APTHTTPPORT}/main/libb/libbar/libbar_1.0/change.txt' libbar.changelog" aptget changelog foo libbar --print-uris
-echo 'Acquire::Changelogs::URI::Label::Testcases "http://localhost:8080/pool/CHANGEPATH/changelog";' > rootdir/etc/apt/apt.conf.d/changelog.conf
-testsuccessequal "'http://localhost:8080/pool/main/f/foo/foo_1.0/changelog' foo.changelog" aptget changelog foo --print-uris
+echo "Acquire::Changelogs::URI::Label::Testcases \"http://localhost:${APTHTTPPORT}/pool/CHANGEPATH/changelog\";" > rootdir/etc/apt/apt.conf.d/changelog.conf
+testsuccessequal "'http://localhost:${APTHTTPPORT}/pool/main/f/foo/foo_1.0/changelog' foo.changelog" aptget changelog foo --print-uris
testsuccess aptget changelog foo -qq
rm -f libbar.changelog foo.changelog
# as such bogus, but can happen with multiple binaries from the same source
-testsuccessequal "'http://localhost:8080/pool/main/f/foo/foo_1.0/changelog' foo.changelog
-'http://localhost:8080/pool/main/f/foo/foo_1.0/changelog' foo.changelog" aptget changelog foo foo --print-uris
+testsuccessequal "'http://localhost:${APTHTTPPORT}/pool/main/f/foo/foo_1.0/changelog' foo.changelog
+'http://localhost:${APTHTTPPORT}/pool/main/f/foo/foo_1.0/changelog' foo.changelog" aptget changelog foo foo --print-uris
testsuccess aptget changelog foo foo -qq
testfileequal '../rootdir/tmp/testsuccess.output' "$(cat ../aptarchive/pool/main/f/foo/foo_1.0/changelog)
$(cat ../aptarchive/pool/main/f/foo/foo_1.0/changelog)"
# no CHANGEPATH in the URI
testequal 'E: Failed to fetch changelog:/foo.changelog Changelog unavailable for foo=1.0
-' aptget changelog foo -qq -d -o Acquire::Changelogs::URI::Label::Testcases='http://localhost:8080/change.txt'
+' aptget changelog foo -qq -d -o Acquire::Changelogs::URI::Label::Testcases="http://localhost:${APTHTTPPORT}/change.txt"
testfailure test -e foo.changelog
-testequal 'E: Failed to fetch http://localhost:8080/does/not/exist/main/f/foo/foo_1.0/change.txt Changelog unavailable for foo=1.0 (404 Not Found)
-' aptget changelog foo -qq -d -o Acquire::Changelogs::URI::Label::Testcases='http://localhost:8080/does/not/exist/CHANGEPATH/change.txt'
+testequal "E: Failed to fetch http://localhost:${APTHTTPPORT}/does/not/exist/main/f/foo/foo_1.0/change.txt Changelog unavailable for foo=1.0 (404 Not Found)
+" aptget changelog foo -qq -d -o Acquire::Changelogs::URI::Label::Testcases="http://localhost:${APTHTTPPORT}/does/not/exist/CHANGEPATH/change.txt"
testfailure test -e foo.changelog
changetohttpswebserver
+echo 'foo' > aptarchive/foo
+echo 'bar' > aptarchive/foo2
+
test_apt_helper_download() {
- echo 'foo' > aptarchive/foo
- echo 'bar' > aptarchive/foo2
+ msgmsg 'Test with' "$1"
msgtest 'apt-file download-file' 'md5sum'
- testsuccess --nomsg apthelper download-file http://localhost:8080/foo ./downloaded/foo2 MD5Sum:d3b07384d113edec49eaa6238ad5ff00
+ testsuccess --nomsg apthelper download-file "${1}/foo" './downloaded/foo2' 'MD5Sum:d3b07384d113edec49eaa6238ad5ff00'
testfileequal ./downloaded/foo2 'foo'
msgtest 'apt-file download-file' 'sha1'
- testsuccess --nomsg apthelper download-file http://localhost:8080/foo ./downloaded/foo1 SHA1:f1d2d2f924e986ac86fdf7b36c94bcdf32beec15
+ testsuccess --nomsg apthelper download-file "${1}/foo" './downloaded/foo1' 'SHA1:f1d2d2f924e986ac86fdf7b36c94bcdf32beec15'
testfileequal ./downloaded/foo1 'foo'
msgtest 'apt-file download-file' 'sha256'
- testsuccess --nomsg apthelper download-file http://localhost:8080/foo ./downloaded/foo3 SHA256:b5bb9d8014a0f9b1d61e21e796d78dccdf1352f23cd32812f4850b878ae4944c
+ testsuccess --nomsg apthelper download-file "${1}/foo" './downloaded/foo3' 'SHA256:b5bb9d8014a0f9b1d61e21e796d78dccdf1352f23cd32812f4850b878ae4944c'
testfileequal ./downloaded/foo3 'foo'
msgtest 'apt-file download-file' 'no-hash'
- testsuccess --nomsg apthelper download-file http://localhost:8080/foo ./downloaded/foo4
+ testsuccess --nomsg apthelper download-file "${1}/foo" './downloaded/foo4'
testfileequal ./downloaded/foo4 'foo'
msgtest 'apt-file download-file' 'wrong md5sum'
- testfailure --nomsg apthelper -qq download-file http://localhost:8080/foo ./downloaded/foo5 MD5Sum:aabbcc
- testfileequal rootdir/tmp/testfailure.output 'E: Failed to fetch http://localhost:8080/foo Hash Sum mismatch
+ testfailure --nomsg apthelper -qq download-file "${1}/foo" './downloaded/foo5' 'MD5Sum:aabbcc'
+ testfileequal rootdir/tmp/testfailure.output "E: Failed to fetch ${1}/foo Hash Sum mismatch
-E: Download Failed'
+E: Download Failed"
testfileequal ./downloaded/foo5.FAILED 'foo'
msgtest 'apt-file download-file' 'wrong sha256'
- testfailure --nomsg apthelper -qq download-file http://localhost:8080/foo ./downloaded/foo6 SHA256:aabbcc
- testfileequal rootdir/tmp/testfailure.output 'E: Failed to fetch http://localhost:8080/foo Hash Sum mismatch
+ testfailure --nomsg apthelper -qq download-file "${1}/foo" './downloaded/foo6' 'SHA256:aabbcc'
+ testfileequal rootdir/tmp/testfailure.output "E: Failed to fetch ${1}/foo Hash Sum mismatch
-E: Download Failed'
- testfileequal ./downloaded/foo6.FAILED 'foo'
+E: Download Failed"
+ testfileequal './downloaded/foo6.FAILED' 'foo'
msgtest 'apt-file download-file' 'sha256 sha1'
- testsuccess --nomsg apthelper download-file http://localhost:8080/foo ./downloaded/foo8 SHA256:b5bb9d8014a0f9b1d61e21e796d78dccdf1352f23cd32812f4850b878ae4944c http://localhost:8080/foo2 ./downloaded/foo7 SHA1:e242ed3bffccdf271b7fbaf34ed72d089537b42f
- testfileequal ./downloaded/foo8 'foo'
- testfileequal ./downloaded/foo7 'bar'
+ testsuccess --nomsg apthelper download-file "${1}/foo" './downloaded/foo8' 'SHA256:b5bb9d8014a0f9b1d61e21e796d78dccdf1352f23cd32812f4850b878ae4944c' \
+ "${1}/foo2" './downloaded/foo7' 'SHA1:e242ed3bffccdf271b7fbaf34ed72d089537b42f'
+ testfileequal './downloaded/foo8' 'foo'
+ testfileequal './downloaded/foo7' 'bar'
msgtest 'apt-file download-file' 'md5sum sha1'
- testsuccess --nomsg apthelper download-file http://localhost:8080/foo ./downloaded/foo9 MD5Sum:d3b07384d113edec49eaa6238ad5ff00 http://localhost:8080/foo2 ./downloaded/foo10 SHA1:e242ed3bffccdf271b7fbaf34ed72d089537b42f
- testfileequal ./downloaded/foo9 'foo'
- testfileequal ./downloaded/foo10 'bar'
+ testsuccess --nomsg apthelper download-file "${1}/foo" './downloaded/foo9' 'MD5Sum:d3b07384d113edec49eaa6238ad5ff00' \
+ "${1}/foo2" './downloaded/foo10' 'SHA1:e242ed3bffccdf271b7fbaf34ed72d089537b42f'
+ testfileequal './downloaded/foo9' 'foo'
+ testfileequal './downloaded/foo10' 'bar'
}
test_apt_helper_detect_proxy() {
testsuccessequal "Using proxy 'https://https-proxy' for URL 'https://ssl.example.com/'" apthelper auto-detect-proxy https://ssl.example.com
}
-test_apt_helper_download
+test_apt_helper_download "http://localhost:${APTHTTPPORT}"
+test_apt_helper_download "https://localhost:${APTHTTPSPORT}"
test_apt_helper_detect_proxy
# test failure modes
testfailureequal 'E: Invalid operation download' apthelper download
testfailureequal 'E: Must specify at least one pair url/filename' apthelper download-file
-testfailureequal 'E: Must specify at least one pair url/filename' apthelper download-file http://example.org/
+testfailureequal 'E: Must specify at least one pair url/filename' apthelper download-file 'http://example.org/'
testfailureequal 'E: Need one URL as argument' apthelper auto-detect-proxy
testfailureequal 'E: Must specify at least one SRV record' apthelper srv-lookup
-testfailureequal 'E: GetSrvRec failed for localhost' apthelper srv-lookup localhost
-testfailureequal 'E: GetSrvRec failed for localhost:8080' apthelper srv-lookup localhost:8080
+testfailureequal 'E: GetSrvRec failed for localhost' apthelper srv-lookup 'localhost'
+testfailureequal "E: GetSrvRec failed for localhost:${APTHTTPPORT}" apthelper srv-lookup "localhost:${APTHTTPPORT}"
+testfailureequal "E: GetSrvRec failed for localhost:${APTHTTPSPORT}" apthelper srv-lookup "localhost:${APTHTTPSPORT}"
setupaptarchive --no-update
echo 'alright' > aptarchive/working
-changetohttpswebserver -o 'aptwebserver::redirect::replace::/redirectme/=http://localhost:8080/'
+changetohttpswebserver -o "aptwebserver::redirect::replace::/redirectme/=http://localhost:${APTHTTPPORT}/"
msgtest 'download of a file works via' 'http'
-testsuccess --nomsg downloadfile 'http://localhost:8080/working' httpfile
+testsuccess --nomsg downloadfile "http://localhost:${APTHTTPPORT}/working" httpfile
testfileequal httpfile 'alright'
msgtest 'download of a file works via' 'https'
-testsuccess --nomsg downloadfile 'https://localhost:4433/working' httpsfile
+testsuccess --nomsg downloadfile "https://localhost:${APTHTTPSPORT}/working" httpsfile
testfileequal httpsfile 'alright'
msgtest 'download of a file does not work if' 'https redirected to http'
-testfailure --nomsg downloadfile 'https://localhost:4433/redirectme/working' redirectfile
+testfailure --nomsg downloadfile "https://localhost:${APTHTTPSPORT}/redirectme/working" redirectfile
msgtest 'libcurl has forbidden access in last request to' 'http resource'
testsuccess --nomsg grep -q -E -- 'Protocol "?http"? not supported or disabled in libcurl' rootdir/tmp/testfailure.output
# setup archive-keyring
mkdir -p aptarchive/ubuntu/project
install -m0644 keys/test-archive-keyring.pub aptarchive/ubuntu/project/
-echo 'APT::Key::ArchiveKeyringURI "http://localhost:8080/ubuntu/project/test-archive-keyring.pub";' >> ./aptconfig.conf
+echo "APT::Key::ArchiveKeyringURI \"http://localhost:${APTHTTPPORT}/ubuntu/project/test-archive-keyring.pub\";" >> ./aptconfig.conf
echo 'APT::Key::Net-Update-Enabled "1";' >> ./aptconfig.conf
# test against the "real" webserver
# setup archive-keyring
mkdir -p aptarchive/ubuntu/project
install -m0644 keys/marvinparanoid.pub aptarchive/ubuntu/project/
-echo 'APT::Key::ArchiveKeyringURI "http://localhost:8080/ubuntu/project/marvinparanoid.pub";' >> ./aptconfig.conf
+echo "APT::Key::ArchiveKeyringURI \"http://localhost:${APTHTTPPORT}/ubuntu/project/marvinparanoid.pub\";" >> ./aptconfig.conf
echo 'APT::Key::Net-Update-Enabled "1";' >> ./aptconfig.conf
# test against the "real" webserver
}
changetowebserver
-methodtest 'http://localhost:8080'
+methodtest "http://localhost:${APTHTTPPORT}"
changetohttpswebserver
-methodtest 'https://localhost:4433'
+methodtest "https://localhost:${APTHTTPSPORT}"
}
msgmsg 'InRelease'
-EXPECT='Hit:1 http://localhost:8080 unstable InRelease
-Reading package lists...'
+EXPECT="Hit:1 http://localhost:${APTHTTPPORT} unstable InRelease
+Reading package lists..."
echo 'Acquire::GzipIndexes "0";' > rootdir/etc/apt/apt.conf.d/02compressindex
runtest
echo 'Acquire::GzipIndexes "1";' > rootdir/etc/apt/apt.conf.d/02compressindex
runtest
msgmsg 'Release/Release.gpg'
-EXPECT='Ign:1 http://localhost:8080 unstable InRelease
+EXPECT="Ign:1 http://localhost:${APTHTTPPORT} unstable InRelease
404 Not Found
-Hit:2 http://localhost:8080 unstable Release
-Reading package lists...'
+Hit:2 http://localhost:${APTHTTPPORT} unstable Release
+Reading package lists..."
find aptarchive -name 'InRelease' -delete
echo 'Acquire::GzipIndexes "0";' > rootdir/etc/apt/apt.conf.d/02compressindex
runtest
runtest
msgmsg 'Release only'
-EXPECT="Ign:1 http://localhost:8080 unstable InRelease
+EXPECT="Ign:1 http://localhost:${APTHTTPPORT} unstable InRelease
404 Not Found
-Hit:2 http://localhost:8080 unstable Release
-Ign:3 http://localhost:8080 unstable Release.gpg
+Hit:2 http://localhost:${APTHTTPPORT} unstable Release
+Ign:3 http://localhost:${APTHTTPPORT} unstable Release.gpg
404 Not Found
Reading package lists...
-W: The data from 'http://localhost:8080 unstable Release' is not signed. Packages from that repository can not be authenticated."
+W: The data from 'http://localhost:${APTHTTPPORT} unstable Release' is not signed. Packages from that repository can not be authenticated."
find aptarchive -name 'Release.gpg' -delete
echo 'Acquire::GzipIndexes "0";' > rootdir/etc/apt/apt.conf.d/02compressindex
runtest 'warning'
signreleasefiles
msgmsg 'expired InRelease'
-EXPECT='Hit:1 http://localhost:8080 unstable InRelease
+EXPECT="Hit:1 http://localhost:${APTHTTPPORT} unstable InRelease
Reading package lists...
-E: Release file for http://localhost:8080/dists/unstable/InRelease is expired (invalid since). Updates for this repository will not be applied.'
+E: Release file for http://localhost:${APTHTTPPORT}/dists/unstable/InRelease is expired (invalid since). Updates for this repository will not be applied."
echo 'Acquire::GzipIndexes "0";' > rootdir/etc/apt/apt.conf.d/02compressindex
runtest 'failure'
echo 'Acquire::GzipIndexes "1";' > rootdir/etc/apt/apt.conf.d/02compressindex
runtest 'failure'
msgmsg 'expired Release/Release.gpg'
-EXPECT='Ign:1 http://localhost:8080 unstable InRelease
+EXPECT="Ign:1 http://localhost:${APTHTTPPORT} unstable InRelease
404 Not Found
-Hit:2 http://localhost:8080 unstable Release
+Hit:2 http://localhost:${APTHTTPPORT} unstable Release
Reading package lists...
-E: Release file for http://localhost:8080/dists/unstable/Release is expired (invalid since). Updates for this repository will not be applied.'
+E: Release file for http://localhost:${APTHTTPPORT}/dists/unstable/Release is expired (invalid since). Updates for this repository will not be applied."
find aptarchive -name 'InRelease' -delete
echo 'Acquire::GzipIndexes "0";' > rootdir/etc/apt/apt.conf.d/02compressindex
runtest 'failure'
runtest 'failure'
msgmsg 'expired Release only'
-EXPECT="Ign:1 http://localhost:8080 unstable InRelease
+EXPECT="Ign:1 http://localhost:${APTHTTPPORT} unstable InRelease
404 Not Found
-Hit:2 http://localhost:8080 unstable Release
-Ign:3 http://localhost:8080 unstable Release.gpg
+Hit:2 http://localhost:${APTHTTPPORT} unstable Release
+Ign:3 http://localhost:${APTHTTPPORT} unstable Release.gpg
404 Not Found
Reading package lists...
-W: The data from 'http://localhost:8080 unstable Release' is not signed. Packages from that repository can not be authenticated.
-E: Release file for http://localhost:8080/dists/unstable/Release is expired (invalid since). Updates for this repository will not be applied."
+W: The data from 'http://localhost:${APTHTTPPORT} unstable Release' is not signed. Packages from that repository can not be authenticated.
+E: Release file for http://localhost:${APTHTTPPORT}/dists/unstable/Release is expired (invalid since). Updates for this repository will not be applied."
find aptarchive -name 'Release.gpg' -delete
echo 'Acquire::GzipIndexes "0";' > rootdir/etc/apt/apt.conf.d/02compressindex
runtest 'failure' 'warning'
msgmsg 'no Release at all'
-EXPECT="Ign:1 http://localhost:8080 unstable InRelease
+EXPECT="Ign:1 http://localhost:${APTHTTPPORT} unstable InRelease
404 Not Found
-Ign:2 http://localhost:8080 unstable Release
+Ign:2 http://localhost:${APTHTTPPORT} unstable Release
404 Not Found
-Ign:3 http://localhost:8080 unstable/main Sources
+Ign:3 http://localhost:${APTHTTPPORT} unstable/main Sources
404 Not Found
-Ign:4 http://localhost:8080 unstable/main amd64 Packages
+Ign:4 http://localhost:${APTHTTPPORT} unstable/main amd64 Packages
404 Not Found
-Ign:5 http://localhost:8080 unstable/main Translation-en
+Ign:5 http://localhost:${APTHTTPPORT} unstable/main Translation-en
404 Not Found
-Ign:3 http://localhost:8080 unstable/main Sources
+Ign:3 http://localhost:${APTHTTPPORT} unstable/main Sources
404 Not Found
-Ign:4 http://localhost:8080 unstable/main amd64 Packages
+Ign:4 http://localhost:${APTHTTPPORT} unstable/main amd64 Packages
404 Not Found
-Ign:5 http://localhost:8080 unstable/main Translation-en
+Ign:5 http://localhost:${APTHTTPPORT} unstable/main Translation-en
404 Not Found
-Ign:3 http://localhost:8080 unstable/main Sources
+Ign:3 http://localhost:${APTHTTPPORT} unstable/main Sources
404 Not Found
-Ign:4 http://localhost:8080 unstable/main amd64 Packages
+Ign:4 http://localhost:${APTHTTPPORT} unstable/main amd64 Packages
404 Not Found
-Ign:5 http://localhost:8080 unstable/main Translation-en
+Ign:5 http://localhost:${APTHTTPPORT} unstable/main Translation-en
404 Not Found
-Hit:3 http://localhost:8080 unstable/main Sources
-Hit:4 http://localhost:8080 unstable/main amd64 Packages
-Hit:5 http://localhost:8080 unstable/main Translation-en
+Hit:3 http://localhost:${APTHTTPPORT} unstable/main Sources
+Hit:4 http://localhost:${APTHTTPPORT} unstable/main amd64 Packages
+Hit:5 http://localhost:${APTHTTPPORT} unstable/main Translation-en
Reading package lists...
-W: The repository 'http://localhost:8080 unstable Release' does not have a Release file. This is deprecated, please contact the owner of the repository."
+W: The repository 'http://localhost:${APTHTTPPORT} unstable Release' does not have a Release file. This is deprecated, please contact the owner of the repository."
find aptarchive -name '*Release*' -delete
echo 'Acquire::GzipIndexes "0";
Acquire::PDiffs "0";' > rootdir/etc/apt/apt.conf.d/02compressindex
}
changetowebserver
-methodtest 'http://localhost:8080'
+methodtest "http://localhost:${APTHTTPPORT}"
changetohttpswebserver
-methodtest 'https://localhost:4433'
+methodtest "https://localhost:${APTHTTPSPORT}"
aptarchive/dists/unstable/main/binary-i386/
# ensure this raises an error
-testfailuremsg "W: Failed to fetch copy:$(readlink -f ./rootdir)/var/lib/apt/lists/localhost:8080_dists_unstable_main_binary-i386_Packages Hash Sum mismatch
+testfailuremsg "W: Failed to fetch copy:$(readlink -f ./rootdir)/var/lib/apt/lists/localhost:${APTHTTPPORT}_dists_unstable_main_binary-i386_Packages Hash Sum mismatch
E: Some index files failed to download. They have been ignored, or old ones used instead." aptget update -o Debug::pkgAcquire::Worker=1 -o Debug::Acquire::http=1
testfileequal lists.before "$(listcurrentlistsdirectory)"
}
msgmsg 'server basic auth'
-rewritesourceslist 'http://localhost:8080'
-runtest 'http://localhost:8080'
-rewritesourceslist 'https://localhost:4433'
-runtest 'https://localhost:4433'
-rewritesourceslist 'http://localhost:8080'
+rewritesourceslist "http://localhost:${APTHTTPPORT}"
+runtest "http://localhost:${APTHTTPPORT}"
+rewritesourceslist "https://localhost:${APTHTTPSPORT}"
+runtest "https://localhost:${APTHTTPSPORT}"
+rewritesourceslist "http://localhost:${APTHTTPPORT}"
msgmsg 'proxy to server basic auth'
webserverconfig 'aptwebserver::request::absolute' 'uri'
-export http_proxy='http://localhost:8080'
-runtest 'http://localhost:8080'
+export http_proxy="http://localhost:${APTHTTPPORT}"
+runtest "http://localhost:${APTHTTPPORT}"
unset http_proxy
msgmsg 'proxy basic auth to server basic auth'
webserverconfig 'aptwebserver::proxy-authorization' "$(printf 'moon:deer2' | base64)"
-export http_proxy='http://moon:deer2@localhost:8080'
-runtest 'http://localhost:8080'
+export http_proxy="http://moon:deer2@localhost:${APTHTTPPORT}"
+runtest "http://localhost:${APTHTTPPORT}"
msgmsg 'proxy basic auth to server'
authfile ''
webserverconfig 'aptwebserver::authorization' ''
-testauthsuccess 'http://localhost:8080'
+testauthsuccess "http://localhost:${APTHTTPPORT}"
forcecompressor "$1"
createemptyarchive 'Packages'
- testaptgetupdate "Get:2 http://localhost:8080 Packages []
+ testaptgetupdate "Get:2 http://localhost:${APTHTTPPORT} Packages []
Reading package lists..." "empty archive Packages.$COMPRESS over http"
createemptyfile 'Packages'
#FIXME: we should response with a good error message instead
- testaptgetupdate "Get:2 http://localhost:8080 Packages
-Err:2 http://localhost:8080 Packages
+ testaptgetupdate "Get:2 http://localhost:${APTHTTPPORT} Packages
+Err:2 http://localhost:${APTHTTPPORT} Packages
Empty files can't be valid archives
Reading package lists...
-W: Failed to fetch ${COMPRESSOR}:$(readlink -f rootdir/var/lib/apt/lists/partial/localhost:8080_Packages.${COMPRESS}) Empty files can't be valid archives
+W: Failed to fetch ${COMPRESSOR}:$(readlink -f rootdir/var/lib/apt/lists/partial/localhost:${APTHTTPPORT}_Packages.${COMPRESS}) Empty files can't be valid archives
E: Some index files failed to download. They have been ignored, or old ones used instead." "empty file Packages.$COMPRESS over http"
}
testsuccess --nomsg aptget install unrelated --download-only -y
}
-testrun 'http://localhost:8080'
+testrun "http://localhost:${APTHTTPPORT}"
rm -rf rootdir/var/lib/apt/lists rootdir/var/cache/apt/archives
changetohttpswebserver
-testrun 'https://localhost:4433'
+testrun "https://localhost:${APTHTTPSPORT}"
rm -rf rootdir/var/lib/apt/lists
mkdir -p rootdir/var/lib/apt/lists
-touch rootdir/var/lib/apt/lists/localhost:8080_dists_unstable_main_i18n_Translation-ast_DE
+touch rootdir/var/lib/apt/lists/localhost:${APTHTTPPORT}_dists_unstable_main_i18n_Translation-ast_DE
msgtest 'Download of builtin files' 'without Index'
testwarning --nomsg aptget update
rm -rf rootdir/var/lib/apt/lists
mkdir -p rootdir/var/lib/apt/lists
-touch rootdir/var/lib/apt/lists/localhost:8080_dists_unstable_main_i18n_Translation-ast_DE
+touch rootdir/var/lib/apt/lists/localhost:${APTHTTPPORT}_dists_unstable_main_i18n_Translation-ast_DE
msgtest 'Download of nothing (even builtin) if none is forced' 'without Index'
testwarning --nomsg aptget update -o Acquire::Languages=none
msgtest 'Check that absolute paths are' 'not accepted'
testfailure --nomsg aptget update --allow-insecure-repositories
-echo 'Acquire::http::Proxy "http://localhost:8080";' > rootdir/etc/apt/apt.conf.d/99proxy
+echo "Acquire::http::Proxy \"http://localhost:${APTHTTPPORT}\";" > rootdir/etc/apt/apt.conf.d/99proxy
msgtest 'Check that requests to proxies are' 'absolute uris'
testsuccess --nomsg aptget update
# setup http redirecting to https
getlabelfromsuite() { echo 'Testcases'; }
setupaptarchive --no-update
-changetowebserver -o 'aptwebserver::redirect::replace::/redirectme/=https://localhost:4433/' \
- -o 'aptwebserver::redirect::replace::/downgrademe/=http://localhost:8080/' \
- -o 'aptwebserver::support::http=false'
-changetohttpswebserver
-sed -i -e 's#:4433/#:8080/redirectme#' -e 's# https:# http:#' rootdir/etc/apt/sources.list.d/*
+changetohttpswebserver -o 'aptwebserver::support::http=false'
+webserverconfig 'aptwebserver::redirect::replace::/downgrademe/' "http://localhost:${APTHTTPPORT}/"
+webserverconfig 'aptwebserver::redirect::replace::/redirectme/' "https://localhost:${APTHTTPSPORT}/"
+sed -i -e "s#:${APTHTTPSPORT}/#:${APTHTTPPORT}/redirectme#" -e 's# https:# http:#' rootdir/etc/apt/sources.list.d/*
testsuccess aptget update -o Debug::Acquire::http=1 -o Debug::Acquire::https=1 -o Debug::pkgAcquire::Worker=1
msgtest 'Test that the webserver does not answer' 'http requests'
-downloadfile 'http://localhost:8080/pool/main/a/apt/apt_1.0/changelog' changelog >/dev/null 2>&1 && msgfail || msgpass
+downloadfile "http://localhost:${APTHTTPPORT}/pool/main/a/apt/apt_1.0/changelog" changelog >/dev/null 2>&1 && msgfail || msgpass
-echo 'Acquire::Changelogs::URI::Label::Testcases "http://localhost:8080/redirectme/pool/CHANGEPATH/changelog";' > rootdir/etc/apt/apt.conf.d/changelog.conf
-testsuccessequal "'http://localhost:8080/redirectme/pool/main/a/apt/apt_1.0/changelog' apt.changelog" aptget changelog apt --print-uris
+echo "Acquire::Changelogs::URI::Label::Testcases \"http://localhost:${APTHTTPPORT}/redirectme/pool/CHANGEPATH/changelog\";" > rootdir/etc/apt/apt.conf.d/changelog.conf
+testsuccessequal "'http://localhost:${APTHTTPPORT}/redirectme/pool/main/a/apt/apt_1.0/changelog' apt.changelog" aptget changelog apt --print-uris
cd downloaded
testsuccess aptget changelog apt -d
# check that downgrades from https to http are not allowed
webserverconfig 'aptwebserver::support::http' 'true'
-sed -i -e 's#:8080/redirectme#:4433/downgrademe#' -e 's# http:# https:#' rootdir/etc/apt/sources.list.d/*
+sed -i -e "s#:${APTHTTPPORT}/redirectme#:${APTHTTPSPORT}/downgrademe#" -e 's# http:# https:#' rootdir/etc/apt/sources.list.d/*
testfailure aptget update --allow-insecure-repositories
testdownload 'non-existent file via redirect fails' 'testfailure' "$1/redirectme/failing"
}
-runtest 'http://localhost:8080'
-runtest 'https://localhost:4433'
+runtest "http://localhost:${APTHTTPPORT}"
+runtest "https://localhost:${APTHTTPSPORT}"
TARGET=./downloaded/testfile-downloaded
dd if=/dev/zero of=$TARGET bs=99k count=1 2>/dev/null
-if ! downloadfile http://localhost:8080/testfile "$TARGET" > "$DOWNLOADLOG"; then
+if ! downloadfile http://localhost:${APTHTTPPORT}/testfile "$TARGET" > "$DOWNLOADLOG"; then
cat >&2 "$DOWNLOADLOG"
msgfail
else
setupaptarchive
changetowebserver
-ARCHIVE='http://localhost:8080'
+ARCHIVE="http://localhost:${APTHTTPPORT}"
msgtest 'Initial apt-get update should work with' 'InRelease'
testsuccess --nomsg aptget update
# part of the InRelease
listcurrentlistsdirectory | sed '/_InRelease/ d' > listsdir.lst
msgtest 'apt-get update should ignore unsigned data in the' 'InRelease'
-testsuccessequal "Get:1 http://localhost:8080 stable InRelease [$(stat -c%s aptarchive/dists/stable/InRelease) B]
+testsuccessequal "Get:1 http://localhost:${APTHTTPPORT} stable InRelease [$(stat -c%s aptarchive/dists/stable/InRelease) B]
Reading package lists..." --nomsg aptget update
testfileequal './listsdir.lst' "$(listcurrentlistsdirectory | sed '/_InRelease/ d')"
buildsimplenativepackage 'unrelated' 'all' '0.5~squeeze1' 'unstable'
setupaptarchive --no-update
-changetowebserver -o 'aptwebserver::redirect::replace::/redirectme/=http://0.0.0.0:8080/'
-rewritesourceslist 'http://localhost:8080/redirectme'
+changetowebserver
+webserverconfig 'aptwebserver::redirect::replace::/redirectme/' "http://0.0.0.0:${APTHTTPPORT}/"
+rewritesourceslist "http://localhost:${APTHTTPPORT}/redirectme"
-testsuccessequal "Get:1 http://0.0.0.0:8080 unstable InRelease [$(stat -c %s aptarchive/dists/unstable/InRelease) B]
-Get:2 http://0.0.0.0:8080 unstable/main Sources [$(stat -c %s aptarchive/dists/unstable/main/source/Sources.gz) B]
-Get:3 http://0.0.0.0:8080 unstable/main amd64 Packages [$(stat -c %s aptarchive/dists/unstable/main/binary-amd64/Packages.gz) B]
-Get:4 http://0.0.0.0:8080 unstable/main Translation-en [$(stat -c %s aptarchive/dists/unstable/main/i18n/Translation-en.gz) B]
+testsuccessequal "Get:1 http://0.0.0.0:${APTHTTPPORT} unstable InRelease [$(stat -c %s aptarchive/dists/unstable/InRelease) B]
+Get:2 http://0.0.0.0:${APTHTTPPORT} unstable/main Sources [$(stat -c %s aptarchive/dists/unstable/main/source/Sources.gz) B]
+Get:3 http://0.0.0.0:${APTHTTPPORT} unstable/main amd64 Packages [$(stat -c %s aptarchive/dists/unstable/main/binary-amd64/Packages.gz) B]
+Get:4 http://0.0.0.0:${APTHTTPPORT} unstable/main Translation-en [$(stat -c %s aptarchive/dists/unstable/main/i18n/Translation-en.gz) B]
Reading package lists..." aptget update
-testsuccessequal 'Hit:1 http://0.0.0.0:8080 unstable InRelease
-Reading package lists...' aptget update
+testsuccessequal "Hit:1 http://0.0.0.0:${APTHTTPPORT} unstable InRelease
+Reading package lists..." aptget update
testrun "$1"
}
-serverconfigs 'http://localhost:8080'
+serverconfigs "http://localhost:${APTHTTPPORT}"
changetohttpswebserver
-serverconfigs 'https://localhost:4433'
+serverconfigs "https://localhost:${APTHTTPSPORT}"
}
installaptold() {
- testsuccessequal 'Reading package lists...
+ testsuccessequal "Reading package lists...
Building dependency tree...
Suggested packages:
aptitude | synaptic | wajig dpkg-dev apt-doc bzip2 lzma python-apt
apt
0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
After this operation, 5370 kB of additional disk space will be used.
-Get:1 http://localhost:8080 apt 0.7.25.3
-Download complete and in download only mode' aptget install apt -dy
+Get:1 http://localhost:${APTHTTPPORT} apt 0.7.25.3
+Download complete and in download only mode" aptget install apt -dy
}
installaptnew() {
- testsuccessequal 'Reading package lists...
+ testsuccessequal "Reading package lists...
Building dependency tree...
Suggested packages:
aptitude | synaptic | wajig dpkg-dev apt-doc bzip2 lzma python-apt
apt
0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
After this operation, 5808 kB of additional disk space will be used.
-Get:1 http://localhost:8080 apt 0.8.0~pre1
-Download complete and in download only mode' aptget install apt -dy
+Get:1 http://localhost:${APTHTTPPORT} apt 0.8.0~pre1
+Download complete and in download only mode" aptget install apt -dy
}
failaptold() {
testsuccessequal "Reading package lists...
Building dependency tree...
Need to get 6 B of source archives.
-Get:1 http://localhost:8080 $1 1.0 (dsc) [3 B]
-Get:2 http://localhost:8080 $1 1.0 (tar) [3 B]
+Get:1 http://localhost:${APTHTTPPORT} $1 1.0 (dsc) [3 B]
+Get:2 http://localhost:${APTHTTPPORT} $1 1.0 (tar) [3 B]
Download complete and in download only mode" aptget source -d "$@"
msgtest 'Files were successfully downloaded for' "$1"
testsuccess --nomsg test -e ${1}_1.0.dsc -a -e ${1}_1.0.tar.gz
testfailureequal "Reading package lists...
Building dependency tree...
Need to get 6 B of source archives.
-Get:1 http://localhost:8080 $1 1.0 (dsc) [3 B]
-Err:1 http://localhost:8080 $1 1.0 (dsc)
+Get:1 http://localhost:${APTHTTPPORT} $1 1.0 (dsc) [3 B]
+Err:1 http://localhost:${APTHTTPPORT} $1 1.0 (dsc)
Hash Sum mismatch
-Get:2 http://localhost:8080 $1 1.0 (tar) [3 B]
-Err:2 http://localhost:8080 $1 1.0 (tar)
+Get:2 http://localhost:${APTHTTPPORT} $1 1.0 (tar) [3 B]
+Err:2 http://localhost:${APTHTTPPORT} $1 1.0 (tar)
Hash Sum mismatch
-E: Failed to fetch http://localhost:8080/${1}_1.0.dsc Hash Sum mismatch
+E: Failed to fetch http://localhost:${APTHTTPPORT}/${1}_1.0.dsc Hash Sum mismatch
-E: Failed to fetch http://localhost:8080/${1}_1.0.tar.gz Hash Sum mismatch
+E: Failed to fetch http://localhost:${APTHTTPPORT}/${1}_1.0.tar.gz Hash Sum mismatch
E: Failed to fetch some archives." aptget source -d "$@"
msgtest 'Files were not download as they have hashsum mismatches for' "$1"
testsuccessequal "Reading package lists...
Building dependency tree...
Need to get 6 B of source archives.
-Get:1 http://localhost:8080 $1 1.0 (dsc) [3 B]
-Get:2 http://localhost:8080 $1 1.0 (tar) [3 B]
+Get:1 http://localhost:${APTHTTPPORT} $1 1.0 (dsc) [3 B]
+Get:2 http://localhost:${APTHTTPPORT} $1 1.0 (tar) [3 B]
Download complete and in download only mode" aptget source --allow-unauthenticated -d "$@" -o Acquire::ForceHash=ROT26
msgtest 'Files were downloaded unauthenticated as user allowed it' "$1"
testsuccess --nomsg test -e ${1}_1.0.dsc -a -e ${1}_1.0.tar.gz
# deal with cases in which we haven't for all files the same checksum type
# mostly pathologic as this shouldn't happen, but just to be sure
testok pkg-mixed-ok
-testfailureequal 'Reading package lists...
+testfailureequal "Reading package lists...
Building dependency tree...
Need to get 6 B of source archives.
-Get:1 http://localhost:8080 pkg-mixed-sha1-bad 1.0 (tar) [3 B]
-Get:2 http://localhost:8080 pkg-mixed-sha1-bad 1.0 (dsc) [3 B]
-Err:2 http://localhost:8080 pkg-mixed-sha1-bad 1.0 (dsc)
+Get:1 http://localhost:${APTHTTPPORT} pkg-mixed-sha1-bad 1.0 (tar) [3 B]
+Get:2 http://localhost:${APTHTTPPORT} pkg-mixed-sha1-bad 1.0 (dsc) [3 B]
+Err:2 http://localhost:${APTHTTPPORT} pkg-mixed-sha1-bad 1.0 (dsc)
Hash Sum mismatch
-E: Failed to fetch http://localhost:8080/pkg-mixed-sha1-bad_1.0.dsc Hash Sum mismatch
+E: Failed to fetch http://localhost:${APTHTTPPORT}/pkg-mixed-sha1-bad_1.0.dsc Hash Sum mismatch
-E: Failed to fetch some archives.' aptget source -d pkg-mixed-sha1-bad
+E: Failed to fetch some archives." aptget source -d pkg-mixed-sha1-bad
msgtest 'Only tar file is downloaded as the dsc has hashsum mismatch' 'pkg-mixed-sha1-bad'
testsuccess --nomsg test ! -e pkg-mixed-sha1-bad_1.0.dsc -a -e pkg-mixed-sha1-bad_1.0.tar.gz
-testfailureequal 'Reading package lists...
+testfailureequal "Reading package lists...
Building dependency tree...
Need to get 6 B of source archives.
-Get:1 http://localhost:8080 pkg-mixed-sha2-bad 1.0 (tar) [3 B]
-Err:1 http://localhost:8080 pkg-mixed-sha2-bad 1.0 (tar)
+Get:1 http://localhost:${APTHTTPPORT} pkg-mixed-sha2-bad 1.0 (tar) [3 B]
+Err:1 http://localhost:${APTHTTPPORT} pkg-mixed-sha2-bad 1.0 (tar)
Hash Sum mismatch
-Get:2 http://localhost:8080 pkg-mixed-sha2-bad 1.0 (dsc) [3 B]
-E: Failed to fetch http://localhost:8080/pkg-mixed-sha2-bad_1.0.tar.gz Hash Sum mismatch
+Get:2 http://localhost:${APTHTTPPORT} pkg-mixed-sha2-bad 1.0 (dsc) [3 B]
+E: Failed to fetch http://localhost:${APTHTTPPORT}/pkg-mixed-sha2-bad_1.0.tar.gz Hash Sum mismatch
-E: Failed to fetch some archives.' aptget source -d pkg-mixed-sha2-bad
+E: Failed to fetch some archives." aptget source -d pkg-mixed-sha2-bad
msgtest 'Only dsc file is downloaded as the tar has hashsum mismatch' 'pkg-mixed-sha2-bad'
testsuccess --nomsg test -e pkg-mixed-sha2-bad_1.0.dsc -a ! -e pkg-mixed-sha2-bad_1.0.tar.gz
changetowebserver -o 'aptwebserver::overwrite::.*::filename=/knights'
msgtest 'Acquire test file from the webserver to check' 'overwrite'
-if downloadfile http://localhost:8080/holygrail ./knights-talking >/dev/null; then
+if downloadfile http://localhost:${APTHTTPPORT}/holygrail ./knights-talking >/dev/null; then
msgpass
else
msgfail
# and again with pre-existing files with "valid data" which should remain
for f in Release Release.gpg main_binary-amd64_Packages main_source_Sources; do
- echo 'peng neee-wom' > "$LISTS/localhost:8080_dists_stable_${f}"
- chmod 644 "$LISTS/localhost:8080_dists_stable_${f}"
+ echo 'peng neee-wom' > "$LISTS/localhost:${APTHTTPPORT}_dists_stable_${f}"
+ chmod 644 "$LISTS/localhost:${APTHTTPPORT}_dists_stable_${f}"
done
testfailure aptget update
ensure_n_canary_strings_in_dir "$LISTS" 'ni ni ni' 0
# and now with a pre-existing InRelease file
-echo 'peng neee-wom' > "$LISTS/localhost:8080_dists_stable_InRelease"
-chmod 644 "$LISTS/localhost:8080_dists_stable_InRelease"
-rm -f "$LISTS/localhost:8080_dists_stable_Release" "$LISTS/localhost:8080_dists_stable_Release.gpg"
+echo 'peng neee-wom' > "$LISTS/localhost:${APTHTTPPORT}_dists_stable_InRelease"
+chmod 644 "$LISTS/localhost:${APTHTTPPORT}_dists_stable_InRelease"
+rm -f "$LISTS/localhost:${APTHTTPPORT}_dists_stable_Release" "$LISTS/localhost:${APTHTTPPORT}_dists_stable_Release.gpg"
msgtest 'excpected failure of' 'apt-get update'
testfailure aptget update
testsuccess grep '^W:.*Clearsigned file .*NOSPLIT.*' rootdir/tmp/testfailure.output
if (strncmp(uri.c_str(), "http://", 7) != 0 && strncmp(uri.c_str(), "https://", 8) != 0)
{
std::string const host = LookupTag(request, "Host");
- if (host.find(":4433") != std::string::npos)
+ unsigned int const httpsport = _config->FindI("aptwebserver::port::https", 4433);
+ std::string hosthttpsport;
+ strprintf(hosthttpsport, ":%u", httpsport);
+ if (host.find(hosthttpsport) != std::string::npos)
location.append("https://");
else
location.append("http://");
}
// deal with the request
+ unsigned int const httpsport = _config->FindI("aptwebserver::port::https", 4433);
+ std::string hosthttpsport;
+ strprintf(hosthttpsport, ":%u", httpsport);
if (_config->FindB("aptwebserver::support::http", true) == false &&
- LookupTag(*m, "Host").find(":4433") == std::string::npos)
+ LookupTag(*m, "Host").find(hosthttpsport) == std::string::npos)
{
sendError(client, 400, *m, sendContent, "HTTP disabled, all requests must be HTTPS", headers);
continue;
return 1;
}
- int const port = _config->FindI("aptwebserver::port", 8080);
+ int port = _config->FindI("aptwebserver::port", 8080);
// ensure that we accept all connections: v4 or v6
int const iponly = 0;
return 2;
}
+ if (port == 0)
+ {
+ struct sockaddr_in6 addr;
+ socklen_t addrlen = sizeof(sockaddr_in6);
+ if (getsockname(sock, (struct sockaddr*) &addr, &addrlen) != 0)
+ _error->Errno("getsockname", "Could not get chosen port number");
+ else
+ port = ntohs(addr.sin6_port);
+ }
+ std::string const portfilename = _config->Find("aptwebserver::portfile", "");
+ if (portfilename.empty() == false)
+ {
+ FileFd portfile(portfilename, FileFd::WriteOnly | FileFd::Create | FileFd::Empty);
+ std::string portcontent;
+ strprintf(portcontent, "%d", port);
+ portfile.Write(portcontent.c_str(), portcontent.size());
+ portfile.Sync();
+ }
+ _config->Set("aptwebserver::port::http", port);
+
FileFd pidfile;
if (_config->FindB("aptwebserver::fork", false) == true)
{
std::string pidcontent;
strprintf(pidcontent, "%d", child);
pidfile.Write(pidcontent.c_str(), pidcontent.size());
+ pidfile.Sync();
if (_error->PendingError() == true)
{
_error->DumpErrors(std::cerr);