blob: 621576272bfdb735fc8a96ca729b5050c0da306a [file] [log] [blame]
Alexander Afanasyevdfa52c42014-04-24 21:10:11 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
Yingdi Yu28fd32f2014-01-28 19:03:03 -08002/**
Alexander Afanasyevdfa52c42014-04-24 21:10:11 -07003 * Copyright (c) 2013-2014, Regents of the University of California.
4 * All rights reserved.
5 *
6 * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
7 * See AUTHORS.md for complete list of ndn-cxx authors and contributors.
8 *
9 * This file licensed under New BSD License. See COPYING for detailed information about
10 * ndn-cxx library copyright, permissions, and redistribution restrictions.
Yingdi Yu28fd32f2014-01-28 19:03:03 -080011 */
12
Yingdi Yuf56c68f2014-04-24 21:50:13 -070013#include "security/sec-public-info-sqlite3.hpp"
Yingdi Yu28fd32f2014-01-28 19:03:03 -080014#include "security/key-chain.hpp"
Yingdi Yu9a335352014-01-31 11:57:46 -080015#include "util/time.hpp"
Yingdi Yu28fd32f2014-01-28 19:03:03 -080016
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -070017#include "boost-test.hpp"
18
Yingdi Yu28fd32f2014-01-28 19:03:03 -080019using namespace std;
Alexander Afanasyev0abb2da2014-01-30 18:07:57 -080020namespace ndn {
Yingdi Yu28fd32f2014-01-28 19:03:03 -080021
Alexander Afanasyevd1b5c412014-03-27 15:03:51 -070022BOOST_AUTO_TEST_SUITE(SecurityTestSecPublicInfoSqlite3)
Yingdi Yu28fd32f2014-01-28 19:03:03 -080023
Yingdi Yuf56c68f2014-04-24 21:50:13 -070024BOOST_AUTO_TEST_CASE(Delete)
Yingdi Yu28fd32f2014-01-28 19:03:03 -080025{
Yingdi Yuf56c68f2014-04-24 21:50:13 -070026 BOOST_REQUIRE_NO_THROW(KeyChain("sqlite3", "file"));
27 KeyChain keyChain("sqlite3", "file");
Yingdi Yu28fd32f2014-01-28 19:03:03 -080028
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -070029 Name identity("/TestSecPublicInfoSqlite3/Delete");
30 identity.appendVersion();
31
Alexander Afanasyevb46f9702014-02-06 18:58:55 -080032 Name certName1;
33 BOOST_REQUIRE_NO_THROW(certName1 = keyChain.createIdentity(identity));
Alexander Afanasyev6835ad82014-02-12 10:07:20 -080034
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -070035 Name keyName1 = IdentityCertificate::certificateNameToPublicKeyName(certName1);
Yingdi Yu9a335352014-01-31 11:57:46 -080036 Name keyName2;
Yingdi Yuf56c68f2014-04-24 21:50:13 -070037 BOOST_REQUIRE_NO_THROW(keyName2 = keyChain.generateRsaKeyPairAsDefault(identity));
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -070038
Yingdi Yu2e57a582014-02-20 23:34:43 -080039 shared_ptr<IdentityCertificate> cert2;
40 BOOST_REQUIRE_NO_THROW(cert2 = keyChain.selfSign(keyName2));
Yingdi Yu28fd32f2014-01-28 19:03:03 -080041 Name certName2 = cert2->getName();
Yingdi Yu2e57a582014-02-20 23:34:43 -080042 BOOST_REQUIRE_NO_THROW(keyChain.addCertificateAsKeyDefault(*cert2));
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -070043
Yingdi Yu9a335352014-01-31 11:57:46 -080044 Name keyName3;
Yingdi Yuf56c68f2014-04-24 21:50:13 -070045 BOOST_REQUIRE_NO_THROW(keyName3 = keyChain.generateRsaKeyPairAsDefault(identity));
Alexander Afanasyevb1db7c62014-04-03 14:57:25 -070046
Yingdi Yu2e57a582014-02-20 23:34:43 -080047 shared_ptr<IdentityCertificate> cert3;
48 BOOST_REQUIRE_NO_THROW(cert3 = keyChain.selfSign(keyName3));
Yingdi Yu28fd32f2014-01-28 19:03:03 -080049 Name certName3 = cert3->getName();
Yingdi Yu2e57a582014-02-20 23:34:43 -080050 BOOST_REQUIRE_NO_THROW(keyChain.addCertificateAsKeyDefault(*cert3));
51 shared_ptr<IdentityCertificate> cert4;
52 BOOST_REQUIRE_NO_THROW(cert4 = keyChain.selfSign(keyName3));
Yingdi Yu28fd32f2014-01-28 19:03:03 -080053 Name certName4 = cert4->getName();
Yingdi Yu2e57a582014-02-20 23:34:43 -080054 BOOST_REQUIRE_NO_THROW(keyChain.addCertificateAsKeyDefault(*cert4));
55 shared_ptr<IdentityCertificate> cert5;
56 BOOST_REQUIRE_NO_THROW(cert5 = keyChain.selfSign(keyName3));
Yingdi Yu28fd32f2014-01-28 19:03:03 -080057 Name certName5 = cert5->getName();
Yingdi Yu2e57a582014-02-20 23:34:43 -080058 BOOST_REQUIRE_NO_THROW(keyChain.addCertificateAsKeyDefault(*cert5));
Yingdi Yu28fd32f2014-01-28 19:03:03 -080059
Alexander Afanasyev6835ad82014-02-12 10:07:20 -080060 BOOST_CHECK_EQUAL(keyChain.doesIdentityExist(identity), true);
61 BOOST_CHECK_EQUAL(keyChain.doesPublicKeyExist(keyName1), true);
62 BOOST_CHECK_EQUAL(keyChain.doesPublicKeyExist(keyName2), true);
63 BOOST_CHECK_EQUAL(keyChain.doesPublicKeyExist(keyName3), true);
64 BOOST_CHECK_EQUAL(keyChain.doesCertificateExist(certName1), true);
65 BOOST_CHECK_EQUAL(keyChain.doesCertificateExist(certName2), true);
66 BOOST_CHECK_EQUAL(keyChain.doesCertificateExist(certName3), true);
67 BOOST_CHECK_EQUAL(keyChain.doesCertificateExist(certName4), true);
68 BOOST_CHECK_EQUAL(keyChain.doesCertificateExist(certName5), true);
Yingdi Yu28fd32f2014-01-28 19:03:03 -080069
Yingdi Yuf8fc8de2014-02-25 15:45:39 -080070 BOOST_REQUIRE_NO_THROW(keyChain.deleteCertificate(certName5));
Yingdi Yu28fd32f2014-01-28 19:03:03 -080071 BOOST_CHECK_EQUAL(keyChain.doesCertificateExist(certName5), false);
Alexander Afanasyev6835ad82014-02-12 10:07:20 -080072 BOOST_CHECK_EQUAL(keyChain.doesCertificateExist(certName3), true);
73 BOOST_CHECK_EQUAL(keyChain.doesCertificateExist(certName4), true);
Yingdi Yu28fd32f2014-01-28 19:03:03 -080074 BOOST_CHECK_EQUAL(keyChain.doesPublicKeyExist(keyName3), true);
75
Yingdi Yuf8fc8de2014-02-25 15:45:39 -080076 BOOST_REQUIRE_NO_THROW(keyChain.deleteKey(keyName3));
Yingdi Yu28fd32f2014-01-28 19:03:03 -080077 BOOST_CHECK_EQUAL(keyChain.doesCertificateExist(certName4), false);
78 BOOST_CHECK_EQUAL(keyChain.doesCertificateExist(certName3), false);
79 BOOST_CHECK_EQUAL(keyChain.doesPublicKeyExist(keyName3), false);
80 BOOST_CHECK_EQUAL(keyChain.doesPublicKeyExist(keyName2), true);
81 BOOST_CHECK_EQUAL(keyChain.doesPublicKeyExist(keyName1), true);
82 BOOST_CHECK_EQUAL(keyChain.doesIdentityExist(identity), true);
83
Yingdi Yuf8fc8de2014-02-25 15:45:39 -080084 BOOST_REQUIRE_NO_THROW(keyChain.deleteIdentity(identity));
Yingdi Yu28fd32f2014-01-28 19:03:03 -080085 BOOST_CHECK_EQUAL(keyChain.doesCertificateExist(certName2), false);
86 BOOST_CHECK_EQUAL(keyChain.doesPublicKeyExist(keyName2), false);
87 BOOST_CHECK_EQUAL(keyChain.doesCertificateExist(certName1), false);
88 BOOST_CHECK_EQUAL(keyChain.doesPublicKeyExist(keyName1), false);
89 BOOST_CHECK_EQUAL(keyChain.doesIdentityExist(identity), false);
90}
91
92BOOST_AUTO_TEST_SUITE_END()
Alexander Afanasyev0abb2da2014-01-30 18:07:57 -080093
94} // namespace ndn