From 54ce88fd2669a729c89c940be3abc9456d19d542 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Tue, 22 Feb 2011 21:53:23 +0100 Subject: add sha512 interface based on sha2 by aaron gifford --- test/hash.cc | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) (limited to 'test') diff --git a/test/hash.cc b/test/hash.cc index cfdb4ea9d..259aa4e9a 100644 --- a/test/hash.cc +++ b/test/hash.cc @@ -1,6 +1,7 @@ #include #include #include +#include #include #include @@ -10,9 +11,17 @@ template void Test(const char *In,const char *Out) { T Sum; Sum.Add(In); - cout << Sum.Result().Value() << endl; - if (stringcasecmp(Sum.Result().Value(),Out) != 0) + + cout << "expected: '" << Out << "'" << endl; + cout << "got : '" << Sum.Result().Value() << "'" << endl; + cout << "got : '" << Sum.Result().Value() << "'" << endl; + cout << "got : '" << Sum.Result().Value() << "'" << endl; + if (stringcasecmp(Sum.Result().Value(), Out) != 0) { + cout << "FAIL" << endl << endl; abort(); + } else { + cout << "PASS" << endl << endl; + } } template void TestMill(const char *Out) @@ -34,9 +43,8 @@ template void TestMill(const char *Out) Count = 0; } } - - cout << Sum.Result().Value() << endl; - if (stringcasecmp(Sum.Result().Value(),Out) != 0) + + if (stringcasecmp(Sum.Result().Value(), Out) != 0) abort(); } @@ -62,8 +70,13 @@ int main() // SHA-256, From FIPS 180-2 Test("abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq", "248d6a61d20638b8e5c026930c3e6039a33ce45964ff2167f6ecedd419db06c1"); - + // SHA-512, From + Test( + "abc", + "ddaf35a193617abacc417349ae20413112e6fa4e89a97ea20a9eeee64b55d39a" + "2192992a274fc1a836ba3c23a3feebbd454d4423643ce80e2a9ac94fa54ca49f"); + return 0; } -- cgit v1.2.3 From 84a0890e6ef49b5d41a0b9ff0b5a5fe95cca6f3e Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Fri, 25 Feb 2011 14:16:35 +0100 Subject: move sha512,256 into apt-pkg/sha2.{cc,h}, move gifford implementation to sha2_internal.{cc,h} --- test/hash.cc | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'test') diff --git a/test/hash.cc b/test/hash.cc index 259aa4e9a..88f09fca0 100644 --- a/test/hash.cc +++ b/test/hash.cc @@ -1,7 +1,6 @@ #include #include -#include -#include +#include #include #include -- cgit v1.2.3 From d953d210bb54accb416f2144104b79dcd29198ba Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Tue, 17 May 2011 20:20:46 +0200 Subject: * cmdline/apt-get.cc: - do not discard the error messages from the resolver and instead only show the general 'Broken packages' message if nothing else --- test/integration/test-handling-broken-orgroups | 4 ++-- test/integration/test-release-candidate-switching | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'test') diff --git a/test/integration/test-handling-broken-orgroups b/test/integration/test-handling-broken-orgroups index d88ad0000..20b314074 100755 --- a/test/integration/test-handling-broken-orgroups +++ b/test/integration/test-handling-broken-orgroups @@ -58,7 +58,7 @@ The following information may help to resolve the situation: The following packages have unmet dependencies: coolstuff-broken : Depends: cool2 but it is not installable or stuff2 but it is not installable -E: Broken packages' aptget install coolstuff-broken -s +E: Unable to correct problems, you have held broken packages.' aptget install coolstuff-broken -s testequal 'Reading package lists... Building dependency tree... @@ -105,4 +105,4 @@ The following information may help to resolve the situation: The following packages have unmet dependencies: coolstuff-provided-broken : Depends: cool2 but it is not installable or stuff-abi-2 -E: Broken packages' aptget install coolstuff-provided-broken -s +E: Unable to correct problems, you have held broken packages.' aptget install coolstuff-provided-broken -s diff --git a/test/integration/test-release-candidate-switching b/test/integration/test-release-candidate-switching index b6dbe99db..0970cb935 100755 --- a/test/integration/test-release-candidate-switching +++ b/test/integration/test-release-candidate-switching @@ -416,4 +416,4 @@ The following information may help to resolve the situation: The following packages have unmet dependencies: uninstallablepkg : Depends: libmtp8 (>= 10:0.20.1) but it is not going to be installed Depends: amarok-utils (= 2.3.2-2+exp) but 2.3.1-1+sid is to be installed -E: Broken packages" aptget install uninstallablepkg/experimental --trivial-only -V -q=0 +E: Unable to correct problems, you have held broken packages." aptget install uninstallablepkg/experimental --trivial-only -V -q=0 -- cgit v1.2.3 From 67dc3830798e6b59a9fce03682c9802233b0a1fe Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Wed, 13 Jul 2011 19:34:11 +0200 Subject: move hash test to libapt-testcases and add a few more tests --- test/hash.cc | 82 ------------------------------ test/libapt/hashsums_test.cc | 116 +++++++++++++++++++++++++++++++++++++++++++ test/libapt/makefile | 6 +++ test/libapt/run-tests | 7 +++ 4 files changed, 129 insertions(+), 82 deletions(-) delete mode 100644 test/hash.cc create mode 100644 test/libapt/hashsums_test.cc (limited to 'test') diff --git a/test/hash.cc b/test/hash.cc deleted file mode 100644 index 88f09fca0..000000000 --- a/test/hash.cc +++ /dev/null @@ -1,82 +0,0 @@ -#include -#include -#include -#include -#include - -using namespace std; - -template void Test(const char *In,const char *Out) -{ - T Sum; - Sum.Add(In); - - cout << "expected: '" << Out << "'" << endl; - cout << "got : '" << Sum.Result().Value() << "'" << endl; - cout << "got : '" << Sum.Result().Value() << "'" << endl; - cout << "got : '" << Sum.Result().Value() << "'" << endl; - if (stringcasecmp(Sum.Result().Value(), Out) != 0) { - cout << "FAIL" << endl << endl; - abort(); - } else { - cout << "PASS" << endl << endl; - } -} - -template void TestMill(const char *Out) -{ - T Sum; - - const unsigned char As[] = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; - unsigned Count = 1000000; - for (; Count != 0;) - { - if (Count >= 64) - { - Sum.Add(As,64); - Count -= 64; - } - else - { - Sum.Add(As,Count); - Count = 0; - } - } - - if (stringcasecmp(Sum.Result().Value(), Out) != 0) - abort(); -} - -int main() -{ - // From FIPS PUB 180-1 - Test("abc","A9993E364706816ABA3E25717850C26C9CD0D89D"); - Test("abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq", - "84983E441C3BD26EBAAE4AA1F95129E5E54670F1"); - TestMill("34AA973CD4C4DAA4F61EEB2BDBAD27316534016F"); - - // MD5 tests from RFC 1321 - Test("","d41d8cd98f00b204e9800998ecf8427e"); - Test("a","0cc175b9c0f1b6a831c399e269772661"); - Test("abc","900150983cd24fb0d6963f7d28e17f72"); - Test("message digest","f96b697d7cb7938d525a2f31aaf161d0"); - Test("abcdefghijklmnopqrstuvwxyz","c3fcd3d76192e4007dfb496cca67e13b"); - Test("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789", - "d174ab98d277d9f5a5611c2c9f419d9f"); - Test("12345678901234567890123456789012345678901234567890123456789012345678901234567890", - "57edf4a22be3c955ac49da2e2107b67a"); - - // SHA-256, From FIPS 180-2 - Test("abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq", - "248d6a61d20638b8e5c026930c3e6039a33ce45964ff2167f6ecedd419db06c1"); - - // SHA-512, From - Test( - "abc", - "ddaf35a193617abacc417349ae20413112e6fa4e89a97ea20a9eeee64b55d39a" - "2192992a274fc1a836ba3c23a3feebbd454d4423643ce80e2a9ac94fa54ca49f"); - - return 0; -} - - diff --git a/test/libapt/hashsums_test.cc b/test/libapt/hashsums_test.cc new file mode 100644 index 000000000..12096be15 --- /dev/null +++ b/test/libapt/hashsums_test.cc @@ -0,0 +1,116 @@ +#include +#include +#include +#include +#include +#include + +#include + +#include "assert.h" + +template void Test(const char *In,const char *Out) +{ + T Sum; + Sum.Add(In); + equals(Sum.Result().Value(), Out); +} + +template void TestMill(const char *Out) +{ + T Sum; + + const unsigned char As[] = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; + unsigned Count = 1000000; + for (; Count != 0;) + { + if (Count >= 64) + { + Sum.Add(As,64); + Count -= 64; + } + else + { + Sum.Add(As,Count); + Count = 0; + } + } + + if (stringcasecmp(Sum.Result().Value(), Out) != 0) + abort(); +} + +int main(int argc, char** argv) +{ + // From FIPS PUB 180-1 + Test("","da39a3ee5e6b4b0d3255bfef95601890afd80709"); + Test("abc","a9993e364706816aba3e25717850c26c9cd0d89d"); + Test("abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq", + "84983e441c3bd26ebaae4aa1f95129e5e54670f1"); + TestMill("34aa973cd4c4daa4f61eeb2bdbad27316534016f"); + + // MD5 tests from RFC 1321 + Test("","d41d8cd98f00b204e9800998ecf8427e"); + Test("a","0cc175b9c0f1b6a831c399e269772661"); + Test("abc","900150983cd24fb0d6963f7d28e17f72"); + Test("message digest","f96b697d7cb7938d525a2f31aaf161d0"); + Test("abcdefghijklmnopqrstuvwxyz","c3fcd3d76192e4007dfb496cca67e13b"); + Test("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789", + "d174ab98d277d9f5a5611c2c9f419d9f"); + Test("12345678901234567890123456789012345678901234567890123456789012345678901234567890", + "57edf4a22be3c955ac49da2e2107b67a"); + + // SHA-256, From FIPS 180-2 + Test("", "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"); + Test("abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq", + "248d6a61d20638b8e5c026930c3e6039a33ce45964ff2167f6ecedd419db06c1"); + + // SHA-512 + Test("", + "cf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921d36ce9ce" + "47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e"); + Test( + "abc", + "ddaf35a193617abacc417349ae20413112e6fa4e89a97ea20a9eeee64b55d39a" + "2192992a274fc1a836ba3c23a3feebbd454d4423643ce80e2a9ac94fa54ca49f"); + + + Test("The quick brown fox jumps over the lazy dog", "9e107d9d372bb6826bd81d3542a419d6"); + Test("The quick brown fox jumps over the lazy dog.", "e4d909c290d0fb1ca068ffaddf22cbd0"); + Test("The quick brown fox jumps over the lazy dog", "2fd4e1c67a2d28fced849ee1bb76e7391b93eb12"); + Test("The quick brown fox jumps over the lazy cog", "de9f2c7fd25e1b3afad3e85a0bd17d9b100db4b3"); + Test("The quick brown fox jumps over the lazy dog", "d7a8fbb307d7809469ca9abcb0082e4f8d5651e46d3cdb762d02d0bf37c9e592"); + Test("The quick brown fox jumps over the lazy dog.", "ef537f25c895bfa782526529a9b63d97aa631564d5d789c2b765448c8635fb6c"); + Test("The quick brown fox jumps over the lazy dog", "07e547d9586f6a73f73fbac0435ed76951218fb7d0c8d788a309d785436bbb64" + "2e93a252a954f23912547d1e8a3b5ed6e1bfd7097821233fa0538f3db854fee6"); + Test("The quick brown fox jumps over the lazy dog.", "91ea1245f20d46ae9a037a989f54f1f790f0a47607eeb8a14d12890cea77a1bb" + "c6c7ed9cf205e67b7f2b8fd4c7dfd3a7a8617e45f3c463d481c7e586c39ac1ed"); + + FILE* fd = fopen(argv[1], "r"); + if (fd == NULL) { + std::cerr << "Can't open file for 1. testing: " << argv[1] << std::endl; + return 1; + } + Hashes hashes; + hashes.AddFD(fileno(fd)); + equals(argv[2], hashes.MD5.Result().Value()); + equals(argv[3], hashes.SHA1.Result().Value()); + equals(argv[4], hashes.SHA256.Result().Value()); + equals(argv[5], hashes.SHA512.Result().Value()); + + fseek(fd, 0L, SEEK_END); + unsigned long sz = ftell(fd); + fseek(fd, 0L, SEEK_SET); + + Hashes hashes2; + hashes2.AddFD(fileno(fd), sz); + fclose(fd); + equals(argv[2], hashes2.MD5.Result().Value()); + equals(argv[3], hashes2.SHA1.Result().Value()); + equals(argv[4], hashes2.SHA256.Result().Value()); + equals(argv[5], hashes2.SHA512.Result().Value()); + + return 0; +} + + diff --git a/test/libapt/makefile b/test/libapt/makefile index 50058262e..1d36f0c7c 100644 --- a/test/libapt/makefile +++ b/test/libapt/makefile @@ -46,3 +46,9 @@ PROGRAM = GlobalError${BASENAME} SLIBS = -lapt-pkg SOURCE = globalerror_test.cc include $(PROGRAM_H) + +# test the different Hashsum classes +PROGRAM = HashSums${BASENAME} +SLIBS = -lapt-pkg +SOURCE = hashsums_test.cc +include $(PROGRAM_H) diff --git a/test/libapt/run-tests b/test/libapt/run-tests index 4b71c2097..0eea6d4f8 100755 --- a/test/libapt/run-tests +++ b/test/libapt/run-tests @@ -53,6 +53,13 @@ do "${tmppath}/ftp.de.debian.org_debian_dists_sid_main_i18n_Translation-pt" \ "${tmppath}/ftp.de.debian.org_debian_dists_sid_main_i18n_Translation-se~" \ "${tmppath}/ftp.de.debian.org_debian_dists_sid_main_i18n_Translation-st.bak" + elif [ $name = "HashSums${EXT}" ]; then + TMP="$(mktemp)" + dmesg > $TMP + echo -n "Testing with \033[1;35m${name}\033[0m ... " + LD_LIBRARY_PATH=${LDPATH} ${testapp} $TMP $(md5sum $TMP | cut -d' ' -f 1) $(sha1sum $TMP | cut -d' ' -f 1) $(sha256sum $TMP | cut -d' ' -f 1) $(sha512sum $TMP | cut -d' ' -f 1) && echo "\033[1;32mOKAY\033[0m" || echo "\033[1;31mFAILED\033[0m" + rm $TMP + continue fi echo -n "Testing with \033[1;35m${name}\033[0m ... " -- cgit v1.2.3 From 96c9fb174df24fadcde516f26f89d1a64f42eea7 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Wed, 13 Jul 2011 22:29:37 +0200 Subject: test that AddFD for single summations works, too --- test/libapt/hashsums_test.cc | 43 ++++++++++++++++++++++++++++++++++--------- 1 file changed, 34 insertions(+), 9 deletions(-) (limited to 'test') diff --git a/test/libapt/hashsums_test.cc b/test/libapt/hashsums_test.cc index 12096be15..ff1536718 100644 --- a/test/libapt/hashsums_test.cc +++ b/test/libapt/hashsums_test.cc @@ -91,25 +91,50 @@ int main(int argc, char** argv) std::cerr << "Can't open file for 1. testing: " << argv[1] << std::endl; return 1; } + { Hashes hashes; hashes.AddFD(fileno(fd)); equals(argv[2], hashes.MD5.Result().Value()); equals(argv[3], hashes.SHA1.Result().Value()); equals(argv[4], hashes.SHA256.Result().Value()); equals(argv[5], hashes.SHA512.Result().Value()); - + } fseek(fd, 0L, SEEK_END); unsigned long sz = ftell(fd); fseek(fd, 0L, SEEK_SET); - - Hashes hashes2; - hashes2.AddFD(fileno(fd), sz); + { + Hashes hashes; + hashes.AddFD(fileno(fd), sz); + equals(argv[2], hashes.MD5.Result().Value()); + equals(argv[3], hashes.SHA1.Result().Value()); + equals(argv[4], hashes.SHA256.Result().Value()); + equals(argv[5], hashes.SHA512.Result().Value()); + } + fseek(fd, 0L, SEEK_SET); + { + MD5Summation md5; + md5.AddFD(fileno(fd)); + equals(argv[2], md5.Result().Value()); + } + fseek(fd, 0L, SEEK_SET); + { + SHA1Summation sha1; + sha1.AddFD(fileno(fd)); + equals(argv[3], sha1.Result().Value()); + } + fseek(fd, 0L, SEEK_SET); + { + SHA256Summation sha2; + sha2.AddFD(fileno(fd)); + equals(argv[4], sha2.Result().Value()); + } + fseek(fd, 0L, SEEK_SET); + { + SHA512Summation sha2; + sha2.AddFD(fileno(fd)); + equals(argv[5], sha2.Result().Value()); + } fclose(fd); - equals(argv[2], hashes2.MD5.Result().Value()); - equals(argv[3], hashes2.SHA1.Result().Value()); - equals(argv[4], hashes2.SHA256.Result().Value()); - equals(argv[5], hashes2.SHA512.Result().Value()); - return 0; } -- cgit v1.2.3 From 4b42f43bed369817398b6c8d538f08e5bf6dff76 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Thu, 14 Jul 2011 21:06:09 +0200 Subject: * apt-pkg/deb/debmetaindex.cc: - add trusted=yes option to mark unsigned (local) repository as trusted based on a patch from Ansgar Burchardt, thanks a lot! (Closes: #596498) Note that "apt-get update" still warns about unknown signatures even when [trusted=yes] is given for the source. --- .../test-bug-596498-trusted-unsigned-repo | 47 ++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100755 test/integration/test-bug-596498-trusted-unsigned-repo (limited to 'test') diff --git a/test/integration/test-bug-596498-trusted-unsigned-repo b/test/integration/test-bug-596498-trusted-unsigned-repo new file mode 100755 index 000000000..6ebc4a3bb --- /dev/null +++ b/test/integration/test-bug-596498-trusted-unsigned-repo @@ -0,0 +1,47 @@ +#!/bin/sh +set -e + +TESTDIR=$(readlink -f $(dirname $0)) +. $TESTDIR/framework +setupenvironment +configarchitecture 'i386' + +buildsimplenativepackage 'cool' 'i386' '1.0' 'unstable' + +setupaptarchive + +aptgetupdate() { + rm -rf rootdir/var/lib/apt/ rootdir/var/cache/apt/*.bin + aptget update -qq +} + +PKGTEXT="$(aptget install cool --assume-no -d | head -n 7)" +DEBFILE='rootdir/etc/apt/sources.list.d/apt-test-unstable-deb.list' + +testequal "$PKGTEXT +Download complete and in download only mode" aptget install cool --assume-no -d + +sed -i -e 's#deb#deb [trusted=no]#' $DEBFILE +aptgetupdate + +testequal "$PKGTEXT +WARNING: The following packages cannot be authenticated! + cool +Install these packages without verification [y/N]? N +E: Some packages could not be authenticated" aptget install cool --assume-no -d + +find aptarchive/ \( -name 'Release.gpg' -o -name 'InRelease' \) -delete +sed -i -e 's#deb \[trusted=no\]#deb#' $DEBFILE +aptgetupdate + +testequal "$PKGTEXT +WARNING: The following packages cannot be authenticated! + cool +Install these packages without verification [y/N]? N +E: Some packages could not be authenticated" aptget install cool --assume-no -d + +sed -i -e 's#deb#deb [trusted=yes]#' $DEBFILE +aptgetupdate + +testequal "$PKGTEXT +Download complete and in download only mode" aptget install cool --assume-no -d -- cgit v1.2.3 From e99a544c8c48d8067d008b5c7e4e1d5479529ce2 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Fri, 29 Jul 2011 16:33:20 +0200 Subject: test/libapt/hashsums_test.cc: add a test for HashString and VerifyFile --- test/libapt/hashsums_test.cc | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'test') diff --git a/test/libapt/hashsums_test.cc b/test/libapt/hashsums_test.cc index ff1536718..2cb71cc38 100644 --- a/test/libapt/hashsums_test.cc +++ b/test/libapt/hashsums_test.cc @@ -135,6 +135,21 @@ int main(int argc, char** argv) equals(argv[5], sha2.Result().Value()); } fclose(fd); + + // test HashString code + { + HashString sha2("SHA256", argv[4]); + equals(sha2.VerifyFile(argv[1]), true); + } + { + HashString sha2("SHA512", argv[5]); + equals(sha2.VerifyFile(argv[1]), true); + } + { + HashString sha2("SHA256:"+string(argv[4])); + equals(sha2.VerifyFile(argv[1]), true); + } + return 0; } -- cgit v1.2.3