tests: Implement IdentityManagementV2Fixture for v2::KeyChain
The old IdentityManagementFixture is renamed to IdentityManagementV1Fixture.
This commit also removes global KeyChainFixture, as it doesn't work with
TestKeyChain test suites. Instead, IdentityManagementFixtures are
customizing PIB/TPM modules.
Change-Id: Iadc43b78523cd43bff4f454d6aea2fca8107a650
Refs: #2926
diff --git a/tests/identity-management-fixture.cpp b/tests/identity-management-fixture.cpp
index 6767d62..cb2a6de 100644
--- a/tests/identity-management-fixture.cpp
+++ b/tests/identity-management-fixture.cpp
@@ -21,22 +21,18 @@
#include "identity-management-fixture.hpp"
#include "util/io.hpp"
+#include "security/v2/additional-description.hpp"
#include <boost/filesystem.hpp>
namespace ndn {
namespace tests {
-IdentityManagementFixture::IdentityManagementFixture()
-{
-}
+namespace v1 = security::v1;
+namespace v2 = security::v2;
-IdentityManagementFixture::~IdentityManagementFixture()
+IdentityManagementBaseFixture::~IdentityManagementBaseFixture()
{
- for (const auto& identity : m_identities) {
- m_keyChain.deleteIdentity(identity);
- }
-
boost::system::error_code ec;
for (const auto& certFile : m_certFiles) {
boost::filesystem::remove(certFile, ec); // ignore error
@@ -44,36 +40,11 @@
}
bool
-IdentityManagementFixture::addIdentity(const Name& identity, const KeyParams& params)
+IdentityManagementBaseFixture::saveCertToFile(const Data& obj, const std::string& filename)
{
+ m_certFiles.insert(filename);
try {
- m_keyChain.createIdentity(identity, params);
- m_identities.push_back(identity);
- return true;
- }
- catch (std::runtime_error&) {
- return false;
- }
-}
-
-bool
-IdentityManagementFixture::saveIdentityCertificate(const Name& identity,
- const std::string& filename, bool wantAdd)
-{
- shared_ptr<security::v1::IdentityCertificate> cert;
- try {
- cert = m_keyChain.getCertificate(m_keyChain.getDefaultCertificateNameForIdentity(identity));
- }
- catch (const security::v1::SecPublicInfo::Error&) {
- if (wantAdd && this->addIdentity(identity)) {
- return this->saveIdentityCertificate(identity, filename, false);
- }
- return false;
- }
-
- m_certFiles.push_back(filename);
- try {
- io::save(*cert, filename);
+ io::save(obj, filename);
return true;
}
catch (const io::Error&) {
@@ -81,33 +52,111 @@
}
}
+IdentityManagementV1Fixture::~IdentityManagementV1Fixture()
+{
+ for (const auto& identity : m_identities) {
+ m_keyChain.deleteIdentity(identity);
+ }
+}
+
+Name
+IdentityManagementV1Fixture::addIdentity(const Name& identity, const KeyParams& params)
+{
+ Name certName = m_keyChain.createIdentity(identity, params);
+ m_identities.insert(identity);
+ return certName;
+}
+
bool
-IdentityManagementFixture::addSubCertificate(const Name& identity, const Name& issuer,
- const KeyParams& params)
+IdentityManagementV1Fixture::saveIdentityCertificate(const Name& certName, const std::string& filename)
+{
+ try {
+ auto cert = m_keyChain.getCertificate(certName);
+ return saveCertToFile(*cert, filename);
+ }
+ catch (const v1::SecPublicInfo::Error&) {
+ return false;
+ }
+}
+
+bool
+IdentityManagementV1Fixture::addSubCertificate(const Name& subIdentity, const Name& issuer, const KeyParams& params)
{
if (!m_keyChain.doesIdentityExist(issuer))
return false;
- if (!m_keyChain.doesIdentityExist(identity)) {
- addIdentity(identity, params);
+ if (!m_keyChain.doesIdentityExist(subIdentity)) {
+ addIdentity(subIdentity, params);
}
Name identityKeyName;
try {
- identityKeyName = m_keyChain.getDefaultKeyNameForIdentity(identity);
+ identityKeyName = m_keyChain.getDefaultKeyNameForIdentity(subIdentity);
}
- catch (const security::v1::SecPublicInfo::Error&) {
- identityKeyName = m_keyChain.generateRsaKeyPairAsDefault(identity, true);
+ catch (const v1::SecPublicInfo::Error&) {
+ identityKeyName = m_keyChain.generateRsaKeyPairAsDefault(subIdentity, true);
}
- std::vector<security::v1::CertificateSubjectDescription> subjectDescription;
- shared_ptr<security::v1::IdentityCertificate> identityCert =
+ std::vector<v1::CertificateSubjectDescription> subjectDescription;
+ shared_ptr<v1::IdentityCertificate> identityCert =
m_keyChain.prepareUnsignedIdentityCertificate(identityKeyName,
issuer,
time::system_clock::now(),
time::system_clock::now() + time::days(7300),
subjectDescription);
- m_keyChain.sign(*identityCert, security::signingByIdentity(issuer));
+ m_keyChain.sign(*identityCert, signingByIdentity(issuer));
m_keyChain.addCertificateAsIdentityDefault(*identityCert);
return true;
}
+IdentityManagementV2Fixture::IdentityManagementV2Fixture()
+ : m_keyChain("pib-memory:", "tpm-memory:")
+{
+}
+
+security::Identity
+IdentityManagementV2Fixture::addIdentity(const Name& identityName, const KeyParams& params)
+{
+ auto identity = m_keyChain.createIdentity(identityName, params);
+ m_identities.insert(identityName);
+ return identity;
+}
+
+bool
+IdentityManagementV2Fixture::saveIdentityCertificate(const security::Identity& identity,
+ const std::string& filename)
+{
+ try {
+ auto cert = identity.getDefaultKey().getDefaultCertificate();
+ return saveCertToFile(cert, filename);
+ }
+ catch (const security::Pib::Error&) {
+ return false;
+ }
+}
+
+security::Identity
+IdentityManagementV2Fixture::addSubCertificate(const Name& subIdentityName,
+ const security::Identity& issuer, const KeyParams& params)
+{
+ auto subIdentity = addIdentity(subIdentityName, params);
+
+ v2::Certificate request = subIdentity.getDefaultKey().getDefaultCertificate();
+
+ request.setName(request.getKeyName().append("parent").appendVersion());
+
+ SignatureInfo info;
+ info.setValidityPeriod(security::ValidityPeriod(time::system_clock::now(),
+ time::system_clock::now() + time::days(7300)));
+
+ v2::AdditionalDescription description;
+ description.set("type", "sub-certificate");
+ info.appendTypeSpecificTlv(description.wireEncode());
+
+ request.setSignature(Signature(info));
+
+ m_keyChain.sign(request, signingByIdentity(issuer));
+ m_keyChain.setDefaultCertificate(subIdentity.getDefaultKey(), request);
+
+ return subIdentity;
+}
+
} // namespace tests
} // namespace ndn
diff --git a/tests/identity-management-fixture.hpp b/tests/identity-management-fixture.hpp
index f96a24c..d2d1473 100644
--- a/tests/identity-management-fixture.hpp
+++ b/tests/identity-management-fixture.hpp
@@ -23,61 +23,121 @@
#define NDN_TESTS_IDENTITY_MANAGEMENT_FIXTURE_HPP
#include "security/v1/key-chain.hpp"
+#include "security/v2/key-chain.hpp"
#include "security/signing-helpers.hpp"
#include <vector>
#include "boost-test.hpp"
+#include "test-home-fixture.hpp"
namespace ndn {
namespace tests {
-/**
- * @brief IdentityManagementFixture is a test suite level fixture.
- * Test cases in the suite can use this fixture to create identities.
- * Identities added via addIdentity method are automatically deleted
- * during test teardown.
- */
-class IdentityManagementFixture
+class IdentityManagementBaseFixture : public TestHomeFixture<DefaultPibDir>
{
public:
- IdentityManagementFixture();
+ ~IdentityManagementBaseFixture();
- ~IdentityManagementFixture();
-
- /// @brief add identity, return true if succeed.
bool
+ saveCertToFile(const Data& obj, const std::string& filename);
+
+protected:
+ std::set<Name> m_identities;
+ std::set<std::string> m_certFiles;
+};
+
+/**
+ * @brief A test suite level fixture to help with identity management
+ *
+ * Test cases in the suite can use this fixture to create identities. Identities,
+ * certificates, and saved certificates are automatically removed during test teardown.
+ *
+ * @deprecated Use IdentityManagementV2Fixture
+ */
+class IdentityManagementV1Fixture : public IdentityManagementBaseFixture
+{
+public:
+ ~IdentityManagementV1Fixture();
+
+ /**
+ * @brief Add identity
+ * @return name of the created self-signed certificate
+ */
+ Name
addIdentity(const Name& identity, const KeyParams& params = security::v1::KeyChain::DEFAULT_KEY_PARAMS);
/**
* @brief save identity certificate to a file
- * @param identity identity name
+ * @param identity certificate name
* @param filename file name, should be writable
- * @param wantAdd if true, add new identity when necessary
* @return whether successful
*/
bool
- saveIdentityCertificate(const Name& identity, const std::string& filename, bool wantAdd = false);
+ saveIdentityCertificate(const Name& certName, const std::string& filename);
- /** \brief issue a certificate for \p identity signed by \p issuer
+ /**
+ * @brief issue a certificate for \p subIdentity signed by \p issuer
*
* If identity does not exist, it is created.
* A new key is generated as the default key for identity.
* A default certificate for the key is signed by the issuer using its default certificate.
*
- * \return whether success
+ * @return whether success
*/
bool
- addSubCertificate(const Name& identity, const Name& issuer,
+ addSubCertificate(const Name& subIdentity, const Name& issuer,
const KeyParams& params = security::v1::KeyChain::DEFAULT_KEY_PARAMS);
protected:
security::v1::KeyChain m_keyChain;
-
-private:
- std::vector<Name> m_identities;
- std::vector<std::string> m_certFiles;
};
+/**
+ * @brief A test suite level fixture to help with identity management
+ *
+ * Test cases in the suite can use this fixture to create identities. Identities,
+ * certificates, and saved certificates are automatically removed during test teardown.
+ */
+class IdentityManagementV2Fixture : public IdentityManagementBaseFixture
+{
+public:
+ IdentityManagementV2Fixture();
+
+ /**
+ * @brief Add identity @p identityName
+ * @return name of the created self-signed certificate
+ */
+ security::Identity
+ addIdentity(const Name& identityName, const KeyParams& params = security::v2::KeyChain::getDefaultKeyParams());
+
+ /**
+ * @brief Save identity certificate to a file
+ * @param identity identity
+ * @param filename file name, should be writable
+ * @return whether successful
+ */
+ bool
+ saveIdentityCertificate(const security::Identity& identity, const std::string& filename);
+
+ /**
+ * @brief Issue a certificate for \p subIdentityName signed by \p issuer
+ *
+ * If identity does not exist, it is created.
+ * A new key is generated as the default key for identity.
+ * A default certificate for the key is signed by the issuer using its default certificate.
+ *
+ * @return the sub identity
+ */
+ security::Identity
+ addSubCertificate(const Name& subIdentityName, const security::Identity& issuer,
+ const KeyParams& params = security::v2::KeyChain::getDefaultKeyParams());
+
+protected:
+ security::v2::KeyChain m_keyChain;
+};
+
+using IdentityManagementFixture = IdentityManagementV1Fixture;
+
} // namespace tests
} // namespace ndn
diff --git a/tests/integrated/face.cpp b/tests/integrated/face.cpp
index 799a562..9d358a5 100644
--- a/tests/integrated/face.cpp
+++ b/tests/integrated/face.cpp
@@ -28,7 +28,6 @@
#include "identity-management-fixture.hpp"
#include "boost-test.hpp"
-#include "key-chain-fixture.hpp"
#include <stdio.h>
@@ -40,8 +39,7 @@
const std::string PATH = "build/keys-with-default-tpm";
};
-class FacesFixture : public IdentityManagementFixture,
- public PibDirFixture<PibDirWithDefaultTpm>
+class FacesFixture : public IdentityManagementFixture
{
public:
FacesFixture()
diff --git a/tests/key-chain-fixture.cpp b/tests/key-chain-fixture.cpp
deleted file mode 100644
index a8f951b..0000000
--- a/tests/key-chain-fixture.cpp
+++ /dev/null
@@ -1,38 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/**
- * Copyright (c) 2013-2016 Regents of the University of California.
- *
- * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
- *
- * ndn-cxx library is free software: you can redistribute it and/or modify it under the
- * terms of the GNU Lesser General Public License as published by the Free Software
- * Foundation, either version 3 of the License, or (at your option) any later version.
- *
- * ndn-cxx library is distributed in the hope that it will be useful, but WITHOUT ANY
- * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
- * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
- *
- * You should have received copies of the GNU General Public License and GNU Lesser
- * General Public License along with ndn-cxx, e.g., in COPYING.md file. If not, see
- * <http://www.gnu.org/licenses/>.
- *
- * See AUTHORS.md for complete list of ndn-cxx authors and contributors.
- */
-
-#include "key-chain-fixture.hpp"
-
-namespace ndn {
-namespace tests {
-
-KeyChainFixture::KeyChainFixture()
-{
- addIdentity(Name("/localhost/ndn-cxx-test-identity").appendVersion());
-}
-
-BOOST_GLOBAL_FIXTURE(KeyChainFixture)
-#if BOOST_VERSION >= 105900
-;
-#endif // BOOST_VERSION >= 105900
-
-} // namespace tests
-} // namespace ndn
diff --git a/tests/key-chain-fixture.hpp b/tests/test-home-fixture.hpp
similarity index 92%
rename from tests/key-chain-fixture.hpp
rename to tests/test-home-fixture.hpp
index 014f572..8bc1fd1 100644
--- a/tests/key-chain-fixture.hpp
+++ b/tests/test-home-fixture.hpp
@@ -25,7 +25,6 @@
#include "security/v2/key-chain.hpp"
#include "boost-test.hpp"
-#include "identity-management-fixture.hpp"
#include <boost/filesystem.hpp>
#include <boost/algorithm/string.hpp>
@@ -117,23 +116,11 @@
}
};
-
struct DefaultPibDir
{
const std::string PATH = "build/keys";
};
-/**
- * @brief Fixture to create a test KeyChain with default identity
- */
-class KeyChainFixture : public PibDirFixture<DefaultPibDir>,
- public IdentityManagementFixture
-{
-public:
- KeyChainFixture();
-};
-
-
} // namespace tests
} // namespace ndn
diff --git a/tests/unit-tests/face.t.cpp b/tests/unit-tests/face.t.cpp
index 7d4c9c8..2813bd1 100644
--- a/tests/unit-tests/face.t.cpp
+++ b/tests/unit-tests/face.t.cpp
@@ -28,7 +28,7 @@
#include "boost-test.hpp"
#include "identity-management-time-fixture.hpp"
-#include "key-chain-fixture.hpp"
+#include "test-home-fixture.hpp"
#include "make-interest-data.hpp"
namespace ndn {
diff --git a/tests/unit-tests/identity-management-time-fixture.hpp b/tests/unit-tests/identity-management-time-fixture.hpp
index 3451b30..286c8d7 100644
--- a/tests/unit-tests/identity-management-time-fixture.hpp
+++ b/tests/unit-tests/identity-management-time-fixture.hpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
- * Copyright (c) 2013-2016 Regents of the University of California.
+ * Copyright (c) 2013-2017 Regents of the University of California.
*
* This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
*
@@ -28,17 +28,18 @@
namespace ndn {
namespace tests {
-/**
- * @brief IdentityManagementTimeFixture is a test suite level fixture.
- * Test cases in the suite can use this fixture to create identities.
- * Identities added via addIdentity method are automatically deleted
- * during test teardown.
- */
-class IdentityManagementTimeFixture : public UnitTestTimeFixture
- , public IdentityManagementFixture
+class IdentityManagementV1TimeFixture : public UnitTestTimeFixture
+ , public IdentityManagementV1Fixture
{
};
+class IdentityManagementV2TimeFixture : public UnitTestTimeFixture
+ , public IdentityManagementV2Fixture
+{
+};
+
+using IdentityManagementTimeFixture = IdentityManagementV1TimeFixture;
+
} // namespace tests
} // namespace ndn
diff --git a/tests/unit-tests/mgmt/nfd/controller-fixture.hpp b/tests/unit-tests/mgmt/nfd/controller-fixture.hpp
index 76e7bde..e3eb36f 100644
--- a/tests/unit-tests/mgmt/nfd/controller-fixture.hpp
+++ b/tests/unit-tests/mgmt/nfd/controller-fixture.hpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
- * Copyright (c) 2013-2016 Regents of the University of California.
+ * Copyright (c) 2013-2017 Regents of the University of California.
*
* This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
*
@@ -45,12 +45,8 @@
, datasetFailCallback(bind(&ControllerFixture::recordDatasetFail, this, _1, _2))
{
Name identityName("/localhost/ControllerFixture");
- if (this->addIdentity(identityName)) {
- m_keyChain.setDefaultIdentity(identityName);
- }
- else {
- BOOST_FAIL("cannot create identity");
- }
+ this->addIdentity(identityName);
+ m_keyChain.setDefaultIdentity(identityName);
}
/** \brief controls whether Controller's validator should accept or reject validation requests
diff --git a/tests/unit-tests/security/command-interest-validator.t.cpp b/tests/unit-tests/security/command-interest-validator.t.cpp
index f31f3a3..09ae2b9 100644
--- a/tests/unit-tests/security/command-interest-validator.t.cpp
+++ b/tests/unit-tests/security/command-interest-validator.t.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
- * Copyright (c) 2013-2016 Regents of the University of California.
+ * Copyright (c) 2013-2017 Regents of the University of California.
*
* This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
*
@@ -56,7 +56,7 @@
{
Name name("/localhost/CommandInterestValidatorIdentity");
name.appendSequenceNumber(identity);
- BOOST_REQUIRE(m_keyChain.doesIdentityExist(name) || this->addIdentity(name));
+ this->addIdentity(name);
return name;
}
diff --git a/tests/unit-tests/security/conf/checker.t.cpp b/tests/unit-tests/security/conf/checker.t.cpp
index 9ddf43a..493ac16 100644
--- a/tests/unit-tests/security/conf/checker.t.cpp
+++ b/tests/unit-tests/security/conf/checker.t.cpp
@@ -42,11 +42,11 @@
using security::conf::RelationKeyLocatorNameChecker;
Name identity("/SecurityTestConfChecker/CustomizedCheckerTest1");
- BOOST_REQUIRE(addIdentity(identity, RsaKeyParams()));
+ addIdentity(identity, RsaKeyParams());
Name certName = m_keyChain.getDefaultCertificateNameForIdentity(identity);
Name identity2("/SecurityTestConfChecker/CustomizedCheckerTest1Wrong");
- BOOST_REQUIRE(addIdentity(identity2, RsaKeyParams()));
+ addIdentity(identity2, RsaKeyParams());
Name certName2 = m_keyChain.getDefaultCertificateNameForIdentity(identity2);
Name packetName("/SecurityTestConfChecker/CustomizedCheckerTest1/Data");
@@ -157,11 +157,11 @@
using security::conf::RegexKeyLocatorNameChecker;
Name identity("/SecurityTestConfChecker/CustomizedCheckerTest2");
- BOOST_REQUIRE(addIdentity(identity, RsaKeyParams()));
+ addIdentity(identity, RsaKeyParams());
Name certName = m_keyChain.getDefaultCertificateNameForIdentity(identity);
Name identity2("/SecurityTestConfChecker/CustomizedCheckerTest2Wrong");
- BOOST_REQUIRE(addIdentity(identity2, RsaKeyParams()));
+ addIdentity(identity2, RsaKeyParams());
Name certName2 = m_keyChain.getDefaultCertificateNameForIdentity(identity2);
Name packetName("/SecurityTestConfChecker/CustomizedCheckerTest2/Data");
@@ -213,11 +213,11 @@
using security::conf::RegexKeyLocatorNameChecker;
Name identity("/SecurityTestConfChecker/CustomizedCheckerTest3");
- BOOST_REQUIRE(addIdentity(identity, EcdsaKeyParams()));
+ addIdentity(identity, EcdsaKeyParams());
Name certName = m_keyChain.getDefaultCertificateNameForIdentity(identity);
Name identity2("/SecurityTestConfChecker/CustomizedCheckerTest3Wrong");
- BOOST_REQUIRE(addIdentity(identity2, EcdsaKeyParams()));
+ addIdentity(identity2, EcdsaKeyParams());
Name certName2 = m_keyChain.getDefaultCertificateNameForIdentity(identity2);
Name packetName("/SecurityTestConfChecker/CustomizedCheckerTest3/Data");
@@ -273,11 +273,11 @@
using security::conf::HierarchicalChecker;
Name identity("/SecurityTestConfChecker/HierarchicalCheckerTest1");
- BOOST_REQUIRE(addIdentity(identity, EcdsaKeyParams()));
+ addIdentity(identity, EcdsaKeyParams());
Name certName = m_keyChain.getDefaultCertificateNameForIdentity(identity);
Name identity2("/SecurityTestConfChecker/HierarchicalCheckerTest1/Data");
- BOOST_REQUIRE(addIdentity(identity2, RsaKeyParams()));
+ addIdentity(identity2, RsaKeyParams());
Name certName2 = m_keyChain.getDefaultCertificateNameForIdentity(identity2);
Name packetName("/SecurityTestConfChecker/HierarchicalCheckerTest1/Data");
@@ -363,12 +363,12 @@
using security::conf::FixedSignerChecker;
Name identity("/SecurityTestConfChecker/FixedSignerCheckerTest1");
- BOOST_REQUIRE(addIdentity(identity, EcdsaKeyParams()));
+ addIdentity(identity, EcdsaKeyParams());
Name certName = m_keyChain.getDefaultCertificateNameForIdentity(identity);
shared_ptr<v1::IdentityCertificate> cert1 = m_keyChain.getCertificate(certName);
Name identity2("/SecurityTestConfChecker/FixedSignerCheckerTest1Wrong");
- BOOST_REQUIRE(addIdentity(identity2, RsaKeyParams()));
+ addIdentity(identity2, RsaKeyParams());
Name certName2 = m_keyChain.getDefaultCertificateNameForIdentity(identity2);
shared_ptr<v1::IdentityCertificate> cert2 = m_keyChain.getCertificate(certName2);
diff --git a/tests/unit-tests/security/identity-management-fixture.t.cpp b/tests/unit-tests/security/identity-management-fixture.t.cpp
deleted file mode 100644
index 81dcfe5..0000000
--- a/tests/unit-tests/security/identity-management-fixture.t.cpp
+++ /dev/null
@@ -1,45 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/**
- * Copyright (c) 2013-2016 Regents of the University of California.
- *
- * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
- *
- * ndn-cxx library is free software: you can redistribute it and/or modify it under the
- * terms of the GNU Lesser General Public License as published by the Free Software
- * Foundation, either version 3 of the License, or (at your option) any later version.
- *
- * ndn-cxx library is distributed in the hope that it will be useful, but WITHOUT ANY
- * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
- * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
- *
- * You should have received copies of the GNU General Public License and GNU Lesser
- * General Public License along with ndn-cxx, e.g., in COPYING.md file. If not, see
- * <http://www.gnu.org/licenses/>.
- *
- * See AUTHORS.md for complete list of ndn-cxx authors and contributors.
- */
-
-#include "identity-management-fixture.hpp"
-
-#include "boost-test.hpp"
-
-namespace ndn {
-namespace tests {
-
-BOOST_AUTO_TEST_SUITE(Security)
-BOOST_FIXTURE_TEST_SUITE(TestIdentityManagementFixture, IdentityManagementFixture)
-
-BOOST_AUTO_TEST_CASE(Tmp)
-{
- Name identity("/tmp/identity");
- BOOST_REQUIRE(addIdentity(identity));
- Name certName = m_keyChain.getDefaultCertificateNameForIdentity(identity);
- BOOST_REQUIRE_EQUAL(certName.empty(), false);
- BOOST_REQUIRE_NO_THROW(m_keyChain.getCertificate(certName));
-}
-
-BOOST_AUTO_TEST_SUITE_END() // TestIdentityManagementFixture
-BOOST_AUTO_TEST_SUITE_END() // Security
-
-} // namespace tests
-} // namespace ndn
diff --git a/tests/unit-tests/security/sec-rule-relative.t.cpp b/tests/unit-tests/security/sec-rule-relative.t.cpp
index 21f805e..4209f28 100644
--- a/tests/unit-tests/security/sec-rule-relative.t.cpp
+++ b/tests/unit-tests/security/sec-rule-relative.t.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
- * Copyright (c) 2013-2016 Regents of the University of California.
+ * Copyright (c) 2013-2017 Regents of the University of California.
*
* This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
*
@@ -34,9 +34,9 @@
BOOST_AUTO_TEST_CASE(Basic)
{
Name rsaIdentity("/SecurityTestSecRule/Basic/Rsa");
- BOOST_REQUIRE(addIdentity(rsaIdentity, RsaKeyParams()));
+ addIdentity(rsaIdentity, RsaKeyParams());
Name ecdsaIdentity("/SecurityTestSecRule/Basic/Ecdsa");
- BOOST_REQUIRE(addIdentity(ecdsaIdentity, EcdsaKeyParams()));
+ addIdentity(ecdsaIdentity, EcdsaKeyParams());
Name dataName("SecurityTestSecRule/Basic");
Data rsaData(dataName);
diff --git a/tests/unit-tests/security/sec-rule-specific.t.cpp b/tests/unit-tests/security/sec-rule-specific.t.cpp
index d8c5d24..761b60f 100644
--- a/tests/unit-tests/security/sec-rule-specific.t.cpp
+++ b/tests/unit-tests/security/sec-rule-specific.t.cpp
@@ -36,9 +36,9 @@
BOOST_AUTO_TEST_CASE(Basic)
{
Name rsaIdentity("/SecurityTestSecRule/Basic/Rsa");
- BOOST_REQUIRE(addIdentity(rsaIdentity, RsaKeyParams()));
+ addIdentity(rsaIdentity, RsaKeyParams());
Name ecdsaIdentity("/SecurityTestSecRule/Basic/Ecdsa");
- BOOST_REQUIRE(addIdentity(ecdsaIdentity, EcdsaKeyParams()));
+ addIdentity(ecdsaIdentity, EcdsaKeyParams());
Name dataName("SecurityTestSecRule/Basic");
Data rsaData(dataName);
diff --git a/tests/unit-tests/security/signature-sha256-with-ecdsa.t.cpp b/tests/unit-tests/security/signature-sha256-with-ecdsa.t.cpp
index c54ee4c..7f20981 100644
--- a/tests/unit-tests/security/signature-sha256-with-ecdsa.t.cpp
+++ b/tests/unit-tests/security/signature-sha256-with-ecdsa.t.cpp
@@ -105,7 +105,7 @@
BOOST_AUTO_TEST_CASE(DataSignature)
{
Name identityName("/SecurityTestSignatureSha256WithEcdsa/DataSignature");
- BOOST_REQUIRE(addIdentity(identityName, EcdsaKeyParams()));
+ addIdentity(identityName, EcdsaKeyParams());
shared_ptr<security::v1::PublicKey> publicKey;
BOOST_REQUIRE_NO_THROW(publicKey = m_keyChain.getPublicKeyFromTpm(
m_keyChain.getDefaultKeyNameForIdentity(identityName)));
@@ -126,7 +126,7 @@
BOOST_AUTO_TEST_CASE(InterestSignature)
{
Name identityName("/SecurityTestSignatureSha256WithEcdsa/InterestSignature");
- BOOST_REQUIRE(addIdentity(identityName, EcdsaKeyParams()));
+ addIdentity(identityName, EcdsaKeyParams());
shared_ptr<security::v1::PublicKey> publicKey;
BOOST_REQUIRE_NO_THROW(publicKey = m_keyChain.getPublicKeyFromTpm(
m_keyChain.getDefaultKeyNameForIdentity(identityName)));
diff --git a/tests/unit-tests/security/signature-sha256-with-rsa.t.cpp b/tests/unit-tests/security/signature-sha256-with-rsa.t.cpp
index 494ea71..4944cbd 100644
--- a/tests/unit-tests/security/signature-sha256-with-rsa.t.cpp
+++ b/tests/unit-tests/security/signature-sha256-with-rsa.t.cpp
@@ -110,7 +110,7 @@
BOOST_AUTO_TEST_CASE(DataSignature)
{
Name identityName("/SecurityTestSignatureSha256WithRsa/DataSignature");
- BOOST_REQUIRE(addIdentity(identityName, RsaKeyParams()));
+ addIdentity(identityName, RsaKeyParams());
shared_ptr<security::v1::PublicKey> publicKey;
BOOST_REQUIRE_NO_THROW(publicKey = m_keyChain.getPublicKeyFromTpm(
m_keyChain.getDefaultKeyNameForIdentity(identityName)));
@@ -131,7 +131,7 @@
BOOST_AUTO_TEST_CASE(InterestSignature)
{
Name identityName("/SecurityTestSignatureSha256WithRsa/InterestSignature");
- BOOST_REQUIRE(addIdentity(identityName, RsaKeyParams()));
+ addIdentity(identityName, RsaKeyParams());
shared_ptr<security::v1::PublicKey> publicKey;
BOOST_REQUIRE_NO_THROW(publicKey = m_keyChain.getPublicKeyFromTpm(
m_keyChain.getDefaultKeyNameForIdentity(identityName)));
diff --git a/tests/unit-tests/security/v1/key-chain.t.cpp b/tests/unit-tests/security/v1/key-chain.t.cpp
index 6130cae..36dac9c 100644
--- a/tests/unit-tests/security/v1/key-chain.t.cpp
+++ b/tests/unit-tests/security/v1/key-chain.t.cpp
@@ -26,7 +26,7 @@
#include "boost-test.hpp"
#include "dummy-keychain.hpp"
#include "../../test-home-env-saver.hpp"
-#include "key-chain-fixture.hpp"
+#include "test-home-fixture.hpp"
#include "identity-management-fixture.hpp"
#include <boost/algorithm/string.hpp>
diff --git a/tests/unit-tests/security/v2/key-chain.t.cpp b/tests/unit-tests/security/v2/key-chain.t.cpp
index db14070..8ce962e 100644
--- a/tests/unit-tests/security/v2/key-chain.t.cpp
+++ b/tests/unit-tests/security/v2/key-chain.t.cpp
@@ -24,7 +24,7 @@
#include "boost-test.hpp"
#include "unit-tests/test-home-env-saver.hpp"
-#include "key-chain-fixture.hpp"
+#include "test-home-fixture.hpp"
#include "validator.hpp"
namespace ndn {
diff --git a/tests/unit-tests/security/validator-config.t.cpp b/tests/unit-tests/security/validator-config.t.cpp
index 74aab21..022e80b 100644
--- a/tests/unit-tests/security/validator-config.t.cpp
+++ b/tests/unit-tests/security/validator-config.t.cpp
@@ -49,7 +49,7 @@
{
Name identity("/TestValidatorConfig/NameFilter");
identity.appendVersion();
- BOOST_REQUIRE(saveIdentityCertificate(identity, "trust-anchor-1.cert", true));
+ BOOST_REQUIRE(saveIdentityCertificate(addIdentity(identity), "trust-anchor-1.cert"));
Name certName = m_keyChain.getDefaultCertificateNameForIdentity(identity);
Name dataName1("/simple/equal");
@@ -113,7 +113,7 @@
{
Name identity("/TestValidatorConfig/NameFilter2");
identity.appendVersion();
- BOOST_REQUIRE(saveIdentityCertificate(identity, "trust-anchor-2.cert", true));
+ BOOST_REQUIRE(saveIdentityCertificate(addIdentity(identity), "trust-anchor-2.cert"));
Name certName = m_keyChain.getDefaultCertificateNameForIdentity(identity);
Name dataName1("/simple/isPrefixOf");
@@ -185,7 +185,7 @@
{
Name identity("/TestValidatorConfig/NameFilter3");
identity.appendVersion();
- BOOST_REQUIRE(saveIdentityCertificate(identity, "trust-anchor-3.cert", true));
+ BOOST_REQUIRE(saveIdentityCertificate(addIdentity(identity), "trust-anchor-3.cert"));
Name certName = m_keyChain.getDefaultCertificateNameForIdentity(identity);
Name dataName1("/simple/isStrictPrefixOf");
@@ -257,7 +257,7 @@
{
Name identity("/TestValidatorConfig/NameFilter4");
identity.appendVersion();
- BOOST_REQUIRE(saveIdentityCertificate(identity, "trust-anchor-4.cert", true));
+ BOOST_REQUIRE(saveIdentityCertificate(addIdentity(identity), "trust-anchor-4.cert"));
Name certName = m_keyChain.getDefaultCertificateNameForIdentity(identity);
Name dataName1("/simple/regex");
@@ -328,7 +328,7 @@
{
Name identity("/TestValidatorConfig/KeyLocatorNameChecker1");
identity.appendVersion();
- BOOST_REQUIRE(saveIdentityCertificate(identity, "trust-anchor-5.cert", true));
+ BOOST_REQUIRE(saveIdentityCertificate(addIdentity(identity), "trust-anchor-5.cert"));
Name dataName1 = identity;
dataName1.append("1");
@@ -397,11 +397,11 @@
Name identity1 = identity;
identity1.append("1").appendVersion();
- BOOST_REQUIRE(saveIdentityCertificate(identity1, "trust-anchor-7.cert", true));
+ BOOST_REQUIRE(saveIdentityCertificate(addIdentity(identity1), "trust-anchor-7.cert"));
Name identity2 = identity;
identity2.append("2").appendVersion();
- BOOST_REQUIRE_NO_THROW(addIdentity(identity2));
+ addIdentity(identity2);
Name dataName1 = identity;
dataName1.append("data").appendVersion();
@@ -483,11 +483,11 @@
{
Name identity1("/TestValidatorConfig/MultiCheckers/");
identity1.appendVersion();
- BOOST_REQUIRE(saveIdentityCertificate(identity1, "trust-anchor-multi-1.cert", true));
+ BOOST_REQUIRE(saveIdentityCertificate(addIdentity(identity1), "trust-anchor-multi-1.cert"));
Name identity2("/TestValidatorConfig/");
identity2.appendVersion();
- BOOST_REQUIRE(saveIdentityCertificate(identity2, "trust-anchor-multi-2.cert", true));
+ BOOST_REQUIRE(saveIdentityCertificate(addIdentity(identity2), "trust-anchor-multi-2.cert"));
const std::string CONFIG =
"rule\n"
@@ -596,7 +596,7 @@
BOOST_AUTO_TEST_CASE(Reset)
{
Name root("/TestValidatorConfig/Reload");
- BOOST_REQUIRE(saveIdentityCertificate(root, "trust-anchor-8.cert", true));
+ BOOST_REQUIRE(saveIdentityCertificate(addIdentity(root), "trust-anchor-8.cert"));
Face face(nullptr, m_keyChain);
@@ -657,7 +657,7 @@
{
Name identity("/TestValidatorConfig/Wildcard");
identity.appendVersion();
- BOOST_REQUIRE_NO_THROW(addIdentity(identity));
+ addIdentity(identity);
Name dataName1("/any/data");
shared_ptr<Data> data1 = make_shared<Data>(dataName1);
@@ -687,7 +687,7 @@
Name identity1 = identity;
identity1.appendVersion();
- BOOST_REQUIRE(saveIdentityCertificate(identity1, "trust-anchor-9.cert", true));
+ BOOST_REQUIRE(saveIdentityCertificate(addIdentity(identity1), "trust-anchor-9.cert"));
Name interestName("/TestValidatorConfig/SignedInterestTest");
Name interestName1 = interestName;
@@ -750,15 +750,15 @@
Name identity1 = identity;
identity1.append("Key1");
- BOOST_REQUIRE(saveIdentityCertificate(identity1, "trust-anchor-10-1.cert", true));
+ BOOST_REQUIRE(saveIdentityCertificate(addIdentity(identity1), "trust-anchor-10-1.cert"));
Name identity2 = identity;
identity2.append("Key2");
- BOOST_REQUIRE(saveIdentityCertificate(identity2, "trust-anchor-10-2.cert", true));
+ BOOST_REQUIRE(saveIdentityCertificate(addIdentity(identity2), "trust-anchor-10-2.cert"));
Name identity3 = identity;
identity3.append("Key3");
- BOOST_REQUIRE(saveIdentityCertificate(identity3, "trust-anchor-10-3.cert", true));
+ BOOST_REQUIRE(saveIdentityCertificate(addIdentity(identity3), "trust-anchor-10-3.cert"));
Name interestName("/TestValidatorConfig/MaxKeyTest");
@@ -850,19 +850,19 @@
Name identity1 = identity;
identity1.append("Key1");
- BOOST_REQUIRE(saveIdentityCertificate(identity1, "trust-anchor-10-1.cert", true));
+ BOOST_REQUIRE(saveIdentityCertificate(addIdentity(identity1), "trust-anchor-10-1.cert"));
Name identity2 = identity;
identity2.append("Key2");
- BOOST_REQUIRE(saveIdentityCertificate(identity2, "trust-anchor-10-2.cert", true));
+ BOOST_REQUIRE(saveIdentityCertificate(addIdentity(identity2), "trust-anchor-10-2.cert"));
Name identity3 = identity;
identity3.append("Key3");
- BOOST_REQUIRE(saveIdentityCertificate(identity3, "trust-anchor-10-3.cert", true));
+ BOOST_REQUIRE(saveIdentityCertificate(addIdentity(identity3), "trust-anchor-10-3.cert"));
Name identity4 = identity;
identity4.append("Key4");
- BOOST_REQUIRE(saveIdentityCertificate(identity4, "trust-anchor-10-4.cert", true));
+ BOOST_REQUIRE(saveIdentityCertificate(addIdentity(identity4), "trust-anchor-10-4.cert"));
Name interestName("/TestValidatorConfig/MaxKeyTest");
@@ -983,12 +983,12 @@
BOOST_AUTO_TEST_CASE(FixedSignerChecker2)
{
Name rsaIdentity("/TestValidatorConfig/FixedSignerChecker2/Rsa");
- BOOST_REQUIRE(addIdentity(rsaIdentity));
- Name rsaCertName = m_keyChain.getDefaultCertificateNameForIdentity(rsaIdentity);
+ addIdentity(rsaIdentity);
+ // Name rsaCertName = m_keyChain.getDefaultCertificateNameForIdentity(rsaIdentity);
Name ecdsaIdentity("/TestValidatorConfig/FixedSignerChecker2/Ecdsa");
- BOOST_REQUIRE(addIdentity(ecdsaIdentity, EcdsaKeyParams()));
- BOOST_REQUIRE(saveIdentityCertificate(ecdsaIdentity, "trust-anchor-11.cert"));
+ auto identity = addIdentity(ecdsaIdentity, EcdsaKeyParams());
+ BOOST_REQUIRE(saveIdentityCertificate(identity, "trust-anchor-11.cert"));
Name dataName("/TestValidatorConfig/FixedSignerChecker2");
shared_ptr<Data> dataRsa = make_shared<Data>(dataName);
@@ -1127,11 +1127,11 @@
std::vector<v1::CertificateSubjectDescription> subjectDescription;
Name root("/TestValidatorConfig");
- BOOST_REQUIRE(saveIdentityCertificate(root, "trust-anchor-6.cert", true));
+ BOOST_REQUIRE(saveIdentityCertificate(addIdentity(root), "trust-anchor-6.cert"));
Name sld("/TestValidatorConfig/HierarchicalChecker");
- BOOST_REQUIRE(addIdentity(sld));
+ addIdentity(sld);
advanceClocks(time::milliseconds(100));
Name sldKeyName = m_keyChain.generateRsaKeyPairAsDefault(sld, true);
shared_ptr<v1::IdentityCertificate> sldCert =
@@ -1144,7 +1144,7 @@
m_keyChain.addCertificateAsIdentityDefault(*sldCert);
Name nld("/TestValidatorConfig/HierarchicalChecker/NextLevel");
- BOOST_REQUIRE(addIdentity(nld));
+ addIdentity(nld);
advanceClocks(time::milliseconds(100));
Name nldKeyName = m_keyChain.generateRsaKeyPairAsDefault(nld, true);
shared_ptr<v1::IdentityCertificate> nldCert =
@@ -1224,10 +1224,10 @@
std::vector<v1::CertificateSubjectDescription> subjectDescription;
Name root("/TestValidatorConfig");
- BOOST_REQUIRE(saveIdentityCertificate(root, "trust-anchor-8.cert", true));
+ BOOST_REQUIRE(saveIdentityCertificate(addIdentity(root), "trust-anchor-8.cert"));
Name sld("/TestValidatorConfig/Nrd-1");
- BOOST_REQUIRE(addIdentity(sld));
+ addIdentity(sld);
advanceClocks(time::milliseconds(100));
Name sldKeyName = m_keyChain.generateRsaKeyPairAsDefault(sld, true);
shared_ptr<v1::IdentityCertificate> sldCert =
@@ -1240,7 +1240,7 @@
m_keyChain.addCertificateAsIdentityDefault(*sldCert);
Name nld("/TestValidatorConfig/Nrd-1/Nrd-2");
- BOOST_REQUIRE(addIdentity(nld));
+ addIdentity(nld);
advanceClocks(time::milliseconds(100));
Name nldKeyName = m_keyChain.generateRsaKeyPairAsDefault(nld, true);
shared_ptr<v1::IdentityCertificate> nldCert =
@@ -1386,13 +1386,13 @@
std::string("trust-anchor-2.cert"));
firstIdentity = Name("/TestValidatorConfig/Dir/First");
- BOOST_REQUIRE(addIdentity(firstIdentity));
+ addIdentity(firstIdentity);
Name firstCertName = m_keyChain.getDefaultCertificateNameForIdentity(firstIdentity);
firstCert = m_keyChain.getCertificate(firstCertName);
io::save(*firstCert, firstCertPath.string());
secondIdentity = Name("/TestValidatorConfig/Dir/Second");
- BOOST_REQUIRE(addIdentity(secondIdentity));
+ addIdentity(secondIdentity);
Name secondCertName = m_keyChain.getDefaultCertificateNameForIdentity(secondIdentity);
secondCert = m_keyChain.getCertificate(secondCertName);
}
@@ -1494,9 +1494,9 @@
: clientFace(io, m_keyChain, {true, true})
, validationResult(boost::logic::indeterminate)
{
- BOOST_REQUIRE(addIdentity(ca));
- BOOST_REQUIRE(saveIdentityCertificate(ca, "trust-anchor-1.cert", true));
- BOOST_REQUIRE(addSubCertificate(user, ca));
+ auto certName = addIdentity(ca);
+ saveIdentityCertificate(certName, "trust-anchor-1.cert");
+ addSubCertificate(user, ca);
userCertName = m_keyChain.getDefaultCertificateNameForIdentity(user);
userCert = m_keyChain.getCertificate(userCertName);
diff --git a/tests/unit-tests/security/validator.t.cpp b/tests/unit-tests/security/validator.t.cpp
index 90bd1b9..0b7cda2 100644
--- a/tests/unit-tests/security/validator.t.cpp
+++ b/tests/unit-tests/security/validator.t.cpp
@@ -50,7 +50,7 @@
{
Name identity("/TestValidator/Null");
identity.appendVersion();
- BOOST_REQUIRE(addIdentity(identity, RsaKeyParams()));
+ addIdentity(identity, RsaKeyParams());
Name dataName = identity;
dataName.append("1");
@@ -94,12 +94,12 @@
BOOST_AUTO_TEST_CASE(RsaSignatureVerification)
{
Name identity("/TestValidator/RsaSignatureVerification");
- BOOST_REQUIRE(addIdentity(identity, RsaKeyParams()));
+ addIdentity(identity, RsaKeyParams());
Name keyName = m_keyChain.getDefaultKeyNameForIdentity(identity);
shared_ptr<v1::PublicKey> publicKey = m_keyChain.getPublicKey(keyName);
Name identity2("/TestValidator/RsaSignatureVerification/id2");
- BOOST_REQUIRE(addIdentity(identity2, RsaKeyParams()));
+ addIdentity(identity2, RsaKeyParams());
Name keyName2 = m_keyChain.getDefaultKeyNameForIdentity(identity2);
shared_ptr<v1::PublicKey> publicKey2 = m_keyChain.getPublicKey(keyName2);
@@ -157,12 +157,12 @@
BOOST_AUTO_TEST_CASE(EcdsaSignatureVerification)
{
Name identity("/TestValidator/EcdsaSignatureVerification");
- BOOST_REQUIRE(addIdentity(identity, EcdsaKeyParams()));
+ addIdentity(identity, EcdsaKeyParams());
Name keyName = m_keyChain.getDefaultKeyNameForIdentity(identity);
shared_ptr<v1::PublicKey> publicKey = m_keyChain.getPublicKey(keyName);
Name identity2("/TestValidator/EcdsaSignatureVerification/id2");
- BOOST_REQUIRE(addIdentity(identity2, EcdsaKeyParams()));
+ addIdentity(identity2, EcdsaKeyParams());
Name keyName2 = m_keyChain.getDefaultKeyNameForIdentity(identity2);
shared_ptr<v1::PublicKey> publicKey2 = m_keyChain.getPublicKey(keyName2);
@@ -192,12 +192,12 @@
BOOST_AUTO_TEST_CASE(EcdsaSignatureVerification2)
{
Name ecdsaIdentity("/SecurityTestValidator/EcdsaSignatureVerification2/ecdsa");
- BOOST_REQUIRE(addIdentity(ecdsaIdentity, EcdsaKeyParams()));
+ addIdentity(ecdsaIdentity, EcdsaKeyParams());
Name ecdsaCertName = m_keyChain.getDefaultCertificateNameForIdentity(ecdsaIdentity);
shared_ptr<v1::IdentityCertificate> ecdsaCert = m_keyChain.getCertificate(ecdsaCertName);
Name rsaIdentity("/SecurityTestValidator/EcdsaSignatureVerification2/rsa");
- BOOST_REQUIRE(addIdentity(rsaIdentity, RsaKeyParams()));
+ addIdentity(rsaIdentity, RsaKeyParams());
Name rsaCertName = m_keyChain.getDefaultCertificateNameForIdentity(rsaIdentity);
shared_ptr<v1::IdentityCertificate> rsaCert = m_keyChain.getCertificate(rsaCertName);
diff --git a/tests/unit-tests/util/io.t.cpp b/tests/unit-tests/util/io.t.cpp
index fcb1f2b..e4dfa63 100644
--- a/tests/unit-tests/util/io.t.cpp
+++ b/tests/unit-tests/util/io.t.cpp
@@ -269,7 +269,7 @@
{
Name identity("/TestIo/IdCert");
identity.appendVersion();
- BOOST_REQUIRE(addIdentity(identity, RsaKeyParams()));
+ addIdentity(identity, RsaKeyParams());
Name certName = m_keyChain.getDefaultCertificateNameForIdentity(identity);
shared_ptr<security::v1::IdentityCertificate> idCert;
BOOST_REQUIRE_NO_THROW(idCert = m_keyChain.getCertificate(certName));
diff --git a/tests/wscript b/tests/wscript
index ad31f19..89a06cc 100644
--- a/tests/wscript
+++ b/tests/wscript
@@ -16,7 +16,7 @@
# core modules that can be shared between unit and integrated tests
bld(features="cxx",
target="boost-tests-base",
- source="key-chain-fixture.cpp identity-management-fixture.cpp",
+ source="identity-management-fixture.cpp",
use='ndn-cxx tests-base BOOST',
includes='.',
install_path=None)