blob: 70dd0f60bec6ded0ebcb04a6ff219c9c08a606c6 [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"
Yingdi Yu9a335352014-01-31 11:57:46 -080014#include "util/time.hpp"
Yingdi Yu28fd32f2014-01-28 19:03:03 -080015
16using namespace std;
Alexander Afanasyev0abb2da2014-01-30 18:07:57 -080017namespace ndn {
Yingdi Yu28fd32f2014-01-28 19:03:03 -080018
19BOOST_AUTO_TEST_SUITE(TestSecPublicInfoSqlite3)
20
21BOOST_AUTO_TEST_CASE (Delete)
22{
23 KeyChainImpl<SecPublicInfoSqlite3, SecTpmFile> keyChain;
24
Yingdi Yu9a335352014-01-31 11:57:46 -080025 Name identity(string("/TestSecPublicInfoSqlite3/Delete/") + boost::lexical_cast<string>(time::now()));
Alexander Afanasyevb46f9702014-02-06 18:58:55 -080026 Name certName1;
27 BOOST_REQUIRE_NO_THROW(certName1 = keyChain.createIdentity(identity));
28
Yingdi Yu28fd32f2014-01-28 19:03:03 -080029 Name keyName1 = IdentityCertificate::certificateNameToPublicKeyName(certName1);
Yingdi Yu9a335352014-01-31 11:57:46 -080030 Name keyName2;
31 BOOST_CHECK_NO_THROW(keyName2 = keyChain.generateRSAKeyPairAsDefault(identity));
32
Yingdi Yu28fd32f2014-01-28 19:03:03 -080033 ptr_lib::shared_ptr<IdentityCertificate> cert2 = keyChain.selfSign(keyName2);
34 Name certName2 = cert2->getName();
35 keyChain.addCertificateAsKeyDefault(*cert2);
Yingdi Yu9a335352014-01-31 11:57:46 -080036
37 Name keyName3;
38 BOOST_CHECK_NO_THROW(keyName3 = keyChain.generateRSAKeyPairAsDefault(identity));
39
Yingdi Yu28fd32f2014-01-28 19:03:03 -080040 ptr_lib::shared_ptr<IdentityCertificate> cert3 = keyChain.selfSign(keyName3);
41 Name certName3 = cert3->getName();
42 keyChain.addCertificateAsKeyDefault(*cert3);
43 ptr_lib::shared_ptr<IdentityCertificate> cert4 = keyChain.selfSign(keyName3);
44 Name certName4 = cert4->getName();
45 keyChain.addCertificateAsKeyDefault(*cert4);
46 ptr_lib::shared_ptr<IdentityCertificate> cert5 = keyChain.selfSign(keyName3);
47 Name certName5 = cert5->getName();
48 keyChain.addCertificateAsKeyDefault(*cert5);
49
50 BOOST_REQUIRE_EQUAL(keyChain.doesIdentityExist(identity), true);
51 BOOST_REQUIRE_EQUAL(keyChain.doesPublicKeyExist(keyName1), true);
52 BOOST_REQUIRE_EQUAL(keyChain.doesPublicKeyExist(keyName2), true);
53 BOOST_REQUIRE_EQUAL(keyChain.doesPublicKeyExist(keyName3), true);
54 BOOST_REQUIRE_EQUAL(keyChain.doesCertificateExist(certName1), true);
55 BOOST_REQUIRE_EQUAL(keyChain.doesCertificateExist(certName2), true);
56 BOOST_REQUIRE_EQUAL(keyChain.doesCertificateExist(certName3), true);
57 BOOST_REQUIRE_EQUAL(keyChain.doesCertificateExist(certName4), true);
58 BOOST_REQUIRE_EQUAL(keyChain.doesCertificateExist(certName5), true);
59
60 keyChain.deleteCertificate(certName5);
61 BOOST_CHECK_EQUAL(keyChain.doesCertificateExist(certName5), false);
62 BOOST_REQUIRE_EQUAL(keyChain.doesCertificateExist(certName3), true);
63 BOOST_REQUIRE_EQUAL(keyChain.doesCertificateExist(certName4), true);
64 BOOST_CHECK_EQUAL(keyChain.doesPublicKeyExist(keyName3), true);
65
66 keyChain.deleteKey(keyName3);
67 BOOST_CHECK_EQUAL(keyChain.doesCertificateExist(certName4), false);
68 BOOST_CHECK_EQUAL(keyChain.doesCertificateExist(certName3), false);
69 BOOST_CHECK_EQUAL(keyChain.doesPublicKeyExist(keyName3), false);
70 BOOST_CHECK_EQUAL(keyChain.doesPublicKeyExist(keyName2), true);
71 BOOST_CHECK_EQUAL(keyChain.doesPublicKeyExist(keyName1), true);
72 BOOST_CHECK_EQUAL(keyChain.doesIdentityExist(identity), true);
73
74 keyChain.deleteIdentity(identity);
75 BOOST_CHECK_EQUAL(keyChain.doesCertificateExist(certName2), false);
76 BOOST_CHECK_EQUAL(keyChain.doesPublicKeyExist(keyName2), false);
77 BOOST_CHECK_EQUAL(keyChain.doesCertificateExist(certName1), false);
78 BOOST_CHECK_EQUAL(keyChain.doesPublicKeyExist(keyName1), false);
79 BOOST_CHECK_EQUAL(keyChain.doesIdentityExist(identity), false);
80}
81
82BOOST_AUTO_TEST_SUITE_END()
Alexander Afanasyev0abb2da2014-01-30 18:07:57 -080083
84} // namespace ndn