security: tolerate invalid or unsupported public keys in PIB

Change-Id: I3c1dd9d3fe81d0895e2d1706f0b29a8e61940beb
diff --git a/tests/unit/security/pib/impl/identity-impl.t.cpp b/tests/unit/security/pib/impl/identity-impl.t.cpp
index b7701aa..3f38e0e 100644
--- a/tests/unit/security/pib/impl/identity-impl.t.cpp
+++ b/tests/unit/security/pib/impl/identity-impl.t.cpp
@@ -46,7 +46,7 @@
 
 BOOST_AUTO_TEST_CASE(Properties)
 {
-  BOOST_CHECK_EQUAL(identity1.getName(), id1);
+  BOOST_TEST(identity1.getName() == id1);
 }
 
 BOOST_AUTO_TEST_CASE(KeyOperations)
@@ -128,7 +128,6 @@
 
 BOOST_AUTO_TEST_CASE(Errors)
 {
-  identity1.addKey(id1Key1, id1Key1Name);
   BOOST_CHECK_THROW(identity1.addKey(id2Key1, id2Key1Name), std::invalid_argument);
   BOOST_CHECK_THROW(identity1.removeKey(id2Key1Name), std::invalid_argument);
   BOOST_CHECK_THROW(identity1.getKey(id2Key1Name), std::invalid_argument);
diff --git a/tests/unit/security/pib/impl/key-impl.t.cpp b/tests/unit/security/pib/impl/key-impl.t.cpp
index 2f883a5..4cb960a 100644
--- a/tests/unit/security/pib/impl/key-impl.t.cpp
+++ b/tests/unit/security/pib/impl/key-impl.t.cpp
@@ -47,9 +47,9 @@
 
 BOOST_AUTO_TEST_CASE(Properties)
 {
-  BOOST_CHECK_EQUAL(key11.getIdentity(), id1);
-  BOOST_CHECK_EQUAL(key11.getName(), id1Key1Name);
-  BOOST_CHECK_EQUAL(key11.getKeyType(), KeyType::EC);
+  BOOST_TEST(key11.getIdentity() == id1);
+  BOOST_TEST(key11.getName() == id1Key1Name);
+  BOOST_TEST(key11.getKeyType() == KeyType::EC);
   BOOST_TEST(key11.getPublicKey() == id1Key1, boost::test_tools::per_element());
 }
 
@@ -138,11 +138,9 @@
 
 BOOST_AUTO_TEST_CASE(Errors)
 {
+  // illegal key name
   BOOST_CHECK_THROW(KeyImpl(Name("/wrong"), id1Key1, pibImpl), std::invalid_argument);
 
-  Buffer invalidKey;
-  BOOST_CHECK_THROW(KeyImpl(id1Key1Name, invalidKey, pibImpl), std::invalid_argument);
-
   BOOST_CHECK_THROW(key11.addCertificate(id1Key2Cert1), std::invalid_argument);
   BOOST_CHECK_THROW(key11.removeCertificate(id1Key2Cert1.getName()), std::invalid_argument);
   BOOST_CHECK_THROW(key11.getCertificate(id1Key2Cert1.getName()), std::invalid_argument);
@@ -150,6 +148,19 @@
   BOOST_CHECK_THROW(key11.setDefaultCertificate(id1Key2Cert1.getName()), std::invalid_argument);
 }
 
+BOOST_AUTO_TEST_CASE(UnknownKeyType)
+{
+  Name keyName = security::constructKeyName(id1, name::Component::fromEscapedString("foo"));
+  Buffer invalidKey{0x01, 0x02, 0x03, 0x04};
+  pibImpl->addKey(id1, keyName, invalidKey);
+
+  KeyImpl unknown(keyName, invalidKey, pibImpl);
+  BOOST_TEST(unknown.getIdentity() == id1);
+  BOOST_TEST(unknown.getName() == keyName);
+  BOOST_TEST(unknown.getKeyType() == KeyType::NONE);
+  BOOST_TEST(unknown.getPublicKey() == invalidKey, boost::test_tools::per_element());
+}
+
 BOOST_AUTO_TEST_SUITE_END() // TestKeyImpl
 BOOST_AUTO_TEST_SUITE_END() // Pib
 BOOST_AUTO_TEST_SUITE_END() // Security