blob: 8928ebf3ffa53fcdc2af37e20a0521d193b5d807 [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 Yu2e57a582014-02-20 23:34:43 -080025 Name identity("/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));
Alexander Afanasyev6835ad82014-02-12 10:07:20 -080028
Yingdi Yu28fd32f2014-01-28 19:03:03 -080029 Name keyName1 = IdentityCertificate::certificateNameToPublicKeyName(certName1);
Yingdi Yu9a335352014-01-31 11:57:46 -080030 Name keyName2;
Yingdi Yu2e57a582014-02-20 23:34:43 -080031 BOOST_REQUIRE_NO_THROW(keyName2 = keyChain.generateRSAKeyPairAsDefault(identity));
Yingdi Yu9a335352014-01-31 11:57:46 -080032
Yingdi Yu2e57a582014-02-20 23:34:43 -080033 shared_ptr<IdentityCertificate> cert2;
34 BOOST_REQUIRE_NO_THROW(cert2 = keyChain.selfSign(keyName2));
Yingdi Yu28fd32f2014-01-28 19:03:03 -080035 Name certName2 = cert2->getName();
Yingdi Yu2e57a582014-02-20 23:34:43 -080036 BOOST_REQUIRE_NO_THROW(keyChain.addCertificateAsKeyDefault(*cert2));
Yingdi Yu9a335352014-01-31 11:57:46 -080037
38 Name keyName3;
Yingdi Yu2e57a582014-02-20 23:34:43 -080039 BOOST_REQUIRE_NO_THROW(keyName3 = keyChain.generateRSAKeyPairAsDefault(identity));
Yingdi Yu9a335352014-01-31 11:57:46 -080040
Yingdi Yu2e57a582014-02-20 23:34:43 -080041 shared_ptr<IdentityCertificate> cert3;
42 BOOST_REQUIRE_NO_THROW(cert3 = keyChain.selfSign(keyName3));
Yingdi Yu28fd32f2014-01-28 19:03:03 -080043 Name certName3 = cert3->getName();
Yingdi Yu2e57a582014-02-20 23:34:43 -080044 BOOST_REQUIRE_NO_THROW(keyChain.addCertificateAsKeyDefault(*cert3));
45 shared_ptr<IdentityCertificate> cert4;
46 BOOST_REQUIRE_NO_THROW(cert4 = keyChain.selfSign(keyName3));
Yingdi Yu28fd32f2014-01-28 19:03:03 -080047 Name certName4 = cert4->getName();
Yingdi Yu2e57a582014-02-20 23:34:43 -080048 BOOST_REQUIRE_NO_THROW(keyChain.addCertificateAsKeyDefault(*cert4));
49 shared_ptr<IdentityCertificate> cert5;
50 BOOST_REQUIRE_NO_THROW(cert5 = keyChain.selfSign(keyName3));
Yingdi Yu28fd32f2014-01-28 19:03:03 -080051 Name certName5 = cert5->getName();
Yingdi Yu2e57a582014-02-20 23:34:43 -080052 BOOST_REQUIRE_NO_THROW(keyChain.addCertificateAsKeyDefault(*cert5));
Yingdi Yu28fd32f2014-01-28 19:03:03 -080053
Alexander Afanasyev6835ad82014-02-12 10:07:20 -080054 BOOST_CHECK_EQUAL(keyChain.doesIdentityExist(identity), true);
55 BOOST_CHECK_EQUAL(keyChain.doesPublicKeyExist(keyName1), true);
56 BOOST_CHECK_EQUAL(keyChain.doesPublicKeyExist(keyName2), true);
57 BOOST_CHECK_EQUAL(keyChain.doesPublicKeyExist(keyName3), true);
58 BOOST_CHECK_EQUAL(keyChain.doesCertificateExist(certName1), true);
59 BOOST_CHECK_EQUAL(keyChain.doesCertificateExist(certName2), true);
60 BOOST_CHECK_EQUAL(keyChain.doesCertificateExist(certName3), true);
61 BOOST_CHECK_EQUAL(keyChain.doesCertificateExist(certName4), true);
62 BOOST_CHECK_EQUAL(keyChain.doesCertificateExist(certName5), true);
Yingdi Yu28fd32f2014-01-28 19:03:03 -080063
Yingdi Yuf8fc8de2014-02-25 15:45:39 -080064 BOOST_REQUIRE_NO_THROW(keyChain.deleteCertificate(certName5));
Yingdi Yu28fd32f2014-01-28 19:03:03 -080065 BOOST_CHECK_EQUAL(keyChain.doesCertificateExist(certName5), false);
Alexander Afanasyev6835ad82014-02-12 10:07:20 -080066 BOOST_CHECK_EQUAL(keyChain.doesCertificateExist(certName3), true);
67 BOOST_CHECK_EQUAL(keyChain.doesCertificateExist(certName4), true);
Yingdi Yu28fd32f2014-01-28 19:03:03 -080068 BOOST_CHECK_EQUAL(keyChain.doesPublicKeyExist(keyName3), true);
69
Yingdi Yuf8fc8de2014-02-25 15:45:39 -080070 BOOST_REQUIRE_NO_THROW(keyChain.deleteKey(keyName3));
Yingdi Yu28fd32f2014-01-28 19:03:03 -080071 BOOST_CHECK_EQUAL(keyChain.doesCertificateExist(certName4), false);
72 BOOST_CHECK_EQUAL(keyChain.doesCertificateExist(certName3), false);
73 BOOST_CHECK_EQUAL(keyChain.doesPublicKeyExist(keyName3), false);
74 BOOST_CHECK_EQUAL(keyChain.doesPublicKeyExist(keyName2), true);
75 BOOST_CHECK_EQUAL(keyChain.doesPublicKeyExist(keyName1), true);
76 BOOST_CHECK_EQUAL(keyChain.doesIdentityExist(identity), true);
77
Yingdi Yuf8fc8de2014-02-25 15:45:39 -080078 BOOST_REQUIRE_NO_THROW(keyChain.deleteIdentity(identity));
Yingdi Yu28fd32f2014-01-28 19:03:03 -080079 BOOST_CHECK_EQUAL(keyChain.doesCertificateExist(certName2), false);
80 BOOST_CHECK_EQUAL(keyChain.doesPublicKeyExist(keyName2), false);
81 BOOST_CHECK_EQUAL(keyChain.doesCertificateExist(certName1), false);
82 BOOST_CHECK_EQUAL(keyChain.doesPublicKeyExist(keyName1), false);
83 BOOST_CHECK_EQUAL(keyChain.doesIdentityExist(identity), false);
84}
85
86BOOST_AUTO_TEST_SUITE_END()
Alexander Afanasyev0abb2da2014-01-30 18:07:57 -080087
88} // namespace ndn