7 #include "zypp/base/Logger.h"
8 #include "zypp/base/Exception.h"
9 #include "zypp/PublicKey.h"
10 #include "zypp/TmpPath.h"
11 #include "zypp/Date.h"
13 #include <boost/test/auto_unit_test.hpp>
15 using boost::unit_test::test_suite;
16 using boost::unit_test::test_case;
21 #define DATADIR (Pathname(TESTS_SRC_DIR) + "/zypp/data/PublicKey")
23 BOOST_AUTO_TEST_CASE(publickey_test)
25 // test for a empty key
26 zypp::PublicKey empty_key;
27 BOOST_REQUIRE( ! empty_key.isValid() );
29 BOOST_CHECK_THROW( zypp::PublicKey("nonexistant"), Exception );
31 zypp::PublicKey k2(DATADIR/"susekey.asc");
32 BOOST_CHECK_EQUAL( k2.id(), "A84EDAE89C800ACA" );
33 BOOST_CHECK_EQUAL( k2.name(), "SuSE Package Signing Key <build@suse.de>" );
34 BOOST_CHECK_EQUAL( k2.fingerprint(), "79C179B2E1C820C1890F9994A84EDAE89C800ACA" );
35 BOOST_CHECK_EQUAL( k2.gpgPubkeyVersion(), "9c800aca" );
36 BOOST_CHECK_EQUAL( k2.gpgPubkeyRelease(), "40d8063e" );
37 BOOST_CHECK_EQUAL( k2.created(), zypp::Date(1087899198) );
38 BOOST_CHECK_EQUAL( k2.expires(), zypp::Date(1214043198) );
39 //BOOST_CHECK_EQUAL( k2.daysToLive(), "" );
40 BOOST_REQUIRE( k2.path() != Pathname() );
41 BOOST_REQUIRE( k2 == k2 );
43 k2 = zypp::PublicKey(DATADIR/"multikey.asc");
44 BOOST_CHECK_EQUAL( k2.id(), "27FA41BD8A7C64F9" );
45 BOOST_CHECK_EQUAL( k2.name(), "Unsupported <unsupported@suse.de>" );
46 BOOST_CHECK_EQUAL( k2.fingerprint(), "D88811AF6B51852351DF538527FA41BD8A7C64F9" );
47 BOOST_CHECK_EQUAL( k2.gpgPubkeyVersion(), "8a7c64f9" );
48 BOOST_CHECK_EQUAL( k2.gpgPubkeyRelease(), "4be01af3" );
49 BOOST_CHECK_EQUAL( k2.created(), zypp::Date(1272978163) );
50 BOOST_CHECK_EQUAL( k2.expires(), zypp::Date(1399122163) );
52 k2 = zypp::PublicKey(DATADIR/"multikey2.asc");
53 BOOST_CHECK_EQUAL( k2.hiddenKeys().size(), 8 );