Procházet zdrojové kódy

improve debug output in case downloadfile fails

Git-Dch: Ignore
David Kalnischkies před 12 roky
rodič
revize
0d58c26ad7

+ 7 - 8
cmdline/apt-helper.cc

@@ -19,6 +19,7 @@
 
 
 #include <apt-private/acqprogress.h>
 #include <apt-private/acqprogress.h>
 #include <apt-private/private-output.h>
 #include <apt-private/private-output.h>
+#include <apt-private/private-download.h>
 #include <apt-private/private-cmndline.h>
 #include <apt-private/private-cmndline.h>
 
 
 #include <iostream>
 #include <iostream>
@@ -27,7 +28,6 @@
 
 
 #include <apti18n.h>
 #include <apti18n.h>
 									/*}}}*/
 									/*}}}*/
-using namespace std;
 
 
 static bool DoDownloadFile(CommandLine &CmdL)
 static bool DoDownloadFile(CommandLine &CmdL)
 {
 {
@@ -43,23 +43,22 @@ static bool DoDownloadFile(CommandLine &CmdL)
    new pkgAcqFile(&Fetcher, download_uri, "", 0, "desc", "short-desc", 
    new pkgAcqFile(&Fetcher, download_uri, "", 0, "desc", "short-desc", 
                   "dest-dir-ignored", targetfile);
                   "dest-dir-ignored", targetfile);
    Fetcher.Run();
    Fetcher.Run();
-   if (!FileExists(targetfile))
-   {
-      _error->Error(_("Download Failed"));
-      return false;
-   }
+   bool Failed = false;
+   if (AcquireRun(Fetcher, 0, &Failed, NULL) == false || Failed == false ||
+	 FileExists(targetfile) == false)
+      return _error->Error(_("Download Failed"));
    return true;
    return true;
 }
 }
 
 
 static bool ShowHelp(CommandLine &)
 static bool ShowHelp(CommandLine &)
 {
 {
-   ioprintf(cout,_("%s %s for %s compiled on %s %s\n"),PACKAGE,PACKAGE_VERSION,
+   ioprintf(std::cout,_("%s %s for %s compiled on %s %s\n"),PACKAGE,PACKAGE_VERSION,
 	    COMMON_ARCH,__DATE__,__TIME__);
 	    COMMON_ARCH,__DATE__,__TIME__);
 
 
    if (_config->FindB("version") == true)
    if (_config->FindB("version") == true)
      return true;
      return true;
 
 
-   cout << 
+   std::cout <<
     _("Usage: apt-helper [options] command\n"
     _("Usage: apt-helper [options] command\n"
       "       apt-helper [options] download-file uri target-path\n"
       "       apt-helper [options] download-file uri target-path\n"
       "\n"
       "\n"

+ 52 - 31
test/integration/framework

@@ -863,18 +863,16 @@ signreleasefiles() {
 
 
 webserverconfig() {
 webserverconfig() {
 	msgtest "Set webserver config option '${1}' to" "$2"
 	msgtest "Set webserver config option '${1}' to" "$2"
-	downloadfile "http://localhost:8080/_config/set/${1}/${2}" '/dev/null' >/dev/null
-	local DOWNLOG='download-testfile.log'
-	rm -f "$DOWNLOG"
-	local STATUS="${TMPWORKINGDIRECTORY}/rootdir/tmp/webserverconfig.status"
-	downloadfile "http://localhost:8080/_config/find/aptwebserver::last-status-code" "$STATUS" > "$DOWNLOG"
-	if [ "$(cat "$STATUS")" = '200' ]; then
+	local DOWNLOG='rootdir/tmp/download-testfile.log'
+	local STATUS='rootdir/tmp/webserverconfig.status'
+	rm -f "$STATUS" "$DOWNLOG"
+	if downloadfile "http://localhost:8080/_config/set/${1}/${2}" "$STATUS" > "$DOWNLOG"; then
 		msgpass
 		msgpass
 	else
 	else
-		cat >&2 "$DOWNLOG"
-		msgfail "Statuscode was $(cat "$STATUS")"
+		cat "$DOWNLOG" "$STATUS"
+		msgfail
 	fi
 	fi
-	rm "$STATUS"
+	testwebserverlaststatuscode '200'
 }
 }
 
 
 rewritesourceslist() {
 rewritesourceslist() {
@@ -952,10 +950,10 @@ acquire::cdrom::autodetect 0;" > rootdir/etc/apt/apt.conf.d/00cdrom
 }
 }
 
 
 downloadfile() {
 downloadfile() {
-        PROTO="$(echo "$1" | cut -d':' -f 1)"
-        apthelper -o Acquire::https::CaInfo=${TESTDIR}/apt.pem \
-                  -o Debug::Acquire::${PROTO}=1 \
-                  download-file "$1" "$2" 2>&1
+	local PROTO="$(echo "$1" | cut -d':' -f 1 )"
+	apthelper -o Acquire::https::CaInfo=${TESTDIR}/apt.pem \
+		-o Debug::Acquire::${PROTO}=1 \
+		download-file "$1" "$2" 2>&1 || true
 	# only if the file exists the download was successful
 	# only if the file exists the download was successful
 	if [ -e "$2" ]; then
 	if [ -e "$2" ]; then
 		return 0
 		return 0
@@ -967,8 +965,8 @@ downloadfile() {
 checkdiff() {
 checkdiff() {
 	local DIFFTEXT="$(command diff -u "$@" | sed -e '/^---/ d' -e '/^+++/ d' -e '/^@@/ d')"
 	local DIFFTEXT="$(command diff -u "$@" | sed -e '/^---/ d' -e '/^+++/ d' -e '/^@@/ d')"
 	if [ -n "$DIFFTEXT" ]; then
 	if [ -n "$DIFFTEXT" ]; then
-		echo
-		echo "$DIFFTEXT"
+		echo >&2
+		echo >&2 "$DIFFTEXT"
 		return 1
 		return 1
 	else
 	else
 		return 0
 		return 0
@@ -1017,7 +1015,9 @@ testequalor2() {
 	shift 2
 	shift 2
 	msgtest "Test for equality OR of" "$*"
 	msgtest "Test for equality OR of" "$*"
 	$* >$COMPAREAGAINST 2>&1 || true
 	$* >$COMPAREAGAINST 2>&1 || true
-	if checkdiff $COMPAREFILE1 $COMPAREAGAINST 1> /dev/null || checkdiff $COMPAREFILE2 $COMPAREAGAINST 1> /dev/null; then
+	if checkdiff $COMPAREFILE1 $COMPAREAGAINST >/dev/null 2>&1 || \
+		checkdiff $COMPAREFILE2 $COMPAREAGAINST >/dev/null 2>&1
+	then
 		msgpass
 		msgpass
 	else
 	else
 		echo -n "\n${CINFO}Diff against OR 1${CNORMAL}"
 		echo -n "\n${CINFO}Diff against OR 1${CNORMAL}"
@@ -1051,24 +1051,24 @@ testnopackage() {
 	msgtest "Test for non-existent packages" "apt-cache show $*"
 	msgtest "Test for non-existent packages" "apt-cache show $*"
 	local SHOWPKG="$(aptcache show "$@" 2>&1 | grep '^Package: ')"
 	local SHOWPKG="$(aptcache show "$@" 2>&1 | grep '^Package: ')"
 	if [ -n "$SHOWPKG" ]; then
 	if [ -n "$SHOWPKG" ]; then
-		echo
-		echo "$SHOWPKG"
+		echo >&2
+		echo >&2 "$SHOWPKG"
 		msgfail
 		msgfail
-		return 1
+	else
+		msgpass
 	fi
 	fi
-	msgpass
 }
 }
 
 
 testdpkginstalled() {
 testdpkginstalled() {
 	msgtest "Test for correctly installed package(s) with" "dpkg -l $*"
 	msgtest "Test for correctly installed package(s) with" "dpkg -l $*"
 	local PKGS="$(dpkg -l "$@" 2>/dev/null | grep '^i' | wc -l)"
 	local PKGS="$(dpkg -l "$@" 2>/dev/null | grep '^i' | wc -l)"
 	if [ "$PKGS" != $# ]; then
 	if [ "$PKGS" != $# ]; then
-		echo $PKGS
-		dpkg -l "$@" | grep '^[a-z]'
+		echo >&2 $PKGS
+		dpkg -l "$@" | grep '^[a-z]' >&2
 		msgfail
 		msgfail
-		return 1
+	else
+		msgpass
 	fi
 	fi
-	msgpass
 }
 }
 
 
 testdpkgnotinstalled() {
 testdpkgnotinstalled() {
@@ -1076,11 +1076,11 @@ testdpkgnotinstalled() {
 	local PKGS="$(dpkg -l "$@" 2> /dev/null | grep '^i' | wc -l)"
 	local PKGS="$(dpkg -l "$@" 2> /dev/null | grep '^i' | wc -l)"
 	if [ "$PKGS" != 0 ]; then
 	if [ "$PKGS" != 0 ]; then
 		echo
 		echo
-		dpkg -l "$@" | grep '^[a-z]'
+		dpkg -l "$@" | grep '^[a-z]' >&2
 		msgfail
 		msgfail
-		return 1
+	else
+		msgpass
 	fi
 	fi
-	msgpass
 }
 }
 
 
 testmarkedauto() {
 testmarkedauto() {
@@ -1105,8 +1105,8 @@ testsuccess() {
 	if $@ >${OUTPUT} 2>&1; then
 	if $@ >${OUTPUT} 2>&1; then
 		msgpass
 		msgpass
 	else
 	else
-		echo
-		cat $OUTPUT
+		echo >&2
+		cat >&2 $OUTPUT
 		msgfail
 		msgfail
 	fi
 	fi
 }
 }
@@ -1119,14 +1119,35 @@ testfailure() {
 	fi
 	fi
 	local OUTPUT="${TMPWORKINGDIRECTORY}/rootdir/tmp/testfailure.output"
 	local OUTPUT="${TMPWORKINGDIRECTORY}/rootdir/tmp/testfailure.output"
 	if $@ >${OUTPUT} 2>&1; then
 	if $@ >${OUTPUT} 2>&1; then
-		echo
-		cat $OUTPUT
+		echo >&2
+		cat >&2 $OUTPUT
 		msgfail
 		msgfail
 	else
 	else
 		msgpass
 		msgpass
 	fi
 	fi
 }
 }
 
 
+testwebserverlaststatuscode() {
+	local DOWNLOG='rootdir/tmp/webserverstatus-testfile.log'
+	local STATUS='rootdir/tmp/webserverstatus-statusfile.log'
+	rm -f "$DOWNLOG" "$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
+	else
+		echo >&2
+		if [ -n "$2" ]; then
+			shift
+			echo >&2 '#### Additionally provided output files contain:'
+			cat >&2 "$@"
+		fi
+		echo >&2 '#### Download log of the status code:'
+		cat >&2 "$DOWNLOG"
+		msgfail "Status was $(cat "$STATUS")"
+	fi
+}
+
 pause() {
 pause() {
 	echo "STOPPED execution. Press enter to continue"
 	echo "STOPPED execution. Press enter to continue"
 	local IGNORE
 	local IGNORE

+ 13 - 7
test/integration/test-apt-https-no-redirect

@@ -7,18 +7,24 @@ TESTDIR=$(readlink -f $(dirname $0))
 setupenvironment
 setupenvironment
 configarchitecture "i386"
 configarchitecture "i386"
 
 
-buildsimplenativepackage 'apt' 'all' '1.0' 'stable'
+insertpackage 'stable' 'apt' 'all' '1'
 setupaptarchive --no-update
 setupaptarchive --no-update
 
 
+echo 'alright' > aptarchive/working
 changetohttpswebserver  -o 'aptwebserver::redirect::replace::/redirectme/=http://localhost:8080/'
 changetohttpswebserver  -o 'aptwebserver::redirect::replace::/redirectme/=http://localhost:8080/'
 
 
-msgtest 'normal http download works'
-downloadfile 'http://localhost:8080/pool/apt_1.0/changelog' changelog2 >/dev/null 2>/dev/null && msgpass || msgfail
+msgtest 'download of a file works via' 'http'
+downloadfile 'http://localhost:8080/working' httpfile >/dev/null 2>&1 && msgpass || msgfail
+testfileequal httpfile 'alright'
 
 
-msgtest 'normal https download works'
-downloadfile 'https://localhost:4433/pool/apt_1.0/changelog' changelog >/dev/null 2>/dev/null && msgpass || msgfail
+msgtest 'download of a file works via' 'https'
+downloadfile 'https://localhost:4433/working' httpsfile >/dev/null 2>&1 && msgpass || msgfail
+testfileequal httpsfile 'alright'
 
 
-msgtest 'redirecting https to http does not work'
-downloadfile 'https://localhost:4433/redirectme/pool/apt_1.0/changelog' changelog3 2>&1 | grep "Protocol http not supported or disabled in libcurl" > /dev/null && msgpass || msgfail
+msgtest 'download of a file does not work if' 'https redirected to http'
+downloadfile 'https://localhost:4433/redirectme/working' redirectfile >curloutput 2>&1 && msgfail || msgpass
+
+msgtest 'libcurl has forbidden access in last request to' 'http resource'
+grep -q -- 'Protocol http not supported or disabled in libcurl' curloutput && msgpass || msgfail
 
 
 
 

+ 14 - 29
test/integration/test-partial-file-support

@@ -13,17 +13,18 @@ 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"
+	rm -f "$DOWNLOADLOG"
 	msgtest "Testing download of file $2 with" "$1"
 	msgtest "Testing download of file $2 with" "$1"
-	if ! downloadfile "$2" "$3" > "$DOWNLOG"; then
-		cat >&2 "$DOWNLOG"
+	if ! downloadfile "$2" "$3" > "$DOWNLOADLOG"; then
+		cat >&2 "$DOWNLOADLOG"
 		msgfail
 		msgfail
 	else
 	else
 		msgpass
 		msgpass
 	fi
 	fi
-	cat "$DOWNLOG" | while read field hash; do
+	cat "$DOWNLOADLOG" | while read field hash; do
 		local EXPECTED
 		local EXPECTED
 		case "$field" in
 		case "$field" in
 		'MD5Sum-Hash:') EXPECTED="$(md5sum "$TESTFILE" | cut -d' ' -f 1)";;
 		'MD5Sum-Hash:') EXPECTED="$(md5sum "$TESTFILE" | cut -d' ' -f 1)";;
@@ -40,28 +41,12 @@ testdownloadfile() {
 		if [ "$EXPECTED" "$4" "$hash" ]; then
 		if [ "$EXPECTED" "$4" "$hash" ]; then
 			msgpass
 			msgpass
 		else
 		else
-			cat >&2 "$DOWNLOG"
+			cat >&2 "$DOWNLOADLOG"
 			msgfail "expected: $EXPECTED ; got: $hash"
 			msgfail "expected: $EXPECTED ; got: $hash"
 		fi
 		fi
 	done
 	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
-	else
-		cat >&2 "$DOWNLOG"
-		msgfail "Status was $(cat "$STATUS")"
-	fi
-}
-
-
 TESTFILE='aptarchive/testfile'
 TESTFILE='aptarchive/testfile'
 cp -a ${TESTDIR}/framework $TESTFILE
 cp -a ${TESTDIR}/framework $TESTFILE
 
 
@@ -70,34 +55,34 @@ testrun() {
 
 
 	copysource $TESTFILE 0 ./testfile
 	copysource $TESTFILE 0 ./testfile
 	testdownloadfile 'no data' "${1}/testfile" './testfile' '='
 	testdownloadfile 'no data' "${1}/testfile" './testfile' '='
-	testwebserverlaststatuscode '200'
+	testwebserverlaststatuscode '200' "$DOWNLOADLOG"
 
 
 	copysource $TESTFILE 20 ./testfile
 	copysource $TESTFILE 20 ./testfile
 	testdownloadfile 'valid partial data' "${1}/testfile" './testfile' '='
 	testdownloadfile 'valid partial data' "${1}/testfile" './testfile' '='
-	testwebserverlaststatuscode '206'
+	testwebserverlaststatuscode '206' "$DOWNLOADLOG"
 
 
 	copysource /dev/zero 20 ./testfile
 	copysource /dev/zero 20 ./testfile
 	testdownloadfile 'invalid partial data' "${1}/testfile" './testfile' '!='
 	testdownloadfile 'invalid partial data' "${1}/testfile" './testfile' '!='
-	testwebserverlaststatuscode '206'
+	testwebserverlaststatuscode '206' "$DOWNLOADLOG"
 
 
 	copysource $TESTFILE 1M ./testfile
 	copysource $TESTFILE 1M ./testfile
 	testdownloadfile 'completely downloaded file' "${1}/testfile" './testfile' '='
 	testdownloadfile 'completely downloaded file' "${1}/testfile" './testfile' '='
-	testwebserverlaststatuscode '416'
+	testwebserverlaststatuscode '416' "$DOWNLOADLOG"
 
 
 	copysource /dev/zero 1M ./testfile
 	copysource /dev/zero 1M ./testfile
 	testdownloadfile 'too-big partial file' "${1}/testfile" './testfile' '='
 	testdownloadfile 'too-big partial file' "${1}/testfile" './testfile' '='
-	testwebserverlaststatuscode '200'
+	testwebserverlaststatuscode '200' "$DOWNLOADLOG"
 
 
 	copysource /dev/zero 20 ./testfile
 	copysource /dev/zero 20 ./testfile
 	touch ./testfile
 	touch ./testfile
 	testdownloadfile 'old data' "${1}/testfile" './testfile' '='
 	testdownloadfile 'old data' "${1}/testfile" './testfile' '='
-	testwebserverlaststatuscode '200'
+	testwebserverlaststatuscode '200' "$DOWNLOADLOG"
 
 
 	webserverconfig 'aptwebserver::support::range' 'false'
 	webserverconfig 'aptwebserver::support::range' 'false'
 
 
 	copysource $TESTFILE 20 ./testfile
 	copysource $TESTFILE 20 ./testfile
 	testdownloadfile 'no server support' "${1}/testfile" './testfile' '='
 	testdownloadfile 'no server support' "${1}/testfile" './testfile' '='
-	testwebserverlaststatuscode '200'
+	testwebserverlaststatuscode '200' "$DOWNLOADLOG"
 }
 }
 
 
 testrun 'http://localhost:8080'
 testrun 'http://localhost:8080'