security: avoid parsing PIB and TPM locators multiple times

Change-Id: I2a8831e03d05b499f1f8939e03ea88cb82005743
diff --git a/tests/unit/security/pib/pib-impl.t.cpp b/tests/unit/security/pib/pib-impl.t.cpp
index 3d579c6..d88bad6 100644
--- a/tests/unit/security/pib/pib-impl.t.cpp
+++ b/tests/unit/security/pib/pib-impl.t.cpp
@@ -66,9 +66,8 @@
 BOOST_FIXTURE_TEST_CASE_TEMPLATE(TpmLocator, T, PibImpls, T)
 {
   // Basic getting and setting
-  BOOST_CHECK_NO_THROW(this->pib.getTpmLocator());
-
-  BOOST_CHECK_NO_THROW(this->pib.setTpmLocator("tpmLocator"));
+  BOOST_CHECK_EQUAL(this->pib.getTpmLocator(), "");
+  this->pib.setTpmLocator("tpmLocator");
   BOOST_CHECK_EQUAL(this->pib.getTpmLocator(), "tpmLocator");
 
   // Add cert, and do not change TPM locator
@@ -101,7 +100,6 @@
   // add id1, should be default
   this->pib.addIdentity(this->id1);
   BOOST_CHECK_EQUAL(this->pib.hasIdentity(this->id1), true);
-  BOOST_CHECK_NO_THROW(this->pib.getDefaultIdentity());
   BOOST_CHECK_EQUAL(this->pib.getDefaultIdentity(), this->id1);
 
   // add id2, should not be default
@@ -164,8 +162,7 @@
   BOOST_CHECK_EQUAL(this->pib.hasKey(this->id1Key1Name), true);
   BOOST_CHECK_EQUAL(this->pib.hasIdentity(this->id1), true);
   const Buffer& keyBits = this->pib.getKeyBits(this->id1Key1Name);
-  BOOST_CHECK(keyBits == this->id1Key1);
-  BOOST_CHECK_NO_THROW(this->pib.getDefaultKeyOfIdentity(this->id1));
+  BOOST_TEST(keyBits == this->id1Key1, boost::test_tools::per_element());
   BOOST_CHECK_EQUAL(this->pib.getDefaultKeyOfIdentity(this->id1), this->id1Key1Name);
 
   // add id1Key2, should not be default
@@ -221,7 +218,6 @@
   BOOST_CHECK_EQUAL(this->pib.hasKey(this->id1Key1Name), true);
   BOOST_CHECK_EQUAL(this->pib.getCertificate(this->id1Key1Cert1.getName()).wireEncode(),
                     this->id1Key1Cert1.wireEncode());
-  BOOST_CHECK_NO_THROW(this->pib.getDefaultCertificateOfKey(this->id1Key1Name));
   BOOST_CHECK_EQUAL(this->pib.getDefaultCertificateOfKey(this->id1Key1Name), this->id1Key1Cert1);
 
   // add id1Key1Cert2, should not be default
diff --git a/tests/unit/security/pib/pib.t.cpp b/tests/unit/security/pib/pib.t.cpp
index 929082e..8d668e5 100644
--- a/tests/unit/security/pib/pib.t.cpp
+++ b/tests/unit/security/pib/pib.t.cpp
@@ -38,13 +38,13 @@
 
 BOOST_AUTO_TEST_CASE(TpmLocator)
 {
-  Pib pib("pib-memory", "", make_shared<PibMemory>());
+  Pib pib("pib-memory:", make_shared<PibMemory>());
 
   BOOST_CHECK_EQUAL(pib.getPibLocator(), "pib-memory:");
-  BOOST_CHECK_THROW(pib.getTpmLocator(), Pib::Error);
+  BOOST_CHECK_EQUAL(pib.getTpmLocator(), "");
 
   pib.setTpmLocator("test-tpm-locator");
-  BOOST_CHECK_NO_THROW(pib.getTpmLocator());
+  BOOST_CHECK_EQUAL(pib.getTpmLocator(), "test-tpm-locator");
 
   BOOST_CHECK_THROW(pib.getIdentity(id1), Pib::Error);
   pib.addIdentity(id1);
@@ -52,17 +52,18 @@
 
   pib.setTpmLocator("another-tpm-locator");
   BOOST_CHECK_THROW(pib.getIdentity(id1), Pib::Error);
+  BOOST_CHECK_EQUAL(pib.getTpmLocator(), "another-tpm-locator");
 
   pib.addIdentity(id1);
   BOOST_CHECK_NO_THROW(pib.getIdentity(id1));
   pib.reset();
   BOOST_CHECK_THROW(pib.getIdentity(id1), Pib::Error);
-  BOOST_CHECK_THROW(pib.getTpmLocator(), Pib::Error);
+  BOOST_CHECK_EQUAL(pib.getTpmLocator(), "");
 }
 
 BOOST_AUTO_TEST_CASE(IdentityOperations)
 {
-  Pib pib("pib-memory", "", make_shared<PibMemory>());
+  Pib pib("pib-memory:", make_shared<PibMemory>());
 
   // PIB starts with no identities
   BOOST_CHECK_EQUAL(pib.getIdentities().size(), 0);