summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/integration/framework27
-rwxr-xr-xtest/integration/test-ubuntu-bug-1304403-obsolete-priority-standard48
-rw-r--r--test/libapt/fileutl_test.cc122
3 files changed, 195 insertions, 2 deletions
diff --git a/test/integration/framework b/test/integration/framework
index 1c6f041b0..3b900a960 100644
--- a/test/integration/framework
+++ b/test/integration/framework
@@ -190,7 +190,13 @@ setupenvironment() {
touch var/lib/dpkg/available
mkdir -p usr/lib/apt
ln -s ${METHODSDIR} usr/lib/apt/methods
- ln -s ${BUILDDIRECTORY}/../../debian/apt.conf.autoremove etc/apt/apt.conf.d/01autoremove
+ # use the autoremove from the BUILDDIRECTORY if its there, otherwise
+ # system
+ if [ -e ${BUILDDIRECTORY}/../../debian/apt.conf.autoremove ]; then
+ ln -s ${BUILDDIRECTORY}/../../debian/apt.conf.autoremove etc/apt/apt.conf.d/01autoremove
+ else
+ ln -s /etc/apt/apt.conf.d/01autoremove etc/apt/apt.conf.d/01autoremove
+ fi
cd ..
local PACKAGESFILE=$(echo "$(basename $0)" | sed -e 's/^test-/Packages-/' -e 's/^skip-/Packages-/')
if [ -f "${TESTDIRECTORY}/${PACKAGESFILE}" ]; then
@@ -879,6 +885,20 @@ rewritesourceslist() {
done
}
+# wait for up to 10s for a pid file to appear to avoid possible race
+# when a helper is started and dosn't write the PID quick enough
+waitforpidfile() {
+ local PIDFILE="$1"
+ for i in $(seq 10); do
+ if test -s "$PIDFILE"; then
+ return 0
+ fi
+ sleep 1
+ done
+ msgdie "waiting for $PIDFILE failed"
+ return 1
+}
+
changetowebserver() {
if [ "$1" != '--no-rewrite' ]; then
rewritesourceslist 'http://localhost:8080/'
@@ -892,6 +912,7 @@ changetowebserver() {
cat $LOG
false
fi
+ waitforpidfile aptwebserver.pid
local PID="$(cat aptwebserver.pid)"
if [ -z "$PID" ]; then
msgdie 'Could not fork aptwebserver successfully'
@@ -919,7 +940,11 @@ accept = 4433
connect = 8080
" > ${TMPWORKINGDIRECTORY}/stunnel.conf
stunnel4 "${TMPWORKINGDIRECTORY}/stunnel.conf"
+ waitforpidfile "${TMPWORKINGDIRECTORY}/aptarchive/stunnel.pid"
local PID="$(cat ${TMPWORKINGDIRECTORY}/aptarchive/stunnel.pid)"
+ if [ -z "$PID" ]; then
+ msgdie 'Could not fork stunnel4 successfully'
+ fi
addtrap 'prefix' "kill ${PID};"
rewritesourceslist 'https://localhost:4433/'
}
diff --git a/test/integration/test-ubuntu-bug-1304403-obsolete-priority-standard b/test/integration/test-ubuntu-bug-1304403-obsolete-priority-standard
new file mode 100755
index 000000000..2f2d384e1
--- /dev/null
+++ b/test/integration/test-ubuntu-bug-1304403-obsolete-priority-standard
@@ -0,0 +1,48 @@
+#!/bin/sh
+set -e
+
+TESTDIR=$(readlink -f $(dirname $0))
+. $TESTDIR/framework
+
+setupenvironment
+configarchitecture 'i386'
+
+# Regression test for LP: #1304403
+#
+# The issue here is that libkadm5srv-mit8 (priority standard) is replaced
+# by a new libkadm5srv-mit9 and libkbd5-7 breaks on the old -mit8 package.
+# The -mit8 package is no longer downloadable (and hence not upgradeable)
+
+# normal upradable pkg
+# (libkdb5-7 that breaks on libkadm5srv-mit8 (<< 1.11+dfsg~)
+insertinstalledpackage 'upgradable' 'all' '1.0' '' 'extra'
+insertpackage 'unstable' 'upgradable' 'all' '2.0' 'Breaks: not-downloadable (<< 1.1)' 'optional'
+
+# no longer downloadable pkg (libkadm5srv-mit8, replaced by libkadm5srv-mit9)
+# but priority standard pushes it higher
+insertinstalledpackage 'not-downloadable' 'all' '1.0' '' 'standard'
+
+setupaptarchive
+
+# discourage keeping obsolete high-priority packages …
+testequal 'Reading package lists...
+Building dependency tree...
+The following packages will be REMOVED:
+ not-downloadable
+The following packages will be upgraded:
+ upgradable
+1 upgraded, 0 newly installed, 1 to remove and 0 not upgraded.
+Remv not-downloadable [1.0]
+Inst upgradable [1.0] (2.0 unstable [all])
+Conf upgradable (2.0 unstable [all])' aptget -s dist-upgrade
+
+# … but if it has dependencies we want to keep it as usual
+for i in $(seq 1 10); do
+insertinstalledpackage "depender$i" 'all' '1.0' 'Depends: not-downloadable'
+done
+
+testequal 'Reading package lists...
+Building dependency tree...
+The following packages have been kept back:
+ upgradable
+0 upgraded, 0 newly installed, 0 to remove and 1 not upgraded.' aptget -s dist-upgrade
diff --git a/test/libapt/fileutl_test.cc b/test/libapt/fileutl_test.cc
index 8da832ba9..3a354814d 100644
--- a/test/libapt/fileutl_test.cc
+++ b/test/libapt/fileutl_test.cc
@@ -2,17 +2,137 @@
#include <apt-pkg/error.h>
#include <apt-pkg/fileutl.h>
+#include <apt-pkg/aptconfiguration.h>
#include <string>
#include <vector>
#include <stdlib.h>
+#include <sys/stat.h>
+#include <string.h>
#include "assert.h"
+static void assertStringEquals(char const * const expect, char const * const got, unsigned long const line) {
+ if (strncmp(expect, got, strlen(expect)) == 0)
+ return;
+ OutputAssertEqual(expect, "==", got, line);
+}
+#define strequals(x,y) assertStringEquals(x, y, __LINE__)
+
+static bool
+TestFileFd(mode_t const a_umask, mode_t const ExpectedFilePermission, unsigned int const filemode, APT::Configuration::Compressor const &compressor)
+{
+ FileFd f;
+ struct stat buf;
+ static const char* fname = "test.txt";
+
+ umask(a_umask);
+ equals(f.Open(fname, filemode, compressor), true);
+ equals(f.IsOpen(), true);
+ equals(f.Failed(), false);
+ equals(umask(a_umask), a_umask);
+
+ std::string test = "This is a test!";
+ equals(f.Write(test.c_str(), test.size()), true);
+ equals(f.IsOpen(), true);
+ equals(f.Failed(), false);
+
+ f.Close();
+ equals(f.IsOpen(), false);
+ equals(f.Failed(), false);
+
+ equals(f.Open(fname, FileFd::ReadOnly, compressor), true);
+ equalsNot(f.FileSize(), 0);
+ equals(f.IsOpen(), true);
+ equals(f.Failed(), false);
+
+ char readback[20];
+ {
+ char const * const expect = "This";
+ equals(f.Read(readback, strlen(expect)), true);
+ equals(f.Failed(), false);
+ equals(f.Eof(), false);
+ strequals(expect, readback);
+ equals(strlen(expect), f.Tell());
+ }
+ {
+ char const * const expect = "test!";
+ equals(f.Skip((test.size() - f.Tell()) - strlen(expect)), true);
+ equals(f.Read(readback, strlen(expect)), true);
+ equals(f.Failed(), false);
+ equals(f.Eof(), false);
+ strequals(expect, readback);
+ equals(test.size(), f.Tell());
+ }
+
+ equals(f.Seek(0), true);
+ equals(f.Read(readback, 20, true), true);
+ equals(f.Failed(), false);
+ equals(f.Eof(), true);
+ equals(test, readback);
+ equals(test.size(), strlen(readback));
+ equals(f.Size(), f.Tell());
+
+ equals(f.Seek(0), true);
+ f.ReadLine(readback, 20);
+ equals(f.Failed(), false);
+ equals(f.Eof(), true);
+ equals(test, readback);
+ equals(test.size(), strlen(readback));
+ equals(f.Size(), f.Tell());
+
+ f.Close();
+ equals(f.IsOpen(), false);
+ equals(f.Failed(), false);
+
+ // regression test for permission bug LP: #1304657
+ if (stat(fname, &buf) < 0)
+ {
+ _error->Errno("stat", "failed to stat");
+ return false;
+ }
+ unlink(fname);
+ equals(buf.st_mode & 0777, ExpectedFilePermission);
+ return true;
+}
+
+static bool TestFileFd(unsigned int const filemode)
+{
+ std::vector<APT::Configuration::Compressor> const compressors = APT::Configuration::getCompressors();
+ for (std::vector<APT::Configuration::Compressor>::const_iterator c = compressors.begin(); c != compressors.end(); ++c)
+ {
+ if ((filemode & FileFd::ReadWrite) == FileFd::ReadWrite &&
+ (c->Name.empty() != true && c->Binary.empty() != true))
+ continue;
+ if (TestFileFd(0002, 0664, filemode, *c) == false ||
+ TestFileFd(0022, 0644, filemode, *c) == false ||
+ TestFileFd(0077, 0600, filemode, *c) == false ||
+ TestFileFd(0026, 0640, filemode, *c) == false)
+ {
+ _error->DumpErrors();
+ return false;
+ }
+ }
+ return true;
+}
+
int main()
{
- std::vector<std::string> files;
+ if (TestFileFd(FileFd::WriteOnly | FileFd::Create) == false ||
+ TestFileFd(FileFd::WriteOnly | FileFd::Create | FileFd::Empty) == false ||
+ TestFileFd(FileFd::WriteOnly | FileFd::Create | FileFd::Exclusive) == false ||
+ TestFileFd(FileFd::WriteOnly | FileFd::Atomic) == false ||
+ TestFileFd(FileFd::WriteOnly | FileFd::Create | FileFd::Atomic) == false ||
+ // short-hands for ReadWrite with these modes
+ TestFileFd(FileFd::WriteEmpty) == false ||
+ TestFileFd(FileFd::WriteAny) == false ||
+ TestFileFd(FileFd::WriteTemp) == false ||
+ TestFileFd(FileFd::WriteAtomic) == false)
+ {
+ return 1;
+ }
+ std::vector<std::string> files;
// normal match
files = Glob("*.lst");
if (files.size() != 1)