7 #include "zypp/base/Logger.h"
8 #include "zypp/base/Exception.h"
9 #include "zypp/KeyRing.h"
10 #include "zypp/PublicKey.h"
11 #include "zypp/TmpPath.h"
13 #include "zypp/FileChecker.h"
15 #include <boost/test/auto_unit_test.hpp>
17 #include "KeyRingTestReceiver.h"
19 using boost::unit_test::test_suite;
20 using boost::unit_test::test_case;
24 using namespace zypp::filesystem;
26 #define DATADIR (Pathname(TESTS_SRC_DIR) + "/zypp/data/FileChecker")
28 BOOST_AUTO_TEST_CASE(keyring_test)
30 Pathname file( Pathname(DATADIR) + "hello.txt" );
31 Pathname file2( Pathname(DATADIR) + "hello2.txt" );
32 Pathname pubkey( Pathname(DATADIR) + "hello.txt.key" );
33 Pathname signature( Pathname(DATADIR) + "hello.txt.asc" );
36 * 1st scenario, the signature does
40 KeyRingTestReceiver keyring_callbacks;
41 KeyRingTestSignalReceiver receiver;
43 keyring_callbacks.answerTrustKey(true);
44 SignatureFileChecker sigchecker( signature );
45 sigchecker.addPublicKey(pubkey);
50 * second scenario, the signature does not
51 * match, an exception has to be thrown
54 KeyRingTestReceiver keyring_callbacks;
55 KeyRingTestSignalReceiver receiver;
57 keyring_callbacks.answerTrustKey(true);
58 SignatureFileChecker sigchecker( signature );
59 sigchecker.addPublicKey(pubkey);
61 BOOST_CHECK_THROW( sigchecker(file2), zypp::Exception );
67 BOOST_AUTO_TEST_CASE(checksum_test)
69 Pathname file( Pathname(DATADIR) + "hello.txt" );
70 Pathname file2( Pathname(DATADIR) + "hello2.txt" );
71 Pathname pubkey( Pathname(DATADIR) + "hello.txt.key" );
72 Pathname signature( Pathname(DATADIR) + "hello.txt.asc" );
75 * 1st scenario, checksum matches
78 ChecksumFileChecker checker( CheckSum("sha1", "f2105202a0f017ab818b670d04982a89f55f090b") );
83 * 1st scenario, checksum does not matches
86 ChecksumFileChecker checker( CheckSum("sha1", "f2105202a0f017ab818b670d04982a89f55f090b") );
87 BOOST_CHECK_THROW( checker(file2), zypp::FileCheckException );