#include "create_action_map.hpp" #include "firmware_handler.hpp" #include "flags.hpp" #include "image_mock.hpp" #include "util.hpp" #include #include #include #include namespace ipmi_flash { namespace { using ::testing::UnorderedElementsAreArray; TEST(FirmwareHandlerTest, CreateEmptyHandlerListVerifyFails) { std::vector data; data.emplace_back(FirmwareFlags::UpdateFlags::ipmi, nullptr); auto handler = FirmwareBlobHandler::CreateFirmwareBlobHandler( {}, std::move(data), CreateActionMap("abcd")); EXPECT_EQ(handler, nullptr); } TEST(FirmwareHandlerTest, CreateEmptyDataHandlerListFails) { ImageHandlerMock imageMock; std::vector blobs; blobs.emplace_back(hashBlobId, std::make_unique()); blobs.emplace_back("asdf", std::make_unique()); auto handler = FirmwareBlobHandler::CreateFirmwareBlobHandler( std::move(blobs), std::vector(), CreateActionMap("asdf")); EXPECT_EQ(handler, nullptr); } TEST(FirmwareHandlerTest, CreateEmptyActionPackVerifyFails) { /* The ActionPack map corresponds to the firmware list passed in, but * they're not checked against each other yet. */ std::vector data; data.emplace_back(FirmwareFlags::UpdateFlags::ipmi, nullptr); std::vector blobs; blobs.emplace_back("asdf", std::make_unique()); blobs.emplace_back(hashBlobId, std::make_unique()); ActionMap emptyMap; auto handler = FirmwareBlobHandler::CreateFirmwareBlobHandler( std::move(blobs), std::move(data), std::move(emptyMap)); EXPECT_EQ(handler, nullptr); } TEST(FirmwareHandlerTest, FirmwareHandlerListRequiresAtLeastTwoEntries) { /* The hashblob handler must be one of the entries, but it cannot be the * only entry. */ std::vector data; data.emplace_back(FirmwareFlags::UpdateFlags::ipmi, nullptr); /* Provide a firmware list that has the hash blob, which is the required one * -- tested in a different test. */ std::vector blobs; blobs.emplace_back(hashBlobId, std::make_unique()); auto handler = FirmwareBlobHandler::CreateFirmwareBlobHandler( std::move(blobs), std::move(data), CreateActionMap("asdf")); EXPECT_EQ(handler, nullptr); /* Add second firmware and it'll now work. */ std::vector blobs2; blobs2.emplace_back(hashBlobId, std::make_unique()); blobs2.emplace_back("asdf", std::make_unique()); std::vector data2; data2.emplace_back(FirmwareFlags::UpdateFlags::ipmi, nullptr); handler = FirmwareBlobHandler::CreateFirmwareBlobHandler( std::move(blobs2), std::move(data2), CreateActionMap("asdf")); auto result = handler->getBlobIds(); std::vector expectedBlobs = {"asdf", hashBlobId}; EXPECT_THAT(result, UnorderedElementsAreArray(expectedBlobs)); } TEST(FirmwareHandlerTest, VerifyHashRequiredForHappiness) { std::vector data; data.emplace_back(FirmwareFlags::UpdateFlags::ipmi, nullptr); /* This works fine only if you also pass in the hash handler. */ std::vector blobs; blobs.emplace_back("asdf", std::make_unique()); auto handler = FirmwareBlobHandler::CreateFirmwareBlobHandler( std::move(blobs), std::move(data), CreateActionMap("asdf")); EXPECT_EQ(handler, nullptr); std::vector blobs2; blobs2.emplace_back("asdf", std::make_unique()); blobs2.emplace_back(hashBlobId, std::make_unique()); std::vector data2; data2.emplace_back(FirmwareFlags::UpdateFlags::ipmi, nullptr); handler = FirmwareBlobHandler::CreateFirmwareBlobHandler( std::move(blobs2), std::move(data2), CreateActionMap("asdf")); auto result = handler->getBlobIds(); std::vector expectedBlobs = {"asdf", hashBlobId}; EXPECT_THAT(result, UnorderedElementsAreArray(expectedBlobs)); } } // namespace } // namespace ipmi_flash