security: Fix a bug of Validator, making checkPolicy methods pure abstract

This commit also includes fixes to unit tests.

Change-Id: If92569fc9dabaa08714d458e5195b6a83acb8701
diff --git a/tests/test-sec-public-info-sqlite3.cpp b/tests/test-sec-public-info-sqlite3.cpp
index 6e684e9..c1c5d57 100644
--- a/tests/test-sec-public-info-sqlite3.cpp
+++ b/tests/test-sec-public-info-sqlite3.cpp
@@ -11,6 +11,7 @@
 #include <boost/test/unit_test.hpp>
 
 #include "security/key-chain.hpp"
+#include "util/time.hpp"
 
 using namespace std;
 namespace ndn {
@@ -21,14 +22,19 @@
 {
   KeyChainImpl<SecPublicInfoSqlite3, SecTpmFile> keyChain;
 
-  Name identity("/tmp");
+  Name identity(string("/TestSecPublicInfoSqlite3/Delete/") + boost::lexical_cast<string>(time::now()));
   Name certName1 = keyChain.createIdentity(identity);
   Name keyName1 = IdentityCertificate::certificateNameToPublicKeyName(certName1);  
-  Name keyName2 = keyChain.generateRSAKeyPairAsDefault(identity);
+  Name keyName2;
+  BOOST_CHECK_NO_THROW(keyName2 = keyChain.generateRSAKeyPairAsDefault(identity));
+  
   ptr_lib::shared_ptr<IdentityCertificate> cert2 = keyChain.selfSign(keyName2);
   Name certName2 = cert2->getName();
   keyChain.addCertificateAsKeyDefault(*cert2);
-  Name keyName3 = keyChain.generateRSAKeyPairAsDefault(identity);
+  
+  Name keyName3;
+  BOOST_CHECK_NO_THROW(keyName3 = keyChain.generateRSAKeyPairAsDefault(identity));
+  
   ptr_lib::shared_ptr<IdentityCertificate> cert3 = keyChain.selfSign(keyName3);
   Name certName3 = cert3->getName();
   keyChain.addCertificateAsKeyDefault(*cert3);
diff --git a/tests/test-sec-tpm-file.cpp b/tests/test-sec-tpm-file.cpp
index a81b794..51ecbe2 100644
--- a/tests/test-sec-tpm-file.cpp
+++ b/tests/test-sec-tpm-file.cpp
@@ -23,7 +23,7 @@
   SecTpmFile tpm;
   
   Name keyName("/tmp/ksk-123456");
-  tpm.generateKeyPairInTpm(keyName, KEY_TYPE_RSA, 2048);
+  BOOST_CHECK_NO_THROW(tpm.generateKeyPairInTpm(keyName, KEY_TYPE_RSA, 2048));
   
   BOOST_REQUIRE_EQUAL(tpm.doesKeyExistInTpm(keyName, KEY_CLASS_PUBLIC), true);
   BOOST_REQUIRE_EQUAL(tpm.doesKeyExistInTpm(keyName, KEY_CLASS_PRIVATE), true);
@@ -39,7 +39,7 @@
   SecTpmFile tpm;
 
   Name keyName("/tmp/ksk-123456");
-  tpm.generateKeyPairInTpm(keyName, KEY_TYPE_RSA, 2048);
+  BOOST_CHECK_NO_THROW(tpm.generateKeyPairInTpm(keyName, KEY_TYPE_RSA, 2048));
   
   Data data("/tmp/test/1");
   const uint8_t content[] = {0x01, 0x02, 0x03, 0x04};
diff --git a/tests/test-sec-tpm-osx.cpp b/tests/test-sec-tpm-osx.cpp
index 9e0f29f..5bd0467 100644
--- a/tests/test-sec-tpm-osx.cpp
+++ b/tests/test-sec-tpm-osx.cpp
@@ -23,7 +23,7 @@
   SecTpmOsx tpm;
   
   Name keyName("/tmp/ksk-123456");
-  tpm.generateKeyPairInTpm(keyName, KEY_TYPE_RSA, 2048);
+  BOOST_CHECK_NO_THROW(tpm.generateKeyPairInTpm(keyName, KEY_TYPE_RSA, 2048));
   
   BOOST_REQUIRE_EQUAL(tpm.doesKeyExistInTpm(keyName, KEY_CLASS_PUBLIC), true);
   BOOST_REQUIRE_EQUAL(tpm.doesKeyExistInTpm(keyName, KEY_CLASS_PRIVATE), true);
@@ -39,7 +39,7 @@
   SecTpmOsx tpm;
 
   Name keyName("/tmp/ksk-123456");
-  tpm.generateKeyPairInTpm(keyName, KEY_TYPE_RSA, 2048);
+  BOOST_CHECK_NO_THROW(tpm.generateKeyPairInTpm(keyName, KEY_TYPE_RSA, 2048));
   
   Data data("/tmp/test/1");
   const uint8_t content[] = {0x01, 0x02, 0x03, 0x04};
diff --git a/tests/test-validator.cpp b/tests/test-validator.cpp
new file mode 100644
index 0000000..1b24a3d
--- /dev/null
+++ b/tests/test-validator.cpp
@@ -0,0 +1,51 @@
+/**
+ * Copyright (C) 2013 Regents of the University of California.
+ * @author: Yingdi Yu <yingdi0@cs.ucla.edu>
+ * See COPYING for copyright and distribution information.
+ */
+
+#include <boost/test/unit_test.hpp>
+
+#include "security/validator-null.hpp"
+#include "security/key-chain.hpp"
+#include "util/time.hpp"
+
+
+using namespace std;
+
+namespace ndn {
+
+BOOST_AUTO_TEST_SUITE(TestValidator)
+
+void
+onValidated(const shared_ptr<const Data>& data)
+{ BOOST_CHECK(true); }
+
+void
+onValidationFailed(const shared_ptr<const Data>& data)
+{ BOOST_CHECK(false); }
+
+BOOST_AUTO_TEST_CASE (Null)
+{
+  KeyChainImpl<SecPublicInfoSqlite3, SecTpmFile> keyChain;
+  Name identity(string("/TestValidator/Null/") + boost::lexical_cast<std::string>(time::now()));
+  keyChain.createIdentity(identity);
+
+  Name dataName = identity;
+  dataName.append("1");
+  shared_ptr<Data> data = make_shared<Data>(dataName);
+
+  keyChain.signByIdentity(*data, identity);
+  
+  ValidatorNull validator;
+  
+  validator.validate(data,
+		     bind(&onValidated, _1),
+		     bind(&onValidationFailed, _1));
+
+  keyChain.deleteIdentity(identity);
+}
+
+BOOST_AUTO_TEST_SUITE_END()
+
+} // namespace ndn