security: Validator::verifySignature don't throw on Interest with malformed signature
refs #3723
Change-Id: I7de6ab667ffbcc531a5ea8bccae1551e1699cefd
diff --git a/tests/unit-tests/security/command-interest-validator.t.cpp b/tests/unit-tests/security/command-interest-validator.t.cpp
index 6173274..9a9d1e8 100644
--- a/tests/unit-tests/security/command-interest-validator.t.cpp
+++ b/tests/unit-tests/security/command-interest-validator.t.cpp
@@ -112,16 +112,6 @@
unique_ptr<CommandInterestValidator> validator;
};
-template<typename...A>
-void
-setNameComponent(Name& name, ssize_t index, const A& ...a)
-{
- Name name2 = name.getPrefix(index);
- name2.append(name::Component(a...));
- name2.append(name.getSubName(index + 1));
- name = name2;
-}
-
BOOST_AUTO_TEST_SUITE(Security)
BOOST_FIXTURE_TEST_SUITE(TestCommandInterestValidator, CommandInterestValidatorFixture)
@@ -162,57 +152,47 @@
BOOST_AUTO_TEST_CASE(BadTimestamp)
{
auto i1 = makeCommandInterest();
- Name n1 = i1->getName();
- setNameComponent(n1, signed_interest::POS_TIMESTAMP, "not-timestamp");
- i1->setName(n1);
+ setNameComponent(*i1, signed_interest::POS_TIMESTAMP, "not-timestamp");
assertReject(*i1, CommandInterestValidator::ErrorCode::BAD_TIMESTAMP);
}
BOOST_AUTO_TEST_CASE(BadSigInfo)
{
auto i1 = makeCommandInterest();
- Name n1 = i1->getName();
- setNameComponent(n1, signed_interest::POS_SIG_INFO, "not-SignatureInfo");
- i1->setName(n1);
+ setNameComponent(*i1, signed_interest::POS_SIG_INFO, "not-SignatureInfo");
assertReject(*i1, CommandInterestValidator::ErrorCode::BAD_SIG_INFO);
}
BOOST_AUTO_TEST_CASE(MissingKeyLocator)
{
auto i1 = makeCommandInterest();
- Name n1 = i1->getName();
SignatureInfo sigInfo;
- setNameComponent(n1, signed_interest::POS_SIG_INFO,
+ setNameComponent(*i1, signed_interest::POS_SIG_INFO,
sigInfo.wireEncode().begin(), sigInfo.wireEncode().end());
- i1->setName(n1);
assertReject(*i1, CommandInterestValidator::ErrorCode::MISSING_KEY_LOCATOR);
}
BOOST_AUTO_TEST_CASE(BadKeyLocatorType)
{
auto i1 = makeCommandInterest();
- Name n1 = i1->getName();
KeyLocator kl;
kl.setKeyDigest(makeBinaryBlock(tlv::KeyDigest, "\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD", 8));
SignatureInfo sigInfo;
sigInfo.setKeyLocator(kl);
- setNameComponent(n1, signed_interest::POS_SIG_INFO,
+ setNameComponent(*i1, signed_interest::POS_SIG_INFO,
sigInfo.wireEncode().begin(), sigInfo.wireEncode().end());
- i1->setName(n1);
assertReject(*i1, CommandInterestValidator::ErrorCode::BAD_KEY_LOCATOR_TYPE);
}
BOOST_AUTO_TEST_CASE(BadCertName)
{
auto i1 = makeCommandInterest();
- Name n1 = i1->getName();
KeyLocator kl;
kl.setName("/bad/cert/name");
SignatureInfo sigInfo;
sigInfo.setKeyLocator(kl);
- setNameComponent(n1, signed_interest::POS_SIG_INFO,
+ setNameComponent(*i1, signed_interest::POS_SIG_INFO,
sigInfo.wireEncode().begin(), sigInfo.wireEncode().end());
- i1->setName(n1);
assertReject(*i1, CommandInterestValidator::ErrorCode::BAD_CERT_NAME);
}
@@ -265,12 +245,9 @@
auto i1 = makeCommandInterest(); // signed at 0s
assertAccept(*i1);
- auto i2 = makeCommandInterest();
- Name n1 = i1->getName();
- Name n2 = i2->getName();
- setNameComponent(n2, signed_interest::POS_TIMESTAMP,
- n1[signed_interest::POS_TIMESTAMP]);
- i2->setName(n2); // signed at 0s
+ auto i2 = makeCommandInterest(); // signed at 0s
+ setNameComponent(*i2, signed_interest::POS_TIMESTAMP,
+ i1->getName()[signed_interest::POS_TIMESTAMP]);
assertReject(*i2, CommandInterestValidator::ErrorCode::TIMESTAMP_REORDER);
advanceClocks(time::seconds(2));
@@ -320,10 +297,8 @@
auto i1 = makeCommandInterest(1); // signed at 0ms
auto i2 = makeCommandInterest(2); // signed at 0ms
for (auto interest : {i1, i2}) {
- Name name = interest->getName();
- setNameComponent(name, signed_interest::POS_TIMESTAMP,
+ setNameComponent(*interest, signed_interest::POS_TIMESTAMP,
name::Component::fromNumber(time::toUnixTimestamp(time::system_clock::now()).count()));
- interest->setName(name);
} // ensure timestamps are exactly 0ms
assertAccept(*i1); // verifying at 0ms