blob: 233109c8d9f246f99d14d0e9e0aa4855ccd88800 [file] [log] [blame]
Yingdi Yu28fd32f2014-01-28 19:03:03 -08001/**
2 * Copyright (C) 2013 Regents of the University of California.
3 * @author: Yingdi Yu <yingdi0@cs.ucla.edu>
4 * See COPYING for copyright and distribution information.
5 */
6
7#if __clang__
8#pragma clang diagnostic ignored "-Wtautological-compare"
9#endif
10
11#include <boost/test/unit_test.hpp>
12
13#include "security/key-chain.hpp"
14
15using namespace std;
16using namespace ndn;
17
18
19BOOST_AUTO_TEST_SUITE(TestSecPublicInfoSqlite3)
20
21BOOST_AUTO_TEST_CASE (Delete)
22{
23 KeyChainImpl<SecPublicInfoSqlite3, SecTpmFile> keyChain;
24
25 Name identity("/tmp");
26 Name certName1 = keyChain.createIdentity(identity);
27 Name keyName1 = IdentityCertificate::certificateNameToPublicKeyName(certName1);
28 Name keyName2 = keyChain.generateRSAKeyPairAsDefault(identity);
29 ptr_lib::shared_ptr<IdentityCertificate> cert2 = keyChain.selfSign(keyName2);
30 Name certName2 = cert2->getName();
31 keyChain.addCertificateAsKeyDefault(*cert2);
32 Name keyName3 = keyChain.generateRSAKeyPairAsDefault(identity);
33 ptr_lib::shared_ptr<IdentityCertificate> cert3 = keyChain.selfSign(keyName3);
34 Name certName3 = cert3->getName();
35 keyChain.addCertificateAsKeyDefault(*cert3);
36 ptr_lib::shared_ptr<IdentityCertificate> cert4 = keyChain.selfSign(keyName3);
37 Name certName4 = cert4->getName();
38 keyChain.addCertificateAsKeyDefault(*cert4);
39 ptr_lib::shared_ptr<IdentityCertificate> cert5 = keyChain.selfSign(keyName3);
40 Name certName5 = cert5->getName();
41 keyChain.addCertificateAsKeyDefault(*cert5);
42
43 BOOST_REQUIRE_EQUAL(keyChain.doesIdentityExist(identity), true);
44 BOOST_REQUIRE_EQUAL(keyChain.doesPublicKeyExist(keyName1), true);
45 BOOST_REQUIRE_EQUAL(keyChain.doesPublicKeyExist(keyName2), true);
46 BOOST_REQUIRE_EQUAL(keyChain.doesPublicKeyExist(keyName3), true);
47 BOOST_REQUIRE_EQUAL(keyChain.doesCertificateExist(certName1), true);
48 BOOST_REQUIRE_EQUAL(keyChain.doesCertificateExist(certName2), true);
49 BOOST_REQUIRE_EQUAL(keyChain.doesCertificateExist(certName3), true);
50 BOOST_REQUIRE_EQUAL(keyChain.doesCertificateExist(certName4), true);
51 BOOST_REQUIRE_EQUAL(keyChain.doesCertificateExist(certName5), true);
52
53 keyChain.deleteCertificate(certName5);
54 BOOST_CHECK_EQUAL(keyChain.doesCertificateExist(certName5), false);
55 BOOST_REQUIRE_EQUAL(keyChain.doesCertificateExist(certName3), true);
56 BOOST_REQUIRE_EQUAL(keyChain.doesCertificateExist(certName4), true);
57 BOOST_CHECK_EQUAL(keyChain.doesPublicKeyExist(keyName3), true);
58
59 keyChain.deleteKey(keyName3);
60 BOOST_CHECK_EQUAL(keyChain.doesCertificateExist(certName4), false);
61 BOOST_CHECK_EQUAL(keyChain.doesCertificateExist(certName3), false);
62 BOOST_CHECK_EQUAL(keyChain.doesPublicKeyExist(keyName3), false);
63 BOOST_CHECK_EQUAL(keyChain.doesPublicKeyExist(keyName2), true);
64 BOOST_CHECK_EQUAL(keyChain.doesPublicKeyExist(keyName1), true);
65 BOOST_CHECK_EQUAL(keyChain.doesIdentityExist(identity), true);
66
67 keyChain.deleteIdentity(identity);
68 BOOST_CHECK_EQUAL(keyChain.doesCertificateExist(certName2), false);
69 BOOST_CHECK_EQUAL(keyChain.doesPublicKeyExist(keyName2), false);
70 BOOST_CHECK_EQUAL(keyChain.doesCertificateExist(certName1), false);
71 BOOST_CHECK_EQUAL(keyChain.doesPublicKeyExist(keyName1), false);
72 BOOST_CHECK_EQUAL(keyChain.doesIdentityExist(identity), false);
73}
74
75BOOST_AUTO_TEST_SUITE_END()