blob: 6e684e92f32086f1affca5a0d2c8ad3fad7ee7c4 [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;
Alexander Afanasyev0abb2da2014-01-30 18:07:57 -080016namespace ndn {
Yingdi Yu28fd32f2014-01-28 19:03:03 -080017
18BOOST_AUTO_TEST_SUITE(TestSecPublicInfoSqlite3)
19
20BOOST_AUTO_TEST_CASE (Delete)
21{
22 KeyChainImpl<SecPublicInfoSqlite3, SecTpmFile> keyChain;
23
24 Name identity("/tmp");
25 Name certName1 = keyChain.createIdentity(identity);
26 Name keyName1 = IdentityCertificate::certificateNameToPublicKeyName(certName1);
27 Name keyName2 = keyChain.generateRSAKeyPairAsDefault(identity);
28 ptr_lib::shared_ptr<IdentityCertificate> cert2 = keyChain.selfSign(keyName2);
29 Name certName2 = cert2->getName();
30 keyChain.addCertificateAsKeyDefault(*cert2);
31 Name keyName3 = keyChain.generateRSAKeyPairAsDefault(identity);
32 ptr_lib::shared_ptr<IdentityCertificate> cert3 = keyChain.selfSign(keyName3);
33 Name certName3 = cert3->getName();
34 keyChain.addCertificateAsKeyDefault(*cert3);
35 ptr_lib::shared_ptr<IdentityCertificate> cert4 = keyChain.selfSign(keyName3);
36 Name certName4 = cert4->getName();
37 keyChain.addCertificateAsKeyDefault(*cert4);
38 ptr_lib::shared_ptr<IdentityCertificate> cert5 = keyChain.selfSign(keyName3);
39 Name certName5 = cert5->getName();
40 keyChain.addCertificateAsKeyDefault(*cert5);
41
42 BOOST_REQUIRE_EQUAL(keyChain.doesIdentityExist(identity), true);
43 BOOST_REQUIRE_EQUAL(keyChain.doesPublicKeyExist(keyName1), true);
44 BOOST_REQUIRE_EQUAL(keyChain.doesPublicKeyExist(keyName2), true);
45 BOOST_REQUIRE_EQUAL(keyChain.doesPublicKeyExist(keyName3), true);
46 BOOST_REQUIRE_EQUAL(keyChain.doesCertificateExist(certName1), true);
47 BOOST_REQUIRE_EQUAL(keyChain.doesCertificateExist(certName2), true);
48 BOOST_REQUIRE_EQUAL(keyChain.doesCertificateExist(certName3), true);
49 BOOST_REQUIRE_EQUAL(keyChain.doesCertificateExist(certName4), true);
50 BOOST_REQUIRE_EQUAL(keyChain.doesCertificateExist(certName5), true);
51
52 keyChain.deleteCertificate(certName5);
53 BOOST_CHECK_EQUAL(keyChain.doesCertificateExist(certName5), false);
54 BOOST_REQUIRE_EQUAL(keyChain.doesCertificateExist(certName3), true);
55 BOOST_REQUIRE_EQUAL(keyChain.doesCertificateExist(certName4), true);
56 BOOST_CHECK_EQUAL(keyChain.doesPublicKeyExist(keyName3), true);
57
58 keyChain.deleteKey(keyName3);
59 BOOST_CHECK_EQUAL(keyChain.doesCertificateExist(certName4), false);
60 BOOST_CHECK_EQUAL(keyChain.doesCertificateExist(certName3), false);
61 BOOST_CHECK_EQUAL(keyChain.doesPublicKeyExist(keyName3), false);
62 BOOST_CHECK_EQUAL(keyChain.doesPublicKeyExist(keyName2), true);
63 BOOST_CHECK_EQUAL(keyChain.doesPublicKeyExist(keyName1), true);
64 BOOST_CHECK_EQUAL(keyChain.doesIdentityExist(identity), true);
65
66 keyChain.deleteIdentity(identity);
67 BOOST_CHECK_EQUAL(keyChain.doesCertificateExist(certName2), false);
68 BOOST_CHECK_EQUAL(keyChain.doesPublicKeyExist(keyName2), false);
69 BOOST_CHECK_EQUAL(keyChain.doesCertificateExist(certName1), false);
70 BOOST_CHECK_EQUAL(keyChain.doesPublicKeyExist(keyName1), false);
71 BOOST_CHECK_EQUAL(keyChain.doesIdentityExist(identity), false);
72}
73
74BOOST_AUTO_TEST_SUITE_END()
Alexander Afanasyev0abb2da2014-01-30 18:07:57 -080075
76} // namespace ndn