diff options
Diffstat (limited to 'test')
20 files changed, 666 insertions, 251 deletions
diff --git a/test/authReliability/lists/people.ubuntu.com_%7emvo_apt_auth-test-suit_gpg-package-broken_Packages b/test/authReliability/lists/people.ubuntu.com_%7emvo_apt_auth-test-suit_gpg-package-broken_Packages new file mode 100644 index 000000000..3e7265438 --- /dev/null +++ b/test/authReliability/lists/people.ubuntu.com_%7emvo_apt_auth-test-suit_gpg-package-broken_Packages @@ -0,0 +1,25 @@ +Package: libglib2.0-data +Priority: optional +Section: misc +Installed-Size: 2288 +Maintainer: Ubuntu Desktop Team <ubuntu-desktop@lists.ubuntu.com> +Original-Maintainer: Loic Minier <lool@dooz.org> +Architecture: all +Source: glib2.0 +Version: 2.13.6-1ubuntu1 +Replaces: libglib1.3, libglib1.3-data +Depends: libglib2.0-0 (>= 2.13.6-1ubuntu1) +Conflicts: libglib1.3-data +Filename: ./libglib2.0-data_2.13.6-1ubuntu1_all.deb +Size: 958 +MD5sum: 803fc5e2e31a4345b3e9c771e1eae49f +SHA1: 75b2c62b21bae60c58e694dd40ed6d4df946e304 +SHA256: 142d8466eac252f06bc957d76fe1bb87f86f2d3512b99c8d4b08c1ad79fbe59e +Description: Common files for GLib library + GLib is a library containing many useful C routines for things such + as trees, hashes, lists, and strings. It is a useful general-purpose + C library used by projects such as GTK+, GIMP, and GNOME. + . + This package is needed for the runtime libraries to display messages in + languages other than English. + diff --git a/test/authReliability/lists/people.ubuntu.com_%7emvo_apt_auth-test-suit_gpg-package-broken_Release b/test/authReliability/lists/people.ubuntu.com_%7emvo_apt_auth-test-suit_gpg-package-broken_Release new file mode 100644 index 000000000..7ecd4cd19 --- /dev/null +++ b/test/authReliability/lists/people.ubuntu.com_%7emvo_apt_auth-test-suit_gpg-package-broken_Release @@ -0,0 +1,13 @@ +Date: Fri, 27 Jul 2007 14:39:41 UTC +MD5Sum: + 4672dadea6a144839f823c9f3d5fd44b 934 Packages + 82ebcf09a8d78a2b9cf7759349da4936 603 Packages.gz + d41d8cd98f00b204e9800998ecf8427e 0 Release +SHA1: + fa0f294aa30789529371066b10e9497be1284d26 934 Packages + f4032808663b2810d87b4a4dab6f5ae4a1e8fa8e 603 Packages.gz + da39a3ee5e6b4b0d3255bfef95601890afd80709 0 Release +SHA256: + 92c9b605480dc74e6be79c0ddc24738bfcbd6dd3148af531acd68717de528049 934 Packages + 659ccc0d07ff21f0247f9fa5abe149221c90d5e17da52c7afddb035b93c23d39 603 Packages.gz + e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855 0 Release diff --git a/test/authReliability/lists/people.ubuntu.com_%7emvo_apt_auth-test-suit_gpg-package-broken_Release.gpg b/test/authReliability/lists/people.ubuntu.com_%7emvo_apt_auth-test-suit_gpg-package-broken_Release.gpg new file mode 100644 index 000000000..85c356e6f --- /dev/null +++ b/test/authReliability/lists/people.ubuntu.com_%7emvo_apt_auth-test-suit_gpg-package-broken_Release.gpg @@ -0,0 +1,7 @@ +-----BEGIN PGP SIGNATURE----- +Version: GnuPG v1.4.6 (GNU/Linux) + +iD8DBQBGqgOwliSD4VZixzQRAs6jAJ9p7Aiob9gzkUNCtoW8UPrBo0E/YwCdEaz0 +CQJszU6fRYX5jGWXSWzfc5c= +=ugH0 +-----END PGP SIGNATURE----- diff --git a/test/authReliability/lists/people.ubuntu.com_%7emvo_apt_auth-test-suit_gpg-package-ok_Packages b/test/authReliability/lists/people.ubuntu.com_%7emvo_apt_auth-test-suit_gpg-package-ok_Packages new file mode 100644 index 000000000..3e7265438 --- /dev/null +++ b/test/authReliability/lists/people.ubuntu.com_%7emvo_apt_auth-test-suit_gpg-package-ok_Packages @@ -0,0 +1,25 @@ +Package: libglib2.0-data +Priority: optional +Section: misc +Installed-Size: 2288 +Maintainer: Ubuntu Desktop Team <ubuntu-desktop@lists.ubuntu.com> +Original-Maintainer: Loic Minier <lool@dooz.org> +Architecture: all +Source: glib2.0 +Version: 2.13.6-1ubuntu1 +Replaces: libglib1.3, libglib1.3-data +Depends: libglib2.0-0 (>= 2.13.6-1ubuntu1) +Conflicts: libglib1.3-data +Filename: ./libglib2.0-data_2.13.6-1ubuntu1_all.deb +Size: 958 +MD5sum: 803fc5e2e31a4345b3e9c771e1eae49f +SHA1: 75b2c62b21bae60c58e694dd40ed6d4df946e304 +SHA256: 142d8466eac252f06bc957d76fe1bb87f86f2d3512b99c8d4b08c1ad79fbe59e +Description: Common files for GLib library + GLib is a library containing many useful C routines for things such + as trees, hashes, lists, and strings. It is a useful general-purpose + C library used by projects such as GTK+, GIMP, and GNOME. + . + This package is needed for the runtime libraries to display messages in + languages other than English. + diff --git a/test/authReliability/lists/people.ubuntu.com_%7emvo_apt_auth-test-suit_gpg-package-ok_Release b/test/authReliability/lists/people.ubuntu.com_%7emvo_apt_auth-test-suit_gpg-package-ok_Release new file mode 100644 index 000000000..7ecd4cd19 --- /dev/null +++ b/test/authReliability/lists/people.ubuntu.com_%7emvo_apt_auth-test-suit_gpg-package-ok_Release @@ -0,0 +1,13 @@ +Date: Fri, 27 Jul 2007 14:39:41 UTC +MD5Sum: + 4672dadea6a144839f823c9f3d5fd44b 934 Packages + 82ebcf09a8d78a2b9cf7759349da4936 603 Packages.gz + d41d8cd98f00b204e9800998ecf8427e 0 Release +SHA1: + fa0f294aa30789529371066b10e9497be1284d26 934 Packages + f4032808663b2810d87b4a4dab6f5ae4a1e8fa8e 603 Packages.gz + da39a3ee5e6b4b0d3255bfef95601890afd80709 0 Release +SHA256: + 92c9b605480dc74e6be79c0ddc24738bfcbd6dd3148af531acd68717de528049 934 Packages + 659ccc0d07ff21f0247f9fa5abe149221c90d5e17da52c7afddb035b93c23d39 603 Packages.gz + e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855 0 Release diff --git a/test/authReliability/lists/people.ubuntu.com_%7emvo_apt_auth-test-suit_gpg-package-ok_Release.gpg b/test/authReliability/lists/people.ubuntu.com_%7emvo_apt_auth-test-suit_gpg-package-ok_Release.gpg new file mode 100644 index 000000000..85c356e6f --- /dev/null +++ b/test/authReliability/lists/people.ubuntu.com_%7emvo_apt_auth-test-suit_gpg-package-ok_Release.gpg @@ -0,0 +1,7 @@ +-----BEGIN PGP SIGNATURE----- +Version: GnuPG v1.4.6 (GNU/Linux) + +iD8DBQBGqgOwliSD4VZixzQRAs6jAJ9p7Aiob9gzkUNCtoW8UPrBo0E/YwCdEaz0 +CQJszU6fRYX5jGWXSWzfc5c= +=ugH0 +-----END PGP SIGNATURE----- diff --git a/test/authReliability/sources.list.failure b/test/authReliability/sources.list.failure new file mode 100644 index 000000000..110f31884 --- /dev/null +++ b/test/authReliability/sources.list.failure @@ -0,0 +1,2 @@ +deb http://people.ubuntu.com/~mvo/apt/auth-test-suit/gpg-package-broken/ / + diff --git a/test/authReliability/sources.list.good b/test/authReliability/sources.list.good new file mode 100644 index 000000000..2e9a4458a --- /dev/null +++ b/test/authReliability/sources.list.good @@ -0,0 +1,2 @@ +deb http://people.ubuntu.com/~mvo/apt/auth-test-suit/gpg-package-ok/ / + diff --git a/test/libapt/commandlineasstring_test.cc b/test/libapt/commandlineasstring_test.cc new file mode 100644 index 000000000..a38957d7e --- /dev/null +++ b/test/libapt/commandlineasstring_test.cc @@ -0,0 +1,39 @@ +#include <apt-pkg/cmndline.h> +#include <apt-pkg/configuration.h> + +#include <string> + +#include "assert.h" + +class CLT: public CommandLine { + + public: + std::string static AsString(const char * const * const argv, + unsigned int const argc) { + std::string const static conf = "Commandline::AsString"; + _config->Clear(conf); + SaveInConfig(argc, argv); + return _config->Find(conf); + } +}; + +#define CMD(y,z) equals(CLT::AsString(argv, y), z); + +int main() { + { + const char* const argv[] = {"apt-get", "install", "-sf"}; + CMD(3, "apt-get install -sf"); + } + { + const char* const argv[] = {"apt-cache", "-s", "apt", "-so", "Debug::test=Test"}; + CMD(5, "apt-cache -s apt -so Debug::test=Test"); + } + { + const char* const argv[] = {"apt-cache", "-s", "apt", "-so", "Debug::test=Das ist ein Test"}; + CMD(5, "apt-cache -s apt -so Debug::test=\"Das ist ein Test\""); + } + { + const char* const argv[] = {"apt-cache", "-s", "apt", "--hallo", "test=1.0"}; + CMD(5, "apt-cache -s apt --hallo test=1.0"); + } +} diff --git a/test/libapt/compareversion_test.cc b/test/libapt/compareversion_test.cc new file mode 100644 index 000000000..b6213e84c --- /dev/null +++ b/test/libapt/compareversion_test.cc @@ -0,0 +1,123 @@ +// -*- mode: cpp; mode: fold -*- +// Description /*{{{*/ +/* ###################################################################### + + Version Test - Simple program to run through a file and comare versions. + + Each version is compared and the result is checked against an expected + result in the file. The format of the file is + a b Res + Where Res is -1, 1, 0. dpkg -D=1 --compare-versions a "<" b can be + used to determine what Res should be. # at the start of the line + is a comment and blank lines are skipped + + The runner will also call dpkg --compare-versions to check if APT and + dpkg have (still) the same idea. + + ##################################################################### */ + /*}}}*/ +#include <apt-pkg/macros.h> +#include <apt-pkg/error.h> +#include <apt-pkg/version.h> +#include <apt-pkg/debversion.h> +#include <apt-pkg/fileutl.h> +#include <iostream> +#include <fstream> + +#include <stdlib.h> +#include <unistd.h> +#include <sys/types.h> +#include <sys/wait.h> + +using namespace std; + +bool callDPkg(const char *val, const char *ref, const char &op) { + pid_t Process = ExecFork(); + if (Process == 0) + { + const char * args[6]; + args[0] = "/usr/bin/dpkg"; + args[1] = "--compare-versions"; + args[2] = val; + args[3] = (op == 1) ? ">>" : ( (op == 0) ? "=" : "<<"); + args[4] = ref; + args[5] = 0; + execv(args[0], (char**) args); + exit(1); + } + int Ret; + waitpid(Process, &Ret, 0); + return WIFEXITED(Ret) == true && WEXITSTATUS(Ret) == 0; +} + +void assertVersion(int const &CurLine, string const &A, string const &B, int const &Expected) { + int Res = debVS.CmpVersion(A.c_str(), B.c_str()); + bool const dpkg = callDPkg(A.c_str(),B.c_str(), Expected); + Res = (Res < 0) ? -1 : ( (Res > 0) ? 1 : Res); + + if (Res != Expected) + _error->Error("Comparison failed on line %u. '%s' '%s' '%s' %i != %i",CurLine,A.c_str(),((Expected == 1) ? "<<" : ( (Expected == 0) ? "=" : ">>")) ,B.c_str(),Res,Expected); + if (dpkg == false) + _error->Error("DPkg differ with line: %u. '%s' '%s' '%s' == false",CurLine,A.c_str(),((Expected == 1) ? "<<" : ( (Expected == 0) ? "=" : ">>")),B.c_str()); +} + +bool RunTest(const char *File) +{ + ifstream F(File,ios::in); + if (!F != 0) + return false; + + char Buffer[300]; + int CurLine = 0; + + while (1) + { + F.getline(Buffer,sizeof(Buffer)); + CurLine++; + if (F.eof() != 0) + return true; + if (!F != 0) + return _error->Error("Line %u in %s is too long",CurLine,File); + + // Comment + if (Buffer[0] == '#' || Buffer[0] == 0) + continue; + + // First version + char *I; + char *Start = Buffer; + for (I = Buffer; *I != 0 && *I != ' '; I++); + string A(Start, I - Start); + + if (*I == 0) + return _error->Error("Invalid line %u",CurLine); + + // Second version + I++; + Start = I; + for (I = Start; *I != 0 && *I != ' '; I++); + string B(Start,I - Start); + + if (*I == 0 || I[1] == 0) + return _error->Error("Invalid line %u",CurLine); + + // Result + I++; + int const Expected = atoi(I); + assertVersion(CurLine, A, B, Expected); + // Check the reverse as well + assertVersion(CurLine, B, A, Expected*-1); + } +} + +int main(int argc, char *argv[]) +{ + if (argc <= 1) + RunTest("../versions.lst"); + else + RunTest(argv[1]); + + // Print any errors or warnings found + _error->DumpErrors(); + return 0; +} diff --git a/test/libapt/getarchitectures_test.cc b/test/libapt/getarchitectures_test.cc new file mode 100644 index 000000000..1500caeed --- /dev/null +++ b/test/libapt/getarchitectures_test.cc @@ -0,0 +1,61 @@ +#include <apt-pkg/aptconfiguration.h> +#include <apt-pkg/configuration.h> + +#include "assert.h" +#include <string> +#include <vector> + +#include <iostream> + +// simple helper to quickly output a vector of strings +void dumpVector(std::vector<std::string> vec) { + for (std::vector<std::string>::const_iterator v = vec.begin(); + v != vec.end(); v++) + std::cout << *v << std::endl; +} + +int main(int argc,char *argv[]) +{ + std::vector<std::string> vec; + + _config->Set("APT::Architectures::1", "i386"); + _config->Set("APT::Architectures::2", "amd64"); + vec = APT::Configuration::getArchitectures(false); + equals(vec.size(), 2); + equals(vec[0], "i386"); + equals(vec[1], "amd64"); + + _config->Set("APT::Architecture", "i386"); + vec = APT::Configuration::getArchitectures(false); + equals(vec.size(), 2); + equals(vec[0], "i386"); + equals(vec[1], "amd64"); + + _config->Set("APT::Architectures::2", ""); + vec = APT::Configuration::getArchitectures(false); + equals(vec.size(), 1); + equals(vec[0], "i386"); + + _config->Set("APT::Architecture", "armel"); + vec = APT::Configuration::getArchitectures(false); + equals(vec.size(), 2); + equals(vec[0], "i386"); + equals(vec[1], "armel"); + + _config->Set("APT::Architectures::2", "amd64"); + _config->Set("APT::Architectures::3", "i386"); + _config->Set("APT::Architectures::4", "armel"); + _config->Set("APT::Architectures::5", "i386"); + _config->Set("APT::Architectures::6", "amd64"); + _config->Set("APT::Architectures::7", "armel"); + _config->Set("APT::Architectures::8", "armel"); + _config->Set("APT::Architectures::9", "amd64"); + _config->Set("APT::Architectures::10", "amd64"); + vec = APT::Configuration::getArchitectures(false); + equals(vec.size(), 3); + equals(vec[0], "i386"); + equals(vec[1], "amd64"); + equals(vec[2], "armel"); + + return 0; +} diff --git a/test/libapt/globalerror_test.cc b/test/libapt/globalerror_test.cc new file mode 100644 index 000000000..b2752255f --- /dev/null +++ b/test/libapt/globalerror_test.cc @@ -0,0 +1,77 @@ +#include <apt-pkg/error.h> + +#include "assert.h" +#include <string> + +int main(int argc,char *argv[]) +{ + equals(_error->empty(), true); + equals(_error->PendingError(), false); + equals(_error->Notice("%s Notice", "A"), false); + equals(_error->empty(), true); + equals(_error->empty(GlobalError::DEBUG), false); + equals(_error->PendingError(), false); + equals(_error->Error("%s horrible %s %d times", "Something", "happend", 2), false); + equals(_error->PendingError(), true); + std::string text; + equals(_error->PopMessage(text), false); + equals(_error->PendingError(), true); + equals(text, "A Notice"); + equals(_error->PopMessage(text), true); + equals(text, "Something horrible happend 2 times"); + equals(_error->empty(GlobalError::DEBUG), true); + equals(_error->PendingError(), false); + equals(_error->Error("%s horrible %s %d times", "Something", "happend", 2), false); + equals(_error->PendingError(), true); + equals(_error->empty(GlobalError::FATAL), false); + _error->Discard(); + + equals(_error->empty(), true); + equals(_error->PendingError(), false); + equals(_error->Notice("%s Notice", "A"), false); + equals(_error->Error("%s horrible %s %d times", "Something", "happend", 2), false); + equals(_error->PendingError(), true); + equals(_error->empty(GlobalError::NOTICE), false); + _error->PushToStack(); + equals(_error->empty(GlobalError::NOTICE), true); + equals(_error->PendingError(), false); + equals(_error->Warning("%s Warning", "A"), false); + equals(_error->empty(GlobalError::ERROR), true); + equals(_error->PendingError(), false); + _error->RevertToStack(); + equals(_error->empty(GlobalError::ERROR), false); + equals(_error->PendingError(), true); + equals(_error->PopMessage(text), false); + equals(_error->PendingError(), true); + equals(text, "A Notice"); + equals(_error->PopMessage(text), true); + equals(text, "Something horrible happend 2 times"); + equals(_error->PendingError(), false); + equals(_error->empty(), true); + + equals(_error->Notice("%s Notice", "A"), false); + equals(_error->Error("%s horrible %s %d times", "Something", "happend", 2), false); + equals(_error->PendingError(), true); + equals(_error->empty(GlobalError::NOTICE), false); + _error->PushToStack(); + equals(_error->empty(GlobalError::NOTICE), true); + equals(_error->PendingError(), false); + equals(_error->Warning("%s Warning", "A"), false); + equals(_error->empty(GlobalError::ERROR), true); + equals(_error->PendingError(), false); + _error->MergeWithStack(); + equals(_error->empty(GlobalError::ERROR), false); + equals(_error->PendingError(), true); + equals(_error->PopMessage(text), false); + equals(_error->PendingError(), true); + equals(text, "A Notice"); + equals(_error->PopMessage(text), true); + equals(text, "Something horrible happend 2 times"); + equals(_error->PendingError(), false); + equals(_error->empty(), false); + equals(_error->PopMessage(text), false); + equals(text, "A Warning"); + equals(_error->empty(), true); + + return 0; +} diff --git a/test/libapt/makefile b/test/libapt/makefile index 08f581e6d..50058262e 100644 --- a/test/libapt/makefile +++ b/test/libapt/makefile @@ -12,6 +12,11 @@ SLIBS = -lapt-pkg SOURCE = getlanguages_test.cc include $(PROGRAM_H) +PROGRAM = getArchitectures${BASENAME} +SLIBS = -lapt-pkg +SOURCE = getarchitectures_test.cc +include $(PROGRAM_H) + # Program for testing ParseDepends PROGRAM = ParseDepends${BASENAME} SLIBS = -lapt-pkg @@ -23,3 +28,21 @@ PROGRAM = GetListOfFilesInDir${BASENAME} SLIBS = -lapt-pkg SOURCE = getlistoffilesindir_test.cc include $(PROGRAM_H) + +# Program for testing CommandLine reconstruction +PROGRAM = CommandlineAsString${BASENAME} +SLIBS = -lapt-pkg +SOURCE = commandlineasstring_test.cc +include $(PROGRAM_H) + +# Program for testing debians version comparing +PROGRAM = CompareVersion${BASENAME} +SLIBS = -lapt-pkg +SOURCE = compareversion_test.cc +include $(PROGRAM_H) + +# test the GlobalError stack class +PROGRAM = GlobalError${BASENAME} +SLIBS = -lapt-pkg +SOURCE = globalerror_test.cc +include $(PROGRAM_H) diff --git a/test/libapt/parsedepends_test.cc b/test/libapt/parsedepends_test.cc index b7befa561..7b496878d 100644 --- a/test/libapt/parsedepends_test.cc +++ b/test/libapt/parsedepends_test.cc @@ -21,6 +21,12 @@ int main(int argc,char *argv[]) { "apt (>= 0.7.25), " "not-for-me [ !dsk ], " "only-for-me [ dsk ], " + "any-for-me [ any ], " + "not-for-darwin [ !darwin-any ], " + "cpu-for-me [ any-dsk ], " + "os-for-me [ linux-any ], " + "cpu-not-for-me [ any-amd64 ], " + "os-not-for-me [ kfreebsd-any ], " "overlord-dev:any (= 7.15.3~) | overlord-dev:native (>> 7.15.5), " ; @@ -100,6 +106,68 @@ test: Start++; } + if (ParseArchFlags == true) { + Start = debListParser::ParseDepends(Start, End, Package, Version, Op, ParseArchFlags, StripMultiArch); + equals("any-for-me", Package); + equals("", Version); + equals(Null | pkgCache::Dep::NoOp, Op); + } else { + equals(true, 0 == debListParser::ParseDepends(Start, End, Package, Version, Op, ParseArchFlags, StripMultiArch)); + Start = strstr(Start, ","); + Start++; + } + + if (ParseArchFlags == true) { + Start = debListParser::ParseDepends(Start, End, Package, Version, Op, ParseArchFlags, StripMultiArch); + equals("not-for-darwin", Package); + equals("", Version); + equals(Null | pkgCache::Dep::NoOp, Op); + } else { + equals(true, 0 == debListParser::ParseDepends(Start, End, Package, Version, Op, ParseArchFlags, StripMultiArch)); + Start = strstr(Start, ","); + Start++; + } + + if (ParseArchFlags == true) { + Start = debListParser::ParseDepends(Start, End, Package, Version, Op, ParseArchFlags, StripMultiArch); + equals("cpu-for-me", Package); + equals("", Version); + equals(Null | pkgCache::Dep::NoOp, Op); + } else { + equals(true, 0 == debListParser::ParseDepends(Start, End, Package, Version, Op, ParseArchFlags, StripMultiArch)); + Start = strstr(Start, ","); + Start++; + } + + if (ParseArchFlags == true) { + Start = debListParser::ParseDepends(Start, End, Package, Version, Op, ParseArchFlags, StripMultiArch); + equals("os-for-me", Package); + equals("", Version); + equals(Null | pkgCache::Dep::NoOp, Op); + } else { + equals(true, 0 == debListParser::ParseDepends(Start, End, Package, Version, Op, ParseArchFlags, StripMultiArch)); + Start = strstr(Start, ","); + Start++; + } + + if (ParseArchFlags == true) { + Start = debListParser::ParseDepends(Start, End, Package, Version, Op, ParseArchFlags, StripMultiArch); + equals("", Package); // cpu-not-for-me + } else { + equals(true, 0 == debListParser::ParseDepends(Start, End, Package, Version, Op, ParseArchFlags, StripMultiArch)); + Start = strstr(Start, ","); + Start++; + } + + if (ParseArchFlags == true) { + Start = debListParser::ParseDepends(Start, End, Package, Version, Op, ParseArchFlags, StripMultiArch); + equals("", Package); // os-not-for-me + } else { + equals(true, 0 == debListParser::ParseDepends(Start, End, Package, Version, Op, ParseArchFlags, StripMultiArch)); + Start = strstr(Start, ","); + Start++; + } + Start = debListParser::ParseDepends(Start, End, Package, Version, Op, ParseArchFlags, StripMultiArch); if (StripMultiArch == true) equals("overlord-dev", Package); diff --git a/test/libapt/run-tests.sh b/test/libapt/run-tests.sh index f9df1af5f..cb7769e4a 100755 --- a/test/libapt/run-tests.sh +++ b/test/libapt/run-tests.sh @@ -2,6 +2,7 @@ set -e echo "Compiling the tests ..." +test -d '../../build/obj/test/libapt/' || mkdir -p '../../build/obj/test/libapt/' make echo "Running all testcases ..." LDPATH=$(pwd)/../../build/bin diff --git a/test/makefile b/test/makefile index fb9123d0a..52adb96a2 100644 --- a/test/makefile +++ b/test/makefile @@ -25,13 +25,6 @@ SOURCE = scratch.cc include $(PROGRAM_H) # Version compare tester -PROGRAM=versiontest -SLIBS = -lapt-pkg -LIB_MAKES = apt-pkg/makefile -SOURCE = versiontest.cc -include $(PROGRAM_H) - -# Version compare tester PROGRAM=testextract SLIBS = -lapt-pkg -lapt-inst LIB_MAKES = apt-pkg/makefile apt-inst/makefile @@ -75,7 +68,7 @@ SOURCE = test_udevcdrom.cc include $(PROGRAM_H) # Program for checking rpm versions -PROGRAM=rpmver -SLIBS = -lapt-pkg -lrpm -SOURCE = rpmver.cc -include $(PROGRAM_H) +#PROGRAM=rpmver +#SLIBS = -lapt-pkg -lrpm +#SOURCE = rpmver.cc +#include $(PROGRAM_H) diff --git a/test/pre-upload-check.py b/test/pre-upload-check.py index 268b3d672..f9da8f941 100755 --- a/test/pre-upload-check.py +++ b/test/pre-upload-check.py @@ -4,6 +4,8 @@ import sys import os import glob import os.path +import shutil +import time from subprocess import call, PIPE import unittest @@ -11,7 +13,102 @@ import unittest stdout = os.open("/dev/null",0) #sys.stdout stderr = os.open("/dev/null",0) # sys.stderr -apt_args = [] # ["-o","Debug::pkgAcquire::Auth=true"] +apt_args = [] +#apt_args = ["-o","Debug::pkgAcquire::Auth=true"] + +class testAptAuthenticationReliability(unittest.TestCase): + """ + test if the spec https://wiki.ubuntu.com/AptAuthenticationReliability + is properly implemented + """ + #apt = "../bin/apt-get" + apt = "apt-get" + + def setUp(self): + if os.path.exists("/tmp/autFailure"): + os.unlink("/tmp/authFailure"); + if os.path.exists("/tmp/autFailure2"): + os.unlink("/tmp/authFailure2"); + def testRepositorySigFailure(self): + """ + test if a repository that used to be authenticated and fails on + apt-get update refuses to update and uses the old state + """ + # copy valid signatures into lists (those are ok, even + # if the name is "-broken-" ... + for f in glob.glob("./authReliability/lists/*"): + shutil.copy(f,"/var/lib/apt/lists") + # ensure we do *not* get a I-M-S hit + os.utime("/var/lib/apt/lists/%s" % os.path.basename(f), (0,0)) + res = call([self.apt, + "update", + "-o","Dir::Etc::sourcelist=./authReliability/sources.list.failure", + "-o",'APT::Update::Auth-Failure::=touch /tmp/authFailure', + ] + apt_args, + stdout=stdout, stderr=stderr) + self.assert_(os.path.exists("/var/lib/apt/lists/people.ubuntu.com_%7emvo_apt_auth-test-suit_gpg-package-broken_Release.gpg"), + "The gpg file disappeared, this should not happen") + self.assert_(os.path.exists("/var/lib/apt/lists/people.ubuntu.com_%7emvo_apt_auth-test-suit_gpg-package-broken_Packages"), + "The Packages file disappeared, this should not happen") + self.assert_(os.path.exists("/tmp/authFailure"), + "The APT::Update::Auth-Failure script did not run (1)") + # the same with i-m-s hit this time + for f in glob.glob("./authReliability/lists/*"): + shutil.copy(f,"/var/lib/apt/lists") + os.utime("/var/lib/apt/lists/%s" % os.path.basename(f), (time.time(),time.time())) + res = call([self.apt, + "update", + "-o","Dir::Etc::sourcelist=./authReliability/sources.list.failure", + "-o",'APT::Update::Auth-Failure::=touch /tmp/authFailure2', + ] + apt_args, + stdout=stdout, stderr=stderr) + self.assert_(os.path.exists("/var/lib/apt/lists/people.ubuntu.com_%7emvo_apt_auth-test-suit_gpg-package-broken_Release.gpg"), + "The gpg file disappeared, this should not happen") + self.assert_(os.path.exists("/var/lib/apt/lists/people.ubuntu.com_%7emvo_apt_auth-test-suit_gpg-package-broken_Packages"), + "The Packages file disappeared, this should not happen") + self.assert_(os.path.exists("/tmp/authFailure2"), + "The APT::Update::Auth-Failure script did not run (2)") + def testRepositorySigGood(self): + """ + test that a regular repository with good data stays good + """ + res = call([self.apt, + "update", + "-o","Dir::Etc::sourcelist=./authReliability/sources.list.good" + ] + apt_args, + stdout=stdout, stderr=stderr) + self.assert_(os.path.exists("/var/lib/apt/lists/people.ubuntu.com_%7emvo_apt_auth-test-suit_gpg-package-ok_Release.gpg"), + "The gpg file disappeared after a regular download, this should not happen") + self.assert_(os.path.exists("/var/lib/apt/lists/people.ubuntu.com_%7emvo_apt_auth-test-suit_gpg-package-ok_Packages"), + "The Packages file disappeared, this should not happen") + # test good is still good after non I-M-S hit and a previous files in lists/ + for f in glob.glob("./authReliability/lists/*"): + shutil.copy(f,"/var/lib/apt/lists") + # ensure we do *not* get a I-M-S hit + os.utime("/var/lib/apt/lists/%s" % os.path.basename(f), (0,0)) + res = call([self.apt, + "update", + "-o","Dir::Etc::sourcelist=./authReliability/sources.list.good" + ] + apt_args, + stdout=stdout, stderr=stderr) + self.assert_(os.path.exists("/var/lib/apt/lists/people.ubuntu.com_%7emvo_apt_auth-test-suit_gpg-package-ok_Release.gpg"), + "The gpg file disappeared after a I-M-S hit, this should not happen") + self.assert_(os.path.exists("/var/lib/apt/lists/people.ubuntu.com_%7emvo_apt_auth-test-suit_gpg-package-ok_Packages"), + "The Packages file disappeared, this should not happen") + # test good is still good after I-M-S hit + for f in glob.glob("./authReliability/lists/*"): + shutil.copy(f,"/var/lib/apt/lists") + # ensure we do get a I-M-S hit + os.utime("/var/lib/apt/lists/%s" % os.path.basename(f), (time.time(),time.time())) + res = call([self.apt, + "update", + "-o","Dir::Etc::sourcelist=./authReliability/sources.list.good" + ] + apt_args, + stdout=stdout, stderr=stderr) + self.assert_(os.path.exists("/var/lib/apt/lists/people.ubuntu.com_%7emvo_apt_auth-test-suit_gpg-package-ok_Release.gpg"), + "The gpg file disappeared, this should not happen") + self.assert_(os.path.exists("/var/lib/apt/lists/people.ubuntu.com_%7emvo_apt_auth-test-suit_gpg-package-ok_Packages"), + "The Packages file disappeared, this should not happen") class testAuthentication(unittest.TestCase): @@ -95,6 +192,20 @@ class testAuthentication(unittest.TestCase): self.assert_(len(glob.glob("/var/lib/apt/lists/partial/*")) == 0, "partial/ dir has leftover files: %s" % glob.glob("/var/lib/apt/lists/partial/*")) + def testValid(self): + for f in glob.glob("testsources.list/sources.list*validuntil*"): + self._cleanup() + (prefix, testtype, result) = f.split("-") + expected_res = self._expectedRes(result) + cmd = ["update"] + res = call([self.apt,"-o","Dir::Etc::sourcelist=./%s" % f]+cmd+apt_args, + stdout=stdout, stderr=stderr) + self.assert_(res == expected_res, + "test '%s' failed (got %s expected %s" % (f,res,expected_res)) + if expected_res == 0: + self.assert_(len(glob.glob("/var/lib/apt/lists/partial/*")) == 0, + "partial/ dir has leftover files: %s" % glob.glob("/var/lib/apt/lists/partial/*")) + class testLocalRepositories(unittest.TestCase): " test local repository regressions " @@ -149,6 +260,7 @@ if __name__ == "__main__": if len(sys.argv) > 1 and sys.argv[1] == "-v": stdout = sys.stdout stderr = sys.stderr + + # run only one for now + #unittest.main(defaultTest="testAptAuthenticationReliability") unittest.main() - - diff --git a/test/testsources.list/sources.list.all-validuntil-broken b/test/testsources.list/sources.list.all-validuntil-broken new file mode 100644 index 000000000..bab59bb81 --- /dev/null +++ b/test/testsources.list/sources.list.all-validuntil-broken @@ -0,0 +1 @@ +deb http://people.ubuntu.com/~mvo/apt/auth-test-suit/all-validuntil-broken/ / diff --git a/test/versions.lst b/test/versions.lst index efc19c4f0..517214151 100644 --- a/test/versions.lst +++ b/test/versions.lst @@ -10,10 +10,11 @@ 1.3 1.2.2 1 # Important attributes -- . -1 -p - -1 -a - -1 -z - -1 +# disabled as dpkg --compare-versions doesn't like them… +#- . -1 +#p - -1 +#a - -1 +#z - -1 a . -1 z . -1 @@ -22,6 +23,10 @@ z . -1 1:1.25-4 1:1.25-8 -1 0:1.18.36 1.18.36 0 +# native version +1.18.36 1.18.35 1 +0:1.18.36 1.18.35 1 + # Funky, but allowed, characters in upstream version 9:1.18.36:5.4-20 10:0.5.1-22 -1 9:1.18.36:5.4-20 9:1.18.36:5.5-1 -1 @@ -49,3 +54,54 @@ III-alpha9.8 III-alpha9.8-1.5 -1 # #205960 3.0~rc1-1 3.0-1 -1 + +# #573592 - debian policy 5.6.12 +1.0 1.0-0 0 +0.2 1.0-0 -1 +1.0 1.0-0+b1 -1 +1.0 1.0-0~ 1 + +# if a version includes a dash +# it should be the debrev dash - policy says so… +0:0-0-0 0-0 1 + +# do we like strange versions? Yes we like strange versions… +0 0 0 +0 00 0 + +# "steal" the testcases from cupt +1.2.3 1.2.3 0 # identical +4.4.3-2 4.4.3-2 0 # identical +1:2ab:5 1:2ab:5 0 # this is correct... +7:1-a:b-5 7:1-a:b-5 0 # and this +57:1.2.3abYZ+~-4-5 57:1.2.3abYZ+~-4-5 0 # and those too +1.2.3 0:1.2.3 0 # zero epoch +1.2.3 1.2.3-0 0 # zero revision +009 9 0 # zeroes... +009ab5 9ab5 0 # there as well +1.2.3 1.2.3-1 -1 # added non-zero revision +1.2.3 1.2.4 -1 # just bigger +1.2.4 1.2.3 1 # order doesn't matter +1.2.24 1.2.3 1 # bigger, eh? +0.10.0 0.8.7 1 # bigger, eh? +3.2 2.3 1 # major number rocks +1.3.2a 1.3.2 1 # letters rock +0.5.0~git 0.5.0~git2 -1 # numbers rock +2a 21 -1 # but not in all places +1.3.2a 1.3.2b -1 # but there is another letter +1:1.2.3 1.2.4 1 # epoch rocks +1:1.2.3 1:1.2.4 -1 # bigger anyway +1.2a+~bCd3 1.2a++ -1 # tilde doesn't rock +1.2a+~bCd3 1.2a+~ 1 # but first is longer! +5:2 304-2 1 # epoch rocks +5:2 304:2 -1 # so big epoch? +25:2 3:2 1 # 25 > 3, obviously +1:2:123 1:12:3 -1 # 12 > 2 +1.2-5 1.2-3-5 -1 # 1.2 < 1.2-3 +5.10.0 5.005 1 # preceding zeroes don't matters +3a9.8 3.10.2 -1 # letters are before all letter symbols +3a9.8 3~10 1 # but after the tilde +1.4+OOo3.0.0~ 1.4+OOo3.0.0-4 -1 # another tilde check +2.4.7-1 2.4.7-z -1 # revision comparing +1.002-1+b2 1.00 1 # whatever... +2.2.4-47978_Debian_lenny 2.2.4-47978_Debian_lenny 0 # and underscore... diff --git a/test/versiontest.cc b/test/versiontest.cc deleted file mode 100644 index 4ede4b280..000000000 --- a/test/versiontest.cc +++ /dev/null @@ -1,233 +0,0 @@ -// -*- mode: cpp; mode: fold -*- -// Description /*{{{*/ -// $Id: versiontest.cc,v 1.5 2003/08/18 15:55:19 mdz Exp $ -/* ###################################################################### - - Version Test - Simple program to run through a file and comare versions. - - Each version is compared and the result is checked against an expected - result in the file. The format of the file is - a b Res - Where Res is -1, 1, 0. dpkg -D=1 --compare-versions a "<" b can be - used to determine what Res should be. # at the start of the line - is a comment and blank lines are skipped - - ##################################################################### */ - /*}}}*/ -#include <apt-pkg/macros.h> -#include <apt-pkg/error.h> -#include <apt-pkg/version.h> -#include <apt-pkg/debversion.h> -#include <iostream> -#include <fstream> - -using namespace std; - - static int verrevcmp(const char *val, const char *ref) -{ - int vc, rc; - long vl, rl; - const char *vp, *rp; - - if (!val) - val = ""; - if (!ref) - ref = ""; - for (;;) - { - vp = val; - while (*vp && !isdigit(*vp)) - vp++; - rp = ref; - while (*rp && !isdigit(*rp)) - rp++; - for (;;) - { - vc= val == vp ? 0 : *val++; - rc= ref == rp ? 0 : *ref++; - if (!rc && !vc) - break; - if (vc && !isalpha(vc)) - vc += 256; /* assumes ASCII character set */ - if (rc && !isalpha(rc)) - rc += 256; - if (vc != rc) - return vc - rc; - } - val = vp; - ref = rp; - vl = 0; - if (isdigit(*vp)) - vl = strtol(val,(char**)&val,10); - rl = 0; - if (isdigit(*rp)) - rl = strtol(ref,(char**)&ref,10); - if (vl != rl) - return vl - rl; - if (!*val && !*ref) - return 0; - if (!*val) - return -1; - if (!*ref) - return +1; - } -} - -#if 0 -static int verrevcmp(const char *val, const char *ref) -{ - int vc, rc; - long vl, rl; - const char *vp, *rp; - - if (!val) val= ""; - if (!ref) ref= ""; - for (;;) - { - vp= val; while (*vp && !isdigit(*vp) && *vp != '~') vp++; - rp= ref; while (*rp && !isdigit(*rp) && *rp != '~') rp++; - for (;;) - { - vc= val == vp ? 0 : *val++; - rc= ref == rp ? 0 : *ref++; - if (!rc && !vc) break; - if (vc && !isalpha(vc)) vc += 256; /* assumes ASCII character set */ - if (rc && !isalpha(rc)) rc += 256; - if (vc != rc) return vc - rc; - } - - val= vp; - ref= rp; - if (*vp == '~') val++; - if (*rp == '~') ref++; - vl=0; if (isdigit(*val)) vl= strtol(val,(char**)&val,10); - rl=0; if (isdigit(*ref)) rl= strtol(ref,(char**)&ref,10); - if (vl == 0 && rl == 0) - { - if (*vp == '~' && *rp != '~') return -1; - if (*vp != '~' && *rp == '~') return +1; - } - if (*vp == '~') - vl *= -1; - if (*rp == '~') - rl *= -1; - if (vl != rl) return vl - rl; - if (!*val && !*ref) return 0; - if (!*val) - { - if (*ref == '~') - return +1; - else - return -1; - } - - if (!*ref) - { - if (*val == '~') - return -1; - else - return +1; - } - } -} -#endif - -bool RunTest(const char *File) -{ - ifstream F(File,ios::in); - if (!F != 0) - return false; - - char Buffer[300]; - int CurLine = 0; - - while (1) - { - F.getline(Buffer,sizeof(Buffer)); - CurLine++; - if (F.eof() != 0) - return true; - if (!F != 0) - return _error->Error("Line %u in %s is too long",CurLine,File); - - // Comment - if (Buffer[0] == '#' || Buffer[0] == 0) - continue; - - // First version - char *I; - char *Start = Buffer; - for (I = Buffer; *I != 0 && *I != ' '; I++); - string A(Start, I - Start); - - if (*I == 0) - return _error->Error("Invalid line %u",CurLine); - - // Second version - I++; - Start = I; - for (I = Start; *I != 0 && *I != ' '; I++); - string B(Start,I - Start); - - if (*I == 0 || I[1] == 0) - return _error->Error("Invalid line %u",CurLine); - - // Result - I++; - int Expected = atoi(I); - int Res = debVS.CmpVersion(A.c_str(), B.c_str()); - int Res2 = verrevcmp(A.c_str(),B.c_str()); - cout << "'" << A << "' ? '" << B << "' = " << Res << " (= " << Expected << ") " << Res2 << endl; - - if (Res < 0) - Res = -1; - else if (Res > 0) - Res = 1; - - if (Res != Expected) - _error->Error("Comparison failed on line %u. '%s' ? '%s' %i != %i",CurLine,A.c_str(),B.c_str(),Res,Expected); - - // Check the reverse as well - Expected = -1*Expected; - Res = debVS.CmpVersion(B.c_str(), A.c_str()); - Res2 = verrevcmp(B.c_str(),A.c_str()); - - cout << "'" << B << "' ? '" << A << "' = " << Res << " (= " << Expected << ") " << Res2 << endl; - - if (Res < 0) - Res = -1; - else if (Res > 0) - Res = 1; - - if (Res != Expected) - _error->Error("Comparison failed on line %u. '%s' ? '%s' %i != %i",CurLine,B.c_str(),A.c_str(),Res,Expected); - } -} - -int main(int argc, char *argv[]) -{ - if (argc <= 1) - { - cerr << "You must specify a test file" << endl; - return 0; - } - - RunTest(argv[1]); - - // Print any errors or warnings found - if (_error->empty() == false) - { - string Err; - while (_error->empty() == false) - { - - bool Type = _error->PopMessage(Err); - if (Type == true) - cout << "E: " << Err << endl; - else - cout << "W: " << Err << endl; - } - - return 0; - } -} |