blob: 1457a3b55b8b919f3ad5987b5b698b302df94fe6 [file] [log] [blame]
Patrick Venture21be45a2018-11-06 12:08:52 -08001#include "firmware_handler.hpp"
Patrick Venturea78e39f2018-11-06 18:37:06 -08002#include "image_mock.hpp"
Patrick Venture21be45a2018-11-06 12:08:52 -08003
Patrick Venture52854622018-11-06 12:30:00 -08004#include <algorithm>
Patrick Venture4eb55952018-11-16 15:36:24 -08005#include <sdbusplus/test/sdbus_mock.hpp>
Patrick Venturea78e39f2018-11-06 18:37:06 -08006#include <vector>
Patrick Venture21be45a2018-11-06 12:08:52 -08007
8#include <gtest/gtest.h>
9
10namespace blobs
11{
Patrick Venture52854622018-11-06 12:30:00 -080012
13TEST(FirmwareHandlerTest, CreateEmptyListVerifyFails)
Patrick Venture21be45a2018-11-06 12:08:52 -080014{
Patrick Venture1cde5f92018-11-07 08:26:47 -080015 std::vector<DataHandlerPack> data = {
Patrick Venture05abf7e2018-11-09 11:02:56 -080016 {FirmwareBlobHandler::UpdateFlags::ipmi, nullptr},
Patrick Venture1cde5f92018-11-07 08:26:47 -080017 };
18
Patrick Venture4eb55952018-11-16 15:36:24 -080019 sdbusplus::SdBusMock sdbus_mock;
20 auto bus_mock = sdbusplus::get_mocked_new(&sdbus_mock);
21
22 auto handler = FirmwareBlobHandler::CreateFirmwareBlobHandler(
23 std::move(bus_mock), {}, data);
Patrick Venture1cde5f92018-11-07 08:26:47 -080024 EXPECT_EQ(handler, nullptr);
25}
26TEST(FirmwareHandlerTest, CreateEmptyDataHandlerListFails)
27{
28 ImageHandlerMock imageMock;
29
30 std::vector<HandlerPack> blobs = {
Patrick Venture18235e62018-11-08 10:21:09 -080031 {FirmwareBlobHandler::hashBlobID, &imageMock},
Patrick Venture1cde5f92018-11-07 08:26:47 -080032 {"asdf", &imageMock},
33 };
34
Patrick Venture4eb55952018-11-16 15:36:24 -080035 sdbusplus::SdBusMock sdbus_mock;
36 auto bus_mock = sdbusplus::get_mocked_new(&sdbus_mock);
37
38 auto handler = FirmwareBlobHandler::CreateFirmwareBlobHandler(
39 std::move(bus_mock), blobs, {});
Patrick Venture52854622018-11-06 12:30:00 -080040 EXPECT_EQ(handler, nullptr);
41}
Patrick Venture18235e62018-11-08 10:21:09 -080042TEST(FirmwareHandlerTest, VerifyHashRequiredForHappiness)
Patrick Venture52854622018-11-06 12:30:00 -080043{
Patrick Venture18235e62018-11-08 10:21:09 -080044 /* This works fine only if you also pass in the hash handler. */
Patrick Venturea78e39f2018-11-06 18:37:06 -080045 ImageHandlerMock imageMock;
46
47 std::vector<HandlerPack> blobs = {
48 {"asdf", &imageMock},
49 };
Patrick Venture1cde5f92018-11-07 08:26:47 -080050 std::vector<DataHandlerPack> data = {
Patrick Venture05abf7e2018-11-09 11:02:56 -080051 {FirmwareBlobHandler::UpdateFlags::ipmi, nullptr},
Patrick Venture1cde5f92018-11-07 08:26:47 -080052 };
Patrick Venturea78e39f2018-11-06 18:37:06 -080053
Patrick Venture4eb55952018-11-16 15:36:24 -080054 sdbusplus::SdBusMock sdbus_mock;
55 auto bus_mock = sdbusplus::get_mocked_new(&sdbus_mock);
56
57 auto handler = FirmwareBlobHandler::CreateFirmwareBlobHandler(
58 std::move(bus_mock), blobs, data);
Patrick Venture18235e62018-11-08 10:21:09 -080059 EXPECT_EQ(handler, nullptr);
60
61 blobs.push_back({FirmwareBlobHandler::hashBlobID, &imageMock});
62
Patrick Venture4eb55952018-11-16 15:36:24 -080063 handler = FirmwareBlobHandler::CreateFirmwareBlobHandler(
64 std::move(bus_mock), blobs, data);
Patrick Venture21be45a2018-11-06 12:08:52 -080065 auto result = handler->getBlobIds();
Patrick Ventureffcc5502018-11-16 12:32:38 -080066 EXPECT_EQ(3, result.size());
67 EXPECT_EQ(3, std::count(result.begin(), result.end(), "asdf") +
Patrick Venture52854622018-11-06 12:30:00 -080068 std::count(result.begin(), result.end(),
Patrick Ventureffcc5502018-11-16 12:32:38 -080069 FirmwareBlobHandler::hashBlobID) +
70 std::count(result.begin(), result.end(),
71 FirmwareBlobHandler::verifyBlobID));
Patrick Venture21be45a2018-11-06 12:08:52 -080072}
73} // namespace blobs