tests: migrate from DummyForwarder to DummyClientFace::linkTo()
Change-Id: I8d88ffd632468965689b44026ebe34a36f32e7a2
diff --git a/tests/dummy-forwarder.cpp b/tests/dummy-forwarder.cpp
deleted file mode 100644
index 5d53ff1..0000000
--- a/tests/dummy-forwarder.cpp
+++ /dev/null
@@ -1,79 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/**
- * Copyright (c) 2014-2018, Regents of the University of California
- *
- * NAC 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.
- *
- * NAC 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 NAC library authors and contributors.
- */
-
-#include "dummy-forwarder.hpp"
-
-#include <boost/asio/io_service.hpp>
-
-namespace ndn {
-namespace nac {
-namespace tests {
-
-DummyForwarder::DummyForwarder(boost::asio::io_service& io, KeyChain& keyChain)
- : m_io(io)
- , m_keyChain(keyChain)
-{
-}
-
-Face&
-DummyForwarder::addFace()
-{
- auto face = std::make_shared<util::DummyClientFace>(m_io, m_keyChain,
- util::DummyClientFace::Options{true, true});
- std::weak_ptr<Face> weakFace(face);
- face->onSendInterest.connect([this, weakFace] (const Interest& interest) {
- if (auto face = weakFace.lock()) {
- for (auto& otherFace : m_faces) {
- if (&*face == &*otherFace) {
- continue;
- }
- otherFace->receive(interest);
- }
- }
- });
-
- face->onSendData.connect([this, weakFace] (const Data& data) {
- if (auto face = weakFace.lock()) {
- for (auto& otherFace : m_faces) {
- if (&*face == &*otherFace) {
- continue;
- }
- otherFace->receive(data);
- }
- }
- });
-
- face->onSendNack.connect([this, weakFace] (const lp::Nack& nack) {
- if (auto face = weakFace.lock()) {
- for (auto& otherFace : m_faces) {
- if (&*face == &*otherFace) {
- continue;
- }
- otherFace->receive(nack);
- }
- }
- });
-
- m_faces.push_back(face);
- return *face;
-}
-
-} // namespace tests
-} // namespace nac
-} // namespace ndn
diff --git a/tests/dummy-forwarder.hpp b/tests/dummy-forwarder.hpp
deleted file mode 100644
index e4f5fd8..0000000
--- a/tests/dummy-forwarder.hpp
+++ /dev/null
@@ -1,63 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/**
- * Copyright (c) 2014-2018, Regents of the University of California
- *
- * NAC 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.
- *
- * NAC 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 NAC library authors and contributors.
- */
-
-#include <ndn-cxx/interest.hpp>
-#include <ndn-cxx/data.hpp>
-#include <ndn-cxx/lp/nack.hpp>
-#include <ndn-cxx/util/dummy-client-face.hpp>
-#include <ndn-cxx/security/key-chain.hpp>
-
-#ifndef NAC_TESTS_TEST_DUMMY_FORWARDER_HPP
-#define NAC_TESTS_TEST_DUMMY_FORWARDER_HPP
-
-namespace ndn {
-namespace nac {
-namespace tests {
-
-/**
- * @brief Very basic implementation of the dummy forwarder
- *
- * Interests expressed by any added face, will be forwarded to all other faces.
- * Similarly, any pushed data, will be pushed to all other faces.
- */
-class DummyForwarder
-{
-public:
- DummyForwarder(boost::asio::io_service& io, KeyChain& keyChain);
-
- Face&
- addFace();
-
- Face&
- getFace(size_t nFace)
- {
- return *m_faces.at(nFace);
- }
-
-private:
- boost::asio::io_service& m_io;
- KeyChain& m_keyChain;
- std::vector<shared_ptr<util::DummyClientFace>> m_faces;
-};
-
-} // namespace tests
-} // namespace nac
-} // namespace ndn
-
-#endif // NAC_TESTS_TEST_DUMMY_FORWARDER_HPP
diff --git a/tests/unit/access-manager.t.cpp b/tests/unit/access-manager.t.cpp
index 13902e8..d15249f 100644
--- a/tests/unit/access-manager.t.cpp
+++ b/tests/unit/access-manager.t.cpp
@@ -20,10 +20,10 @@
#include "access-manager.hpp"
#include "tests/boost-test.hpp"
-#include "tests/dummy-forwarder.hpp"
#include "tests/io-key-chain-fixture.hpp"
#include <iostream>
+#include <ndn-cxx/util/dummy-client-face.hpp>
#include <ndn-cxx/util/string-helper.hpp>
namespace ndn {
@@ -34,8 +34,7 @@
{
public:
AccessManagerFixture()
- : fw(m_io, m_keyChain)
- , face(static_cast<util::DummyClientFace&>(fw.addFace()))
+ : face(m_io, m_keyChain, {true, true})
, accessIdentity(m_keyChain.createIdentity("/access/policy/identity"))
, nacIdentity(m_keyChain.createIdentity("/access/policy/identity/NAC/dataset", // hack to get access to KEK key-id
RsaKeyParams()))
@@ -51,8 +50,7 @@
}
public:
- DummyForwarder fw;
- util::DummyClientFace& face;
+ util::DummyClientFace face;
Identity accessIdentity;
Identity nacIdentity;
std::vector<Identity> userIdentities;
diff --git a/tests/unit/decryptor.t.cpp b/tests/unit/decryptor.t.cpp
index e7c2a0f..1aeedbc 100644
--- a/tests/unit/decryptor.t.cpp
+++ b/tests/unit/decryptor.t.cpp
@@ -19,17 +19,17 @@
#include "decryptor.hpp"
-#include "encryptor.hpp"
-#include "encrypted-content.hpp"
#include "access-manager.hpp"
+#include "encrypted-content.hpp"
+#include "encryptor.hpp"
#include "tests/boost-test.hpp"
-#include "tests/dummy-forwarder.hpp"
#include "tests/io-key-chain-fixture.hpp"
#include "tests/unit/static-data.hpp"
#include <iostream>
#include <boost/mpl/vector.hpp>
+#include <ndn-cxx/util/dummy-client-face.hpp>
namespace ndn {
namespace nac {
@@ -39,25 +39,22 @@
{
public:
DecryptorStaticDataEnvironment()
- : fw(m_io, m_keyChain)
- , imsFace(static_cast<util::DummyClientFace&>(fw.addFace()))
{
StaticData data;
for (const auto& block : data.managerPackets) {
m_ims.insert(*make_shared<Data>(block));
}
-
for (const auto& block : data.encryptorPackets) {
m_ims.insert(*make_shared<Data>(block));
}
- auto serveFromIms = [this] (const Name& prefix, const Interest& interest) {
+ auto serveFromIms = [this] (const Name&, const Interest& interest) {
auto data = m_ims.find(interest);
if (data != nullptr) {
- imsFace.put(*data);
+ m_imsFace.put(*data);
}
};
- imsFace.setInterestFilter("/", serveFromIms, [] (auto...) {});
+ m_imsFace.setInterestFilter("/", serveFromIms, [] (auto...) {});
advanceClocks(1_ms, 10);
// import "/first/user" identity
@@ -67,9 +64,10 @@
m_keyChain.createIdentity("/not/authorized");
}
-public:
- DummyForwarder fw;
- util::DummyClientFace& imsFace;
+protected:
+ util::DummyClientFace m_imsFace{m_io, m_keyChain, {false, true}};
+
+private:
InMemoryStoragePersistent m_ims;
};
@@ -78,14 +76,15 @@
{
public:
DecryptorFixture()
- : face(static_cast<util::DummyClientFace&>(fw.addFace()))
+ : face(m_io, m_keyChain, {false, true})
, decryptor(m_keyChain.getPib().getIdentity(T().identity).getDefaultKey(), validator, m_keyChain, face)
{
+ face.linkTo(m_imsFace);
advanceClocks(1_ms, 10);
}
public:
- util::DummyClientFace& face;
+ util::DummyClientFace face;
ValidatorNull validator;
Decryptor decryptor;
};
diff --git a/tests/unit/encryptor.t.cpp b/tests/unit/encryptor.t.cpp
index dcbf579..9439fcc 100644
--- a/tests/unit/encryptor.t.cpp
+++ b/tests/unit/encryptor.t.cpp
@@ -20,11 +20,11 @@
#include "encryptor.hpp"
#include "tests/boost-test.hpp"
-#include "tests/dummy-forwarder.hpp"
#include "tests/io-key-chain-fixture.hpp"
#include "tests/unit/static-data.hpp"
#include <iostream>
+#include <ndn-cxx/util/dummy-client-face.hpp>
#include <ndn-cxx/util/string-helper.hpp>
namespace ndn {
@@ -35,8 +35,6 @@
{
public:
EncryptorStaticDataEnvironment(bool shouldPublishData)
- : fw(m_io, m_keyChain)
- , imsFace(static_cast<util::DummyClientFace&>(fw.addFace()))
{
if (shouldPublishData) {
publishData();
@@ -45,14 +43,14 @@
auto serveFromIms = [this] (const Name&, const Interest& interest) {
auto data = m_ims.find(interest);
if (data != nullptr) {
- imsFace.put(*data);
+ m_imsFace.put(*data);
}
};
- imsFace.setInterestFilter("/", serveFromIms, [] (auto...) {});
+ m_imsFace.setInterestFilter("/", serveFromIms, [] (auto...) {});
advanceClocks(1_ms, 10);
- imsFace.sentData.clear();
- imsFace.sentInterests.clear();
+ m_imsFace.sentData.clear();
+ m_imsFace.sentInterests.clear();
}
void
@@ -65,9 +63,10 @@
advanceClocks(1_ms, 10);
}
-public:
- DummyForwarder fw;
- util::DummyClientFace& imsFace;
+protected:
+ util::DummyClientFace m_imsFace{m_io, m_keyChain, {true, true}};
+
+private:
InMemoryStoragePersistent m_ims;
};
@@ -77,18 +76,19 @@
public:
EncryptorFixture()
: EncryptorStaticDataEnvironment(shouldPublishData)
- , face(static_cast<util::DummyClientFace&>(fw.addFace()))
+ , face(m_io, m_keyChain, {true, true})
, encryptor("/access/policy/identity/NAC/dataset", "/some/ck/prefix", signingWithSha256(),
[=] (const ErrorCode& code, const std::string& error) {
onFailure(code, error);
},
validator, m_keyChain, face)
{
+ face.linkTo(m_imsFace);
advanceClocks(1_ms, 10);
}
public:
- util::DummyClientFace& face;
+ util::DummyClientFace face;
ValidatorNull validator;
Encryptor encryptor;
util::Signal<EncryptorFixture, ErrorCode, std::string> onFailure;
@@ -121,7 +121,7 @@
BOOST_CHECK_EQUAL(face.sentInterests.at(0).getName().getPrefix(6),
Name("/access/policy/identity/NAC/dataset/KEK"));
- auto kek = imsFace.sentData.at(0);
+ auto kek = m_imsFace.sentData.at(0);
BOOST_CHECK_EQUAL(kek.getName().getPrefix(6), Name("/access/policy/identity/NAC/dataset/KEK"));
BOOST_CHECK_EQUAL(kek.getName().size(), 7);
@@ -155,15 +155,15 @@
BOOST_CHECK_EQUAL(face.sentInterests.at(0).getName().getPrefix(6), Name("/access/policy/identity/NAC/dataset/KEK"));
// and failed
- BOOST_CHECK_EQUAL(imsFace.sentData.size(), 0);
+ BOOST_CHECK_EQUAL(m_imsFace.sentData.size(), 0);
advanceClocks(1_s, 13); // 4_s default interest lifetime x 3
BOOST_CHECK_EQUAL(nErrors, 1);
- BOOST_CHECK_EQUAL(imsFace.sentData.size(), 0);
+ BOOST_CHECK_EQUAL(m_imsFace.sentData.size(), 0);
advanceClocks(1_s, 730); // 60 seconds between attempts + ~12 seconds for each attempt
BOOST_CHECK_EQUAL(nErrors, 11);
- BOOST_CHECK_EQUAL(imsFace.sentData.size(), 0);
+ BOOST_CHECK_EQUAL(m_imsFace.sentData.size(), 0);
// check recovery
@@ -171,7 +171,7 @@
advanceClocks(1_s, 73);
- auto kek = imsFace.sentData.at(0);
+ auto kek = m_imsFace.sentData.at(0);
BOOST_CHECK_EQUAL(kek.getName().getPrefix(6), Name("/access/policy/identity/NAC/dataset/KEK"));
BOOST_CHECK_EQUAL(kek.getName().size(), 7);
}