firmware: add sdbusplus for use by verification

The verification process starts a systemd service implemented outside
the scope of this codebase.  Therefore, add sdbusplus to the build and
inject into the object.

Change-Id: Icaacb5d60334da78f6363682f3b97714eb482dcf
Signed-off-by: Patrick Venture <venture@google.com>
diff --git a/Makefile.am b/Makefile.am
index 3d0d93c..100ba92 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -11,9 +11,11 @@
 	lpc_aspeed.cpp \
 	lpc_nuvoton.cpp
 libfirmwareblob_la_LDFLAGS = \
+	$(SDBUSPLUS_LIBS) \
 	$(PHOSPHOR_LOGGING_LIBS) \
 	-version-info 0:0:0 -shared
 libfirmwareblob_la_CXXFLAGS = \
+	$(SDBUSPLUS_CFLAGS) \
 	$(PHOSPHOR_LOGGING_CFLAGS) \
 	-flto
 
diff --git a/configure.ac b/configure.ac
index c19c858..020357b 100644
--- a/configure.ac
+++ b/configure.ac
@@ -20,6 +20,7 @@
 LT_INIT # Required for systemd linking
 
 # Checks for libraries.
+PKG_CHECK_MODULES([SDBUSPLUS], [sdbusplus], ,[AC_MSG_ERROR([The openbmc/sdbusplus package is required])])
 PKG_CHECK_MODULES([PHOSPHOR_LOGGING], [phosphor-logging],, [AC_MSG_ERROR([Could not find phosphor-logging...openbmc/phosphor-logging package required])])
 AC_CHECK_HEADER([blobs-ipmid], [AC_MSG_ERROR(["phosphor-ipmi-blobs required and not found."])])
 AX_PTHREAD([], [AC_MSG_ERROR(["pthread required and not found"])])
diff --git a/firmware_handler.cpp b/firmware_handler.cpp
index 74328f3..c6c7fa5 100644
--- a/firmware_handler.cpp
+++ b/firmware_handler.cpp
@@ -36,7 +36,7 @@
 
 std::unique_ptr<GenericBlobInterface>
     FirmwareBlobHandler::CreateFirmwareBlobHandler(
-        const std::vector<HandlerPack>& firmwares,
+        sdbusplus::bus::bus&& bus, const std::vector<HandlerPack>& firmwares,
         const std::vector<DataHandlerPack>& transports)
 {
     /* There must be at least one. */
@@ -68,8 +68,8 @@
         bitmask |= item.bitmask;
     }
 
-    return std::make_unique<FirmwareBlobHandler>(firmwares, blobs, transports,
-                                                 bitmask);
+    return std::make_unique<FirmwareBlobHandler>(std::move(bus), firmwares,
+                                                 blobs, transports, bitmask);
 }
 
 /* Check if the path is in our supported list (or active list). */
diff --git a/firmware_handler.hpp b/firmware_handler.hpp
index 36faa05..897606c 100644
--- a/firmware_handler.hpp
+++ b/firmware_handler.hpp
@@ -7,6 +7,7 @@
 #include <cstdint>
 #include <map>
 #include <memory>
+#include <sdbusplus/bus.hpp>
 #include <string>
 #include <vector>
 
@@ -105,34 +106,38 @@
     /**
      * Create a FirmwareBlobHandler.
      *
+     * @param[in] bus - an sdbusplus handler for a bus to use.
      * @param[in] firmwares - list of firmware blob_ids to support.
      * @param[in] transports - list of transports to support.
      */
     static std::unique_ptr<GenericBlobInterface> CreateFirmwareBlobHandler(
-        const std::vector<HandlerPack>& firmwares,
+        sdbusplus::bus::bus&& bus, const std::vector<HandlerPack>& firmwares,
         const std::vector<DataHandlerPack>& transports);
 
     /**
      * Create a FirmwareBlobHandler.
      *
+     * @param[in] bus - an sdbusplus handler for a bus to use
      * @param[in] firmwares - list of firmware types and their handlers
      * @param[in] blobs - list of blobs_ids to support
      * @param[in] transports - list of transport types and their handlers
      * @param[in] bitmask - bitmask of transports to support
      */
-    FirmwareBlobHandler(const std::vector<HandlerPack>& firmwares,
+    FirmwareBlobHandler(sdbusplus::bus::bus&& bus,
+                        const std::vector<HandlerPack>& firmwares,
                         const std::vector<std::string>& blobs,
                         const std::vector<DataHandlerPack>& transports,
                         std::uint16_t bitmask) :
-        handlers(firmwares),
-        blobIDs(blobs), transports(transports), bitmask(bitmask),
-        activeImage(activeImageBlobID), activeHash(activeHashBlobID),
-        verifyImage(verifyBlobID), lookup(), state(UpdateState::notYetStarted)
+        bus(std::move(bus)),
+        handlers(firmwares), blobIDs(blobs), transports(transports),
+        bitmask(bitmask), activeImage(activeImageBlobID),
+        activeHash(activeHashBlobID), verifyImage(verifyBlobID), lookup(),
+        state(UpdateState::notYetStarted)
     {
     }
     ~FirmwareBlobHandler() = default;
-    FirmwareBlobHandler(const FirmwareBlobHandler&) = default;
-    FirmwareBlobHandler& operator=(const FirmwareBlobHandler&) = default;
+    FirmwareBlobHandler(const FirmwareBlobHandler&) = delete;
+    FirmwareBlobHandler& operator=(const FirmwareBlobHandler&) = delete;
     FirmwareBlobHandler(FirmwareBlobHandler&&) = default;
     FirmwareBlobHandler& operator=(FirmwareBlobHandler&&) = default;
 
@@ -167,6 +172,8 @@
     };
 
   private:
+    sdbusplus::bus::bus bus;
+
     /** List of handlers by type. */
     std::vector<HandlerPack> handlers;
 
diff --git a/main.cpp b/main.cpp
index 40f4b52..3130eec 100644
--- a/main.cpp
+++ b/main.cpp
@@ -26,6 +26,7 @@
 #include <cstdint>
 #include <memory>
 #include <phosphor-logging/log.hpp>
+#include <sdbusplus/bus.hpp>
 
 namespace blobs
 {
@@ -82,7 +83,8 @@
     using namespace phosphor::logging;
 
     auto handler = blobs::FirmwareBlobHandler::CreateFirmwareBlobHandler(
-        blobs::supportedFirmware, blobs::supportedTransports);
+        sdbusplus::bus::new_default(), blobs::supportedFirmware,
+        blobs::supportedTransports);
 
     if (!handler)
     {
diff --git a/test/Makefile.am b/test/Makefile.am
index 2af6033..731a030 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -2,11 +2,13 @@
 	$(GTEST_CFLAGS) \
 	$(GMOCK_CFLAGS)
 AM_CXXFLAGS = \
-	$(GTEST_MAIN_CFLAGS)
+	$(GTEST_MAIN_CFLAGS) \
+	$(SDBUSPLUS_CFLAGS)
 AM_LDFLAGS = \
 	$(GMOCK_LIBS) \
 	$(GTEST_MAIN_LIBS) \
-	$(OESDK_TESTCASE_FLAGS)
+	$(OESDK_TESTCASE_FLAGS) \
+	$(SDBUSPLUS_LIBS)
 
 # Run all 'check' test programs
 check_PROGRAMS = \
diff --git a/test/firmware_canhandle_unittest.cpp b/test/firmware_canhandle_unittest.cpp
index 5ad48a5..21dc6a0 100644
--- a/test/firmware_canhandle_unittest.cpp
+++ b/test/firmware_canhandle_unittest.cpp
@@ -2,6 +2,7 @@
 #include "firmware_handler.hpp"
 #include "image_mock.hpp"
 
+#include <sdbusplus/test/sdbus_mock.hpp>
 #include <vector>
 
 #include <gtest/gtest.h>
@@ -30,7 +31,11 @@
         {FirmwareBlobHandler::UpdateFlags::ipmi, nullptr},
     };
 
-    auto handler = FirmwareBlobHandler::CreateFirmwareBlobHandler(blobs, data);
+    sdbusplus::SdBusMock sdbus_mock;
+    auto bus_mock = sdbusplus::get_mocked_new(&sdbus_mock);
+
+    auto handler = FirmwareBlobHandler::CreateFirmwareBlobHandler(
+        std::move(bus_mock), blobs, data);
 
     for (const auto& item : items)
     {
diff --git a/test/firmware_close_unittest.cpp b/test/firmware_close_unittest.cpp
index 546d6df..c5b8902 100644
--- a/test/firmware_close_unittest.cpp
+++ b/test/firmware_close_unittest.cpp
@@ -2,6 +2,7 @@
 #include "firmware_handler.hpp"
 #include "image_mock.hpp"
 
+#include <sdbusplus/test/sdbus_mock.hpp>
 #include <vector>
 
 #include <gmock/gmock.h>
@@ -30,7 +31,11 @@
         {FirmwareBlobHandler::UpdateFlags::lpc, &dataMock},
     };
 
-    auto handler = FirmwareBlobHandler::CreateFirmwareBlobHandler(blobs, data);
+    sdbusplus::SdBusMock sdbus_mock;
+    auto bus_mock = sdbusplus::get_mocked_new(&sdbus_mock);
+
+    auto handler = FirmwareBlobHandler::CreateFirmwareBlobHandler(
+        std::move(bus_mock), blobs, data);
 
     EXPECT_CALL(dataMock, open()).WillOnce(Return(true));
     EXPECT_CALL(imageMock, open(Eq(FirmwareBlobHandler::hashBlobID)))
@@ -73,7 +78,11 @@
         {FirmwareBlobHandler::UpdateFlags::lpc, &dataMock},
     };
 
-    auto handler = FirmwareBlobHandler::CreateFirmwareBlobHandler(blobs, data);
+    sdbusplus::SdBusMock sdbus_mock;
+    auto bus_mock = sdbusplus::get_mocked_new(&sdbus_mock);
+
+    auto handler = FirmwareBlobHandler::CreateFirmwareBlobHandler(
+        std::move(bus_mock), blobs, data);
 
     EXPECT_CALL(imageMock, open(Eq(FirmwareBlobHandler::hashBlobID)))
         .WillOnce(Return(true));
diff --git a/test/firmware_commit_unittest.cpp b/test/firmware_commit_unittest.cpp
index d7bb744..35f48d6 100644
--- a/test/firmware_commit_unittest.cpp
+++ b/test/firmware_commit_unittest.cpp
@@ -2,6 +2,7 @@
 #include "firmware_handler.hpp"
 #include "image_mock.hpp"
 
+#include <sdbusplus/test/sdbus_mock.hpp>
 #include <vector>
 
 #include <gtest/gtest.h>
@@ -25,7 +26,11 @@
         {FirmwareBlobHandler::UpdateFlags::ipmi, nullptr},
     };
 
-    auto handler = FirmwareBlobHandler::CreateFirmwareBlobHandler(blobs, data);
+    sdbusplus::SdBusMock sdbus_mock;
+    auto bus_mock = sdbusplus::get_mocked_new(&sdbus_mock);
+
+    auto handler = FirmwareBlobHandler::CreateFirmwareBlobHandler(
+        std::move(bus_mock), blobs, data);
 
     EXPECT_CALL(imageMock2, open("asdf")).WillOnce(Return(true));
 
@@ -50,7 +55,11 @@
         {FirmwareBlobHandler::UpdateFlags::ipmi, nullptr},
     };
 
-    auto handler = FirmwareBlobHandler::CreateFirmwareBlobHandler(blobs, data);
+    sdbusplus::SdBusMock sdbus_mock;
+    auto bus_mock = sdbusplus::get_mocked_new(&sdbus_mock);
+
+    auto handler = FirmwareBlobHandler::CreateFirmwareBlobHandler(
+        std::move(bus_mock), blobs, data);
 
     EXPECT_CALL(imageMock1, open(FirmwareBlobHandler::hashBlobID))
         .WillOnce(Return(true));
@@ -77,7 +86,11 @@
         {FirmwareBlobHandler::UpdateFlags::ipmi, nullptr},
     };
 
-    auto handler = FirmwareBlobHandler::CreateFirmwareBlobHandler(blobs, data);
+    sdbusplus::SdBusMock sdbus_mock;
+    auto bus_mock = sdbusplus::get_mocked_new(&sdbus_mock);
+
+    auto handler = FirmwareBlobHandler::CreateFirmwareBlobHandler(
+        std::move(bus_mock), blobs, data);
 
     EXPECT_TRUE(
         handler->open(0, OpenFlags::write, FirmwareBlobHandler::verifyBlobID));
@@ -99,7 +112,11 @@
         {FirmwareBlobHandler::UpdateFlags::ipmi, nullptr},
     };
 
-    auto handler = FirmwareBlobHandler::CreateFirmwareBlobHandler(blobs, data);
+    sdbusplus::SdBusMock sdbus_mock;
+    auto bus_mock = sdbusplus::get_mocked_new(&sdbus_mock);
+
+    auto handler = FirmwareBlobHandler::CreateFirmwareBlobHandler(
+        std::move(bus_mock), blobs, data);
 
     EXPECT_TRUE(
         handler->open(0, OpenFlags::write, FirmwareBlobHandler::verifyBlobID));
diff --git a/test/firmware_delete_unittest.cpp b/test/firmware_delete_unittest.cpp
index a5550a9..10c4227 100644
--- a/test/firmware_delete_unittest.cpp
+++ b/test/firmware_delete_unittest.cpp
@@ -2,6 +2,7 @@
 #include "firmware_handler.hpp"
 #include "image_mock.hpp"
 
+#include <sdbusplus/test/sdbus_mock.hpp>
 #include <vector>
 
 #include <gmock/gmock.h>
@@ -28,7 +29,11 @@
         {FirmwareBlobHandler::UpdateFlags::lpc, &dataMock},
     };
 
-    auto handler = FirmwareBlobHandler::CreateFirmwareBlobHandler(blobs, data);
+    sdbusplus::SdBusMock sdbus_mock;
+    auto bus_mock = sdbusplus::get_mocked_new(&sdbus_mock);
+
+    auto handler = FirmwareBlobHandler::CreateFirmwareBlobHandler(
+        std::move(bus_mock), blobs, data);
 
     EXPECT_CALL(imageMock, open(Eq(FirmwareBlobHandler::hashBlobID)))
         .WillOnce(Return(true));
diff --git a/test/firmware_handler_unittest.cpp b/test/firmware_handler_unittest.cpp
index ce65ad4..1457a3b 100644
--- a/test/firmware_handler_unittest.cpp
+++ b/test/firmware_handler_unittest.cpp
@@ -2,6 +2,7 @@
 #include "image_mock.hpp"
 
 #include <algorithm>
+#include <sdbusplus/test/sdbus_mock.hpp>
 #include <vector>
 
 #include <gtest/gtest.h>
@@ -15,7 +16,11 @@
         {FirmwareBlobHandler::UpdateFlags::ipmi, nullptr},
     };
 
-    auto handler = FirmwareBlobHandler::CreateFirmwareBlobHandler({}, data);
+    sdbusplus::SdBusMock sdbus_mock;
+    auto bus_mock = sdbusplus::get_mocked_new(&sdbus_mock);
+
+    auto handler = FirmwareBlobHandler::CreateFirmwareBlobHandler(
+        std::move(bus_mock), {}, data);
     EXPECT_EQ(handler, nullptr);
 }
 TEST(FirmwareHandlerTest, CreateEmptyDataHandlerListFails)
@@ -27,7 +32,11 @@
         {"asdf", &imageMock},
     };
 
-    auto handler = FirmwareBlobHandler::CreateFirmwareBlobHandler(blobs, {});
+    sdbusplus::SdBusMock sdbus_mock;
+    auto bus_mock = sdbusplus::get_mocked_new(&sdbus_mock);
+
+    auto handler = FirmwareBlobHandler::CreateFirmwareBlobHandler(
+        std::move(bus_mock), blobs, {});
     EXPECT_EQ(handler, nullptr);
 }
 TEST(FirmwareHandlerTest, VerifyHashRequiredForHappiness)
@@ -42,12 +51,17 @@
         {FirmwareBlobHandler::UpdateFlags::ipmi, nullptr},
     };
 
-    auto handler = FirmwareBlobHandler::CreateFirmwareBlobHandler(blobs, data);
+    sdbusplus::SdBusMock sdbus_mock;
+    auto bus_mock = sdbusplus::get_mocked_new(&sdbus_mock);
+
+    auto handler = FirmwareBlobHandler::CreateFirmwareBlobHandler(
+        std::move(bus_mock), blobs, data);
     EXPECT_EQ(handler, nullptr);
 
     blobs.push_back({FirmwareBlobHandler::hashBlobID, &imageMock});
 
-    handler = FirmwareBlobHandler::CreateFirmwareBlobHandler(blobs, data);
+    handler = FirmwareBlobHandler::CreateFirmwareBlobHandler(
+        std::move(bus_mock), blobs, data);
     auto result = handler->getBlobIds();
     EXPECT_EQ(3, result.size());
     EXPECT_EQ(3, std::count(result.begin(), result.end(), "asdf") +
diff --git a/test/firmware_open_unittest.cpp b/test/firmware_open_unittest.cpp
index 81a1977..c56d5d5 100644
--- a/test/firmware_open_unittest.cpp
+++ b/test/firmware_open_unittest.cpp
@@ -2,6 +2,7 @@
 #include "firmware_handler.hpp"
 #include "image_mock.hpp"
 
+#include <sdbusplus/test/sdbus_mock.hpp>
 #include <vector>
 
 #include <gmock/gmock.h>
@@ -28,7 +29,11 @@
         {FirmwareBlobHandler::UpdateFlags::ipmi, nullptr},
     };
 
-    auto handler = FirmwareBlobHandler::CreateFirmwareBlobHandler(blobs, data);
+    sdbusplus::SdBusMock sdbus_mock;
+    auto bus_mock = sdbusplus::get_mocked_new(&sdbus_mock);
+
+    auto handler = FirmwareBlobHandler::CreateFirmwareBlobHandler(
+        std::move(bus_mock), blobs, data);
 
     EXPECT_CALL(imageMock, open("asdf")).WillOnce(Return(true));
 
@@ -55,7 +60,11 @@
         {FirmwareBlobHandler::UpdateFlags::ipmi, nullptr},
     };
 
-    auto handler = FirmwareBlobHandler::CreateFirmwareBlobHandler(blobs, data);
+    sdbusplus::SdBusMock sdbus_mock;
+    auto bus_mock = sdbusplus::get_mocked_new(&sdbus_mock);
+
+    auto handler = FirmwareBlobHandler::CreateFirmwareBlobHandler(
+        std::move(bus_mock), blobs, data);
 
     EXPECT_CALL(imageMock, open(Eq(FirmwareBlobHandler::hashBlobID)))
         .WillOnce(Return(true));
@@ -88,7 +97,11 @@
         {FirmwareBlobHandler::UpdateFlags::lpc, &dataMock},
     };
 
-    auto handler = FirmwareBlobHandler::CreateFirmwareBlobHandler(blobs, data);
+    sdbusplus::SdBusMock sdbus_mock;
+    auto bus_mock = sdbusplus::get_mocked_new(&sdbus_mock);
+
+    auto handler = FirmwareBlobHandler::CreateFirmwareBlobHandler(
+        std::move(bus_mock), blobs, data);
 
     EXPECT_CALL(dataMock, open()).WillOnce(Return(true));
     EXPECT_CALL(imageMock, open(Eq(FirmwareBlobHandler::hashBlobID)))
@@ -120,7 +133,11 @@
         {FirmwareBlobHandler::UpdateFlags::lpc, &dataMock},
     };
 
-    auto handler = FirmwareBlobHandler::CreateFirmwareBlobHandler(blobs, data);
+    sdbusplus::SdBusMock sdbus_mock;
+    auto bus_mock = sdbusplus::get_mocked_new(&sdbus_mock);
+
+    auto handler = FirmwareBlobHandler::CreateFirmwareBlobHandler(
+        std::move(bus_mock), blobs, data);
 
     EXPECT_CALL(dataMock, open()).WillOnce(Return(false));
 
@@ -148,7 +165,11 @@
         {FirmwareBlobHandler::UpdateFlags::ipmi, nullptr},
     };
 
-    auto handler = FirmwareBlobHandler::CreateFirmwareBlobHandler(blobs, data);
+    sdbusplus::SdBusMock sdbus_mock;
+    auto bus_mock = sdbusplus::get_mocked_new(&sdbus_mock);
+
+    auto handler = FirmwareBlobHandler::CreateFirmwareBlobHandler(
+        std::move(bus_mock), blobs, data);
 
     EXPECT_CALL(imageMock2, open("asdf")).WillOnce(Return(true));
 
@@ -193,7 +214,11 @@
         {FirmwareBlobHandler::UpdateFlags::ipmi, nullptr},
     };
 
-    auto handler = FirmwareBlobHandler::CreateFirmwareBlobHandler(blobs, data);
+    sdbusplus::SdBusMock sdbus_mock;
+    auto bus_mock = sdbusplus::get_mocked_new(&sdbus_mock);
+
+    auto handler = FirmwareBlobHandler::CreateFirmwareBlobHandler(
+        std::move(bus_mock), blobs, data);
 
     EXPECT_CALL(imageMock, open("asdf")).WillOnce(Return(true));
 
@@ -231,7 +256,11 @@
         {FirmwareBlobHandler::UpdateFlags::ipmi, nullptr},
     };
 
-    auto handler = FirmwareBlobHandler::CreateFirmwareBlobHandler(blobs, data);
+    sdbusplus::SdBusMock sdbus_mock;
+    auto bus_mock = sdbusplus::get_mocked_new(&sdbus_mock);
+
+    auto handler = FirmwareBlobHandler::CreateFirmwareBlobHandler(
+        std::move(bus_mock), blobs, data);
 
     EXPECT_CALL(imageMock, open("asdf")).WillOnce(Return(false));
 
@@ -257,7 +286,11 @@
         {FirmwareBlobHandler::UpdateFlags::ipmi, nullptr},
     };
 
-    auto handler = FirmwareBlobHandler::CreateFirmwareBlobHandler(blobs, data);
+    sdbusplus::SdBusMock sdbus_mock;
+    auto bus_mock = sdbusplus::get_mocked_new(&sdbus_mock);
+
+    auto handler = FirmwareBlobHandler::CreateFirmwareBlobHandler(
+        std::move(bus_mock), blobs, data);
 
     EXPECT_FALSE(
         handler->open(0, FirmwareBlobHandler::UpdateFlags::ipmi, "asdf"));
@@ -277,7 +310,11 @@
         {FirmwareBlobHandler::UpdateFlags::ipmi, nullptr},
     };
 
-    auto handler = FirmwareBlobHandler::CreateFirmwareBlobHandler(blobs, data);
+    sdbusplus::SdBusMock sdbus_mock;
+    auto bus_mock = sdbusplus::get_mocked_new(&sdbus_mock);
+
+    auto handler = FirmwareBlobHandler::CreateFirmwareBlobHandler(
+        std::move(bus_mock), blobs, data);
 
     EXPECT_FALSE(
         handler->open(0, FirmwareBlobHandler::UpdateFlags::lpc, "asdf"));
@@ -297,7 +334,11 @@
         {FirmwareBlobHandler::UpdateFlags::ipmi, nullptr},
     };
 
-    auto handler = FirmwareBlobHandler::CreateFirmwareBlobHandler(blobs, data);
+    sdbusplus::SdBusMock sdbus_mock;
+    auto bus_mock = sdbusplus::get_mocked_new(&sdbus_mock);
+
+    auto handler = FirmwareBlobHandler::CreateFirmwareBlobHandler(
+        std::move(bus_mock), blobs, data);
 
     EXPECT_FALSE(handler->open(
         0, OpenFlags::write | FirmwareBlobHandler::UpdateFlags::ipmi, "bcdf"));
diff --git a/test/firmware_sessionstat_unittest.cpp b/test/firmware_sessionstat_unittest.cpp
index 9dbf909..42f67e6 100644
--- a/test/firmware_sessionstat_unittest.cpp
+++ b/test/firmware_sessionstat_unittest.cpp
@@ -2,6 +2,7 @@
 #include "firmware_handler.hpp"
 #include "image_mock.hpp"
 
+#include <sdbusplus/test/sdbus_mock.hpp>
 #include <vector>
 
 #include <gtest/gtest.h>
@@ -26,7 +27,11 @@
         {FirmwareBlobHandler::UpdateFlags::ipmi, nullptr},
     };
 
-    auto handler = FirmwareBlobHandler::CreateFirmwareBlobHandler(blobs, data);
+    sdbusplus::SdBusMock sdbus_mock;
+    auto bus_mock = sdbusplus::get_mocked_new(&sdbus_mock);
+
+    auto handler = FirmwareBlobHandler::CreateFirmwareBlobHandler(
+        std::move(bus_mock), blobs, data);
 
     EXPECT_CALL(imageMock2, open("asdf")).WillOnce(Return(true));
 
@@ -63,7 +68,11 @@
         {FirmwareBlobHandler::UpdateFlags::lpc, &dataMock},
     };
 
-    auto handler = FirmwareBlobHandler::CreateFirmwareBlobHandler(blobs, data);
+    sdbusplus::SdBusMock sdbus_mock;
+    auto bus_mock = sdbusplus::get_mocked_new(&sdbus_mock);
+
+    auto handler = FirmwareBlobHandler::CreateFirmwareBlobHandler(
+        std::move(bus_mock), blobs, data);
 
     EXPECT_CALL(dataMock, open()).WillOnce(Return(true));
     EXPECT_CALL(imageMock2, open("asdf")).WillOnce(Return(true));
diff --git a/test/firmware_stat_unittest.cpp b/test/firmware_stat_unittest.cpp
index 338e7bf..d6cc99d 100644
--- a/test/firmware_stat_unittest.cpp
+++ b/test/firmware_stat_unittest.cpp
@@ -1,6 +1,7 @@
 #include "firmware_handler.hpp"
 #include "image_mock.hpp"
 
+#include <sdbusplus/test/sdbus_mock.hpp>
 #include <vector>
 
 #include <gtest/gtest.h>
@@ -26,7 +27,12 @@
         {FirmwareBlobHandler::UpdateFlags::ipmi, nullptr},
     };
 
-    auto handler = FirmwareBlobHandler::CreateFirmwareBlobHandler(blobs, data);
+    sdbusplus::SdBusMock sdbus_mock;
+    auto bus_mock = sdbusplus::get_mocked_new(&sdbus_mock);
+
+    auto handler = FirmwareBlobHandler::CreateFirmwareBlobHandler(
+        std::move(bus_mock), blobs, data);
+
     struct BlobMeta meta;
     EXPECT_TRUE(handler->stat("asdf", &meta));
     EXPECT_EQ(FirmwareBlobHandler::UpdateFlags::ipmi, meta.blobState);
diff --git a/test/firmware_write_unittest.cpp b/test/firmware_write_unittest.cpp
index 0ba20f5..d9fcae4 100644
--- a/test/firmware_write_unittest.cpp
+++ b/test/firmware_write_unittest.cpp
@@ -4,6 +4,7 @@
 
 #include <cstdint>
 #include <cstring>
+#include <sdbusplus/test/sdbus_mock.hpp>
 #include <vector>
 
 #include <gtest/gtest.h>
@@ -27,7 +28,11 @@
         {FirmwareBlobHandler::UpdateFlags::ipmi, nullptr},
     };
 
-    auto handler = FirmwareBlobHandler::CreateFirmwareBlobHandler(blobs, data);
+    sdbusplus::SdBusMock sdbus_mock;
+    auto bus_mock = sdbusplus::get_mocked_new(&sdbus_mock);
+
+    auto handler = FirmwareBlobHandler::CreateFirmwareBlobHandler(
+        std::move(bus_mock), blobs, data);
 
     EXPECT_CALL(imageMock2, open("asdf")).WillOnce(Return(true));
 
@@ -57,7 +62,11 @@
         {FirmwareBlobHandler::UpdateFlags::lpc, &dataMock},
     };
 
-    auto handler = FirmwareBlobHandler::CreateFirmwareBlobHandler(blobs, data);
+    sdbusplus::SdBusMock sdbus_mock;
+    auto bus_mock = sdbusplus::get_mocked_new(&sdbus_mock);
+
+    auto handler = FirmwareBlobHandler::CreateFirmwareBlobHandler(
+        std::move(bus_mock), blobs, data);
 
     EXPECT_CALL(dataMock, open()).WillOnce(Return(true));
     EXPECT_CALL(imageMock2, open("asdf")).WillOnce(Return(true));
@@ -96,7 +105,11 @@
         {FirmwareBlobHandler::UpdateFlags::lpc, &dataMock},
     };
 
-    auto handler = FirmwareBlobHandler::CreateFirmwareBlobHandler(blobs, data);
+    sdbusplus::SdBusMock sdbus_mock;
+    auto bus_mock = sdbusplus::get_mocked_new(&sdbus_mock);
+
+    auto handler = FirmwareBlobHandler::CreateFirmwareBlobHandler(
+        std::move(bus_mock), blobs, data);
 
     EXPECT_CALL(dataMock, open()).WillOnce(Return(true));
     EXPECT_CALL(imageMock2, open("asdf")).WillOnce(Return(true));
diff --git a/test/firmware_writemeta_unittest.cpp b/test/firmware_writemeta_unittest.cpp
index 13399fb..869ed48 100644
--- a/test/firmware_writemeta_unittest.cpp
+++ b/test/firmware_writemeta_unittest.cpp
@@ -2,6 +2,8 @@
 #include "firmware_handler.hpp"
 #include "image_mock.hpp"
 
+#include <sdbusplus/test/sdbus_mock.hpp>
+
 #include <gtest/gtest.h>
 
 namespace blobs
@@ -24,7 +26,11 @@
         {FirmwareBlobHandler::UpdateFlags::lpc, &dataMock},
     };
 
-    auto handler = FirmwareBlobHandler::CreateFirmwareBlobHandler(blobs, data);
+    sdbusplus::SdBusMock sdbus_mock;
+    auto bus_mock = sdbusplus::get_mocked_new(&sdbus_mock);
+
+    auto handler = FirmwareBlobHandler::CreateFirmwareBlobHandler(
+        std::move(bus_mock), blobs, data);
 
     EXPECT_CALL(imageMock2, open("asdf")).WillOnce(Return(true));
 
@@ -51,7 +57,11 @@
         {FirmwareBlobHandler::UpdateFlags::lpc, &dataMock},
     };
 
-    auto handler = FirmwareBlobHandler::CreateFirmwareBlobHandler(blobs, data);
+    sdbusplus::SdBusMock sdbus_mock;
+    auto bus_mock = sdbusplus::get_mocked_new(&sdbus_mock);
+
+    auto handler = FirmwareBlobHandler::CreateFirmwareBlobHandler(
+        std::move(bus_mock), blobs, data);
 
     EXPECT_CALL(dataMock, open()).WillOnce(Return(true));
     EXPECT_CALL(imageMock2, open("asdf")).WillOnce(Return(true));