Add unit test for certificate delete
Change-Id: Id0f5b4890dc522894f7c30597c8095338599cbdf
Signed-off-by: Marri Devender Rao <devenrao@in.ibm.com>
diff --git a/test/certs_manager_test.cpp b/test/certs_manager_test.cpp
index ee03229..f1a7587 100644
--- a/test/certs_manager_test.cpp
+++ b/test/certs_manager_test.cpp
@@ -96,6 +96,10 @@
{
manager->install(path);
}
+ void delete_()
+ {
+ manager->delete_();
+ }
phosphor::certs::Manager* manager;
};
@@ -276,6 +280,45 @@
EXPECT_FALSE(fs::exists(verifyPath));
}
+/** @brief Test deletion of installed certificate file
+ */
+class MockReloadReset : public phosphor::certs::Manager
+{
+ public:
+ MockReloadReset(sdbusplus::bus::bus& bus, const char* path,
+ std::string& type, std::string&& unit,
+ std::string&& certPath) :
+ Manager(bus, path, type, std::forward<std::string>(unit),
+ std::forward<std::string>(certPath))
+ {
+ }
+ virtual ~MockReloadReset()
+ {
+ }
+
+ MOCK_METHOD1(reloadOrReset, void(const std::string& unit));
+};
+TEST_F(TestCertsManager, TestDeleteCertificate)
+{
+ std::string endpoint("ldap");
+ std::string unit("nslcd.service");
+ std::string type("client");
+ std::string path(certDir + "/" + certificateFile);
+ std::string verifyPath(path);
+ std::string verifyUnit(unit);
+ auto objPath = std::string(OBJPATH) + '/' + type + '/' + endpoint;
+ MockReloadReset manager(bus, objPath.c_str(), type, std::move(unit),
+ std::move(path));
+ EXPECT_CALL(manager, reloadOrReset(verifyUnit)).Times(2);
+ MainApp mainApp(&manager);
+ EXPECT_NO_THROW({ mainApp.install(certificateFile); });
+ EXPECT_TRUE(fs::exists(verifyPath));
+
+ // delete certificate file and verify file is deleted
+ mainApp.delete_();
+ EXPECT_FALSE(fs::exists(verifyPath));
+}
+
/**
* Class to generate private and certificate only file and test verification
*/
@@ -380,4 +423,4 @@
},
InvalidCertificate);
EXPECT_FALSE(fs::exists(verifyPath));
-}
\ No newline at end of file
+}