Yingdi Yu | 28fd32f | 2014-01-28 19:03:03 -0800 | [diff] [blame] | 1 | /** |
| 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 Yu | 9a33535 | 2014-01-31 11:57:46 -0800 | [diff] [blame^] | 14 | #include "util/time.hpp" |
Yingdi Yu | 28fd32f | 2014-01-28 19:03:03 -0800 | [diff] [blame] | 15 | |
| 16 | using namespace std; |
Alexander Afanasyev | 0abb2da | 2014-01-30 18:07:57 -0800 | [diff] [blame] | 17 | namespace ndn { |
Yingdi Yu | 28fd32f | 2014-01-28 19:03:03 -0800 | [diff] [blame] | 18 | |
| 19 | BOOST_AUTO_TEST_SUITE(TestSecPublicInfoSqlite3) |
| 20 | |
| 21 | BOOST_AUTO_TEST_CASE (Delete) |
| 22 | { |
| 23 | KeyChainImpl<SecPublicInfoSqlite3, SecTpmFile> keyChain; |
| 24 | |
Yingdi Yu | 9a33535 | 2014-01-31 11:57:46 -0800 | [diff] [blame^] | 25 | Name identity(string("/TestSecPublicInfoSqlite3/Delete/") + boost::lexical_cast<string>(time::now())); |
Yingdi Yu | 28fd32f | 2014-01-28 19:03:03 -0800 | [diff] [blame] | 26 | Name certName1 = keyChain.createIdentity(identity); |
| 27 | Name keyName1 = IdentityCertificate::certificateNameToPublicKeyName(certName1); |
Yingdi Yu | 9a33535 | 2014-01-31 11:57:46 -0800 | [diff] [blame^] | 28 | Name keyName2; |
| 29 | BOOST_CHECK_NO_THROW(keyName2 = keyChain.generateRSAKeyPairAsDefault(identity)); |
| 30 | |
Yingdi Yu | 28fd32f | 2014-01-28 19:03:03 -0800 | [diff] [blame] | 31 | ptr_lib::shared_ptr<IdentityCertificate> cert2 = keyChain.selfSign(keyName2); |
| 32 | Name certName2 = cert2->getName(); |
| 33 | keyChain.addCertificateAsKeyDefault(*cert2); |
Yingdi Yu | 9a33535 | 2014-01-31 11:57:46 -0800 | [diff] [blame^] | 34 | |
| 35 | Name keyName3; |
| 36 | BOOST_CHECK_NO_THROW(keyName3 = keyChain.generateRSAKeyPairAsDefault(identity)); |
| 37 | |
Yingdi Yu | 28fd32f | 2014-01-28 19:03:03 -0800 | [diff] [blame] | 38 | ptr_lib::shared_ptr<IdentityCertificate> cert3 = keyChain.selfSign(keyName3); |
| 39 | Name certName3 = cert3->getName(); |
| 40 | keyChain.addCertificateAsKeyDefault(*cert3); |
| 41 | ptr_lib::shared_ptr<IdentityCertificate> cert4 = keyChain.selfSign(keyName3); |
| 42 | Name certName4 = cert4->getName(); |
| 43 | keyChain.addCertificateAsKeyDefault(*cert4); |
| 44 | ptr_lib::shared_ptr<IdentityCertificate> cert5 = keyChain.selfSign(keyName3); |
| 45 | Name certName5 = cert5->getName(); |
| 46 | keyChain.addCertificateAsKeyDefault(*cert5); |
| 47 | |
| 48 | BOOST_REQUIRE_EQUAL(keyChain.doesIdentityExist(identity), true); |
| 49 | BOOST_REQUIRE_EQUAL(keyChain.doesPublicKeyExist(keyName1), true); |
| 50 | BOOST_REQUIRE_EQUAL(keyChain.doesPublicKeyExist(keyName2), true); |
| 51 | BOOST_REQUIRE_EQUAL(keyChain.doesPublicKeyExist(keyName3), true); |
| 52 | BOOST_REQUIRE_EQUAL(keyChain.doesCertificateExist(certName1), true); |
| 53 | BOOST_REQUIRE_EQUAL(keyChain.doesCertificateExist(certName2), true); |
| 54 | BOOST_REQUIRE_EQUAL(keyChain.doesCertificateExist(certName3), true); |
| 55 | BOOST_REQUIRE_EQUAL(keyChain.doesCertificateExist(certName4), true); |
| 56 | BOOST_REQUIRE_EQUAL(keyChain.doesCertificateExist(certName5), true); |
| 57 | |
| 58 | keyChain.deleteCertificate(certName5); |
| 59 | BOOST_CHECK_EQUAL(keyChain.doesCertificateExist(certName5), false); |
| 60 | BOOST_REQUIRE_EQUAL(keyChain.doesCertificateExist(certName3), true); |
| 61 | BOOST_REQUIRE_EQUAL(keyChain.doesCertificateExist(certName4), true); |
| 62 | BOOST_CHECK_EQUAL(keyChain.doesPublicKeyExist(keyName3), true); |
| 63 | |
| 64 | keyChain.deleteKey(keyName3); |
| 65 | BOOST_CHECK_EQUAL(keyChain.doesCertificateExist(certName4), false); |
| 66 | BOOST_CHECK_EQUAL(keyChain.doesCertificateExist(certName3), false); |
| 67 | BOOST_CHECK_EQUAL(keyChain.doesPublicKeyExist(keyName3), false); |
| 68 | BOOST_CHECK_EQUAL(keyChain.doesPublicKeyExist(keyName2), true); |
| 69 | BOOST_CHECK_EQUAL(keyChain.doesPublicKeyExist(keyName1), true); |
| 70 | BOOST_CHECK_EQUAL(keyChain.doesIdentityExist(identity), true); |
| 71 | |
| 72 | keyChain.deleteIdentity(identity); |
| 73 | BOOST_CHECK_EQUAL(keyChain.doesCertificateExist(certName2), false); |
| 74 | BOOST_CHECK_EQUAL(keyChain.doesPublicKeyExist(keyName2), false); |
| 75 | BOOST_CHECK_EQUAL(keyChain.doesCertificateExist(certName1), false); |
| 76 | BOOST_CHECK_EQUAL(keyChain.doesPublicKeyExist(keyName1), false); |
| 77 | BOOST_CHECK_EQUAL(keyChain.doesIdentityExist(identity), false); |
| 78 | } |
| 79 | |
| 80 | BOOST_AUTO_TEST_SUITE_END() |
Alexander Afanasyev | 0abb2da | 2014-01-30 18:07:57 -0800 | [diff] [blame] | 81 | |
| 82 | } // namespace ndn |