summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--apt-pkg/contrib/fileutl.cc11
-rw-r--r--apt-pkg/contrib/fileutl.h1
-rw-r--r--cmdline/apt-helper.cc12
-rw-r--r--test/integration/framework28
-rwxr-xr-xtest/integration/test-apt-helper37
-rwxr-xr-xtest/integration/test-apt-https-no-redirect5
6 files changed, 75 insertions, 19 deletions
diff --git a/apt-pkg/contrib/fileutl.cc b/apt-pkg/contrib/fileutl.cc
index 52411a762..79bcf112c 100644
--- a/apt-pkg/contrib/fileutl.cc
+++ b/apt-pkg/contrib/fileutl.cc
@@ -1841,3 +1841,14 @@ std::string GetTempDir()
return string(tmpdir);
}
+
+bool Rename(std::string From, std::string To)
+{
+ if (rename(From.c_str(),To.c_str()) != 0)
+ {
+ _error->Error(_("rename failed, %s (%s -> %s)."),strerror(errno),
+ From.c_str(),To.c_str());
+ return false;
+ }
+ return true;
+}
diff --git a/apt-pkg/contrib/fileutl.h b/apt-pkg/contrib/fileutl.h
index e752e9621..f0569b6fd 100644
--- a/apt-pkg/contrib/fileutl.h
+++ b/apt-pkg/contrib/fileutl.h
@@ -164,6 +164,7 @@ bool RealFileExists(std::string File);
bool DirectoryExists(std::string const &Path) __attrib_const;
bool CreateDirectory(std::string const &Parent, std::string const &Path);
time_t GetModificationTime(std::string const &Path);
+bool Rename(std::string From, std::string To);
std::string GetTempDir();
diff --git a/cmdline/apt-helper.cc b/cmdline/apt-helper.cc
index c1c8b2178..e3652d1ee 100644
--- a/cmdline/apt-helper.cc
+++ b/cmdline/apt-helper.cc
@@ -44,6 +44,9 @@ bool DoDownloadFile(CommandLine &CmdL)
Fetcher.Setup(&Stat);
std::string download_uri = CmdL.FileList[1];
std::string targetfile = CmdL.FileList[2];
+ HashString hash;
+ if (CmdL.FileSize() > 3)
+ hash = HashString(CmdL.FileList[3]);
new pkgAcqFile(&Fetcher, download_uri, "", 0, "desc", "short-desc",
"dest-dir-ignored", targetfile);
Fetcher.Run();
@@ -52,6 +55,15 @@ bool DoDownloadFile(CommandLine &CmdL)
_error->Error(_("Download Failed"));
return false;
}
+ if(hash.empty() == false)
+ {
+ if(hash.VerifyFile(targetfile) == false)
+ {
+ _error->Error(_("HashSum Failed"));
+ Rename(targetfile, targetfile+".failed");
+ return false;
+ }
+ }
return true;
}
diff --git a/test/integration/framework b/test/integration/framework
index 911a4d742..d9bacef83 100644
--- a/test/integration/framework
+++ b/test/integration/framework
@@ -90,18 +90,18 @@ msgdone() {
echo "${CDONE}DONE${CNORMAL}";
fi
}
-
+getaptconfig() {
+ if [ -f ./aptconfig.conf ]; then
+ echo "./aptconfig.conf"
+ elif [ -f ../aptconfig.conf ]; then
+ echo "../aptconfig.conf"
+ fi
+}
runapt() {
msgdebug "Executing: ${CCMD}$*${CDEBUG} "
local CMD="$1"
shift
- if [ -f ./aptconfig.conf ]; then
- MALLOC_PERTURB_=21 MALLOC_CHECK_=2 APT_CONFIG=aptconfig.conf LD_LIBRARY_PATH=${BUILDDIRECTORY} ${BUILDDIRECTORY}/$CMD "$@"
- elif [ -f ../aptconfig.conf ]; then
- MALLOC_PERTURB_=21 MALLOC_CHECK_=2 APT_CONFIG=../aptconfig.conf LD_LIBRARY_PATH=${BUILDDIRECTORY} ${BUILDDIRECTORY}/$CMD "$@"
- else
- MALLOC_PERTURB_=21 MALLOC_CHECK_=2 LD_LIBRARY_PATH=${BUILDDIRECTORY} ${BUILDDIRECTORY}/$CMD "$@"
- fi
+ MALLOC_PERTURB_=21 MALLOC_CHECK_=2 APT_CONFIG="$(getaptconfig)" LD_LIBRARY_PATH=${BUILDDIRECTORY} ${BUILDDIRECTORY}/$CMD "$@"
}
aptconfig() { runapt apt-config "$@"; }
aptcache() { runapt apt-cache "$@"; }
@@ -112,7 +112,7 @@ aptkey() { runapt apt-key "$@"; }
aptmark() { runapt apt-mark "$@"; }
apt() { runapt apt "$@"; }
apthelper() {
- LD_LIBRARY_PATH=${APTHELPERBINDIR} ${APTHELPERBINDIR}/apt-helper "$@";
+ APT_CONFIG="$(getaptconfig)" LD_LIBRARY_PATH=${APTHELPERBINDIR} ${APTHELPERBINDIR}/apt-helper "$@";
}
aptwebserver() {
LD_LIBRARY_PATH=${APTWEBSERVERBINDIR} ${APTWEBSERVERBINDIR}/aptwebserver "$@";
@@ -121,17 +121,11 @@ dpkg() {
command dpkg --root=${TMPWORKINGDIRECTORY}/rootdir --force-not-root --force-bad-path --log=${TMPWORKINGDIRECTORY}/rootdir/var/log/dpkg.log "$@"
}
aptitude() {
- if [ -f ./aptconfig.conf ]; then
- APT_CONFIG=aptconfig.conf LD_LIBRARY_PATH=${BUILDDIRECTORY} command aptitude "$@"
- elif [ -f ../aptconfig.conf ]; then
- APT_CONFIG=../aptconfig.conf LD_LIBRARY_PATH=${BUILDDIRECTORY} command aptitude "$@"
- else
- LD_LIBRARY_PATH=${BUILDDIRECTORY} command aptitude "$@"
- fi
+ APT_CONFIG="$(getaptconfig)" LD_LIBRARY_PATH=${BUILDDIRECTORY} command aptitude "$@"
}
gdb() {
echo "gdb: run »$*«"
- APT_CONFIG=aptconfig.conf LD_LIBRARY_PATH=${BUILDDIRECTORY} command gdb ${BUILDDIRECTORY}/$1 --args "$@"
+ APT_CONFIG="$(getaptconfig)" LD_LIBRARY_PATH=${BUILDDIRECTORY} command gdb ${BUILDDIRECTORY}/$1 --args "$@"
}
http() {
LD_LIBRARY_PATH=${BUILDDIRECTORY} ${BUILDDIRECTORY}/methods/http
diff --git a/test/integration/test-apt-helper b/test/integration/test-apt-helper
new file mode 100755
index 000000000..37ed95181
--- /dev/null
+++ b/test/integration/test-apt-helper
@@ -0,0 +1,37 @@
+#!/bin/sh
+set -e
+
+TESTDIR=$(readlink -f $(dirname $0))
+. $TESTDIR/framework
+
+setupenvironment
+configarchitecture "i386"
+
+changetohttpswebserver
+
+echo "foo" > aptarchive/foo
+
+msgtest 'apt-file download-file md5sum'
+apthelper -qq download-file http://localhost:8080/foo foo2 MD5Sum:d3b07384d113edec49eaa6238ad5ff00 && msgpass || msgfail
+testfileequal foo2 'foo'
+
+msgtest 'apt-file download-file sha1'
+apthelper -qq download-file http://localhost:8080/foo foo1 SHA1:f1d2d2f924e986ac86fdf7b36c94bcdf32beec15 && msgpass || msgfail
+testfileequal foo1 'foo'
+
+msgtest 'apt-file download-file sha256'
+apthelper -qq download-file http://localhost:8080/foo foo3 SHA256:b5bb9d8014a0f9b1d61e21e796d78dccdf1352f23cd32812f4850b878ae4944c && msgpass || msgfail
+testfileequal foo3 'foo'
+
+msgtest 'apt-file download-file no-hash'
+apthelper -qq download-file http://localhost:8080/foo foo4 && msgpass || msgfail
+testfileequal foo4 'foo'
+
+msgtest 'apt-file download-file wrong hash'
+if ! apthelper -qq download-file http://localhost:8080/foo foo5 MD5Sum:aabbcc 2>&1 2> download.stderr; then
+ msgpass
+else
+ msgfail
+fi
+testfileequal download.stderr 'E: HashSum Failed'
+testfileequal foo5.failed 'foo'
diff --git a/test/integration/test-apt-https-no-redirect b/test/integration/test-apt-https-no-redirect
index 0408c6832..99419d1cc 100755
--- a/test/integration/test-apt-https-no-redirect
+++ b/test/integration/test-apt-https-no-redirect
@@ -12,11 +12,12 @@ setupaptarchive --no-update
changetohttpswebserver -o 'aptwebserver::redirect::replace::/redirectme/=http://localhost:8080/'
+DOWNLOG='download-testfile.log'
msgtest 'normal http download works'
-downloadfile 'http://localhost:8080/pool/apt_1.0/changelog' changelog2 >/dev/null 2>/dev/null && msgpass || msgfail
+downloadfile 'http://localhost:8080/pool/apt_1.0/changelog' changelog2 > "$DOWNLOG" && msgpass || msgfail
msgtest 'normal https download works'
-downloadfile 'https://localhost:4433/pool/apt_1.0/changelog' changelog >/dev/null 2>/dev/null && msgpass || msgfail
+downloadfile 'https://localhost:4433/pool/apt_1.0/changelog' changelog > "$DOWNLOG" && msgpass || msgfail
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