blob: ce65ad46d4a876715d875cf7f47962a0c532f8eb [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 Venturea78e39f2018-11-06 18:37:06 -08005#include <vector>
Patrick Venture21be45a2018-11-06 12:08:52 -08006
7#include <gtest/gtest.h>
8
9namespace blobs
10{
Patrick Venture52854622018-11-06 12:30:00 -080011
12TEST(FirmwareHandlerTest, CreateEmptyListVerifyFails)
Patrick Venture21be45a2018-11-06 12:08:52 -080013{
Patrick Venture1cde5f92018-11-07 08:26:47 -080014 std::vector<DataHandlerPack> data = {
Patrick Venture05abf7e2018-11-09 11:02:56 -080015 {FirmwareBlobHandler::UpdateFlags::ipmi, nullptr},
Patrick Venture1cde5f92018-11-07 08:26:47 -080016 };
17
18 auto handler = FirmwareBlobHandler::CreateFirmwareBlobHandler({}, data);
19 EXPECT_EQ(handler, nullptr);
20}
21TEST(FirmwareHandlerTest, CreateEmptyDataHandlerListFails)
22{
23 ImageHandlerMock imageMock;
24
25 std::vector<HandlerPack> blobs = {
Patrick Venture18235e62018-11-08 10:21:09 -080026 {FirmwareBlobHandler::hashBlobID, &imageMock},
Patrick Venture1cde5f92018-11-07 08:26:47 -080027 {"asdf", &imageMock},
28 };
29
30 auto handler = FirmwareBlobHandler::CreateFirmwareBlobHandler(blobs, {});
Patrick Venture52854622018-11-06 12:30:00 -080031 EXPECT_EQ(handler, nullptr);
32}
Patrick Venture18235e62018-11-08 10:21:09 -080033TEST(FirmwareHandlerTest, VerifyHashRequiredForHappiness)
Patrick Venture52854622018-11-06 12:30:00 -080034{
Patrick Venture18235e62018-11-08 10:21:09 -080035 /* This works fine only if you also pass in the hash handler. */
Patrick Venturea78e39f2018-11-06 18:37:06 -080036 ImageHandlerMock imageMock;
37
38 std::vector<HandlerPack> blobs = {
39 {"asdf", &imageMock},
40 };
Patrick Venture1cde5f92018-11-07 08:26:47 -080041 std::vector<DataHandlerPack> data = {
Patrick Venture05abf7e2018-11-09 11:02:56 -080042 {FirmwareBlobHandler::UpdateFlags::ipmi, nullptr},
Patrick Venture1cde5f92018-11-07 08:26:47 -080043 };
Patrick Venturea78e39f2018-11-06 18:37:06 -080044
Patrick Venture1cde5f92018-11-07 08:26:47 -080045 auto handler = FirmwareBlobHandler::CreateFirmwareBlobHandler(blobs, data);
Patrick Venture18235e62018-11-08 10:21:09 -080046 EXPECT_EQ(handler, nullptr);
47
48 blobs.push_back({FirmwareBlobHandler::hashBlobID, &imageMock});
49
50 handler = FirmwareBlobHandler::CreateFirmwareBlobHandler(blobs, data);
Patrick Venture21be45a2018-11-06 12:08:52 -080051 auto result = handler->getBlobIds();
Patrick Ventureffcc5502018-11-16 12:32:38 -080052 EXPECT_EQ(3, result.size());
53 EXPECT_EQ(3, std::count(result.begin(), result.end(), "asdf") +
Patrick Venture52854622018-11-06 12:30:00 -080054 std::count(result.begin(), result.end(),
Patrick Ventureffcc5502018-11-16 12:32:38 -080055 FirmwareBlobHandler::hashBlobID) +
56 std::count(result.begin(), result.end(),
57 FirmwareBlobHandler::verifyBlobID));
Patrick Venture21be45a2018-11-06 12:08:52 -080058}
59} // namespace blobs