mgmt: CommandAuthenticator
refs #2063
Change-Id: I19a82d8d1fdfb3cc5a003166b1a8c1c32bbf24b5
diff --git a/tests/identity-management-fixture.cpp b/tests/identity-management-fixture.cpp
index 1575fa8..3bb7252 100644
--- a/tests/identity-management-fixture.cpp
+++ b/tests/identity-management-fixture.cpp
@@ -24,6 +24,8 @@
*/
#include "identity-management-fixture.hpp"
+#include <ndn-cxx/util/io.hpp>
+#include <boost/filesystem.hpp>
namespace nfd {
namespace tests {
@@ -31,18 +33,23 @@
IdentityManagementFixture::IdentityManagementFixture()
: m_keyChain("sqlite3", "file")
{
- m_keyChain.getDefaultCertificate(); // side effect: creation of the default cert if doesn't exist
+ m_keyChain.getDefaultCertificate(); // side effect: create a default cert if it doesn't exist
}
IdentityManagementFixture::~IdentityManagementFixture()
{
- for (auto&& id : m_identities) {
+ for (const auto& id : m_identities) {
m_keyChain.deleteIdentity(id);
}
+
+ boost::system::error_code ec;
+ for (const auto& certFile : m_certFiles) {
+ boost::filesystem::remove(certFile, ec); // ignore error
+ }
}
bool
-IdentityManagementFixture::addIdentity(const ndn::Name& identity, const ndn::KeyParams& params)
+IdentityManagementFixture::addIdentity(const Name& identity, const ndn::KeyParams& params)
{
try {
m_keyChain.createIdentity(identity, params);
@@ -54,5 +61,29 @@
}
}
+bool
+IdentityManagementFixture::saveIdentityCertificate(const Name& identity, const std::string& filename, bool wantAdd)
+{
+ shared_ptr<ndn::IdentityCertificate> cert;
+ try {
+ cert = m_keyChain.getCertificate(m_keyChain.getDefaultCertificateNameForIdentity(identity));
+ }
+ catch (const ndn::SecPublicInfo::Error&) {
+ if (wantAdd && this->addIdentity(identity)) {
+ return this->saveIdentityCertificate(identity, filename, false);
+ }
+ return false;
+ }
+
+ m_certFiles.push_back(filename);
+ try {
+ ndn::io::save(*cert, filename);
+ return true;
+ }
+ catch (const ndn::io::Error&) {
+ return false;
+ }
+}
+
} // namespace tests
} // namespace nfd