blob: 09cbf9e93902fd55d93c21fbdfd70e67ce502463 [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 Venture7dad86f2019-05-17 08:52:20 -07003#include "util.hpp"
Patrick Venture3ecb3502019-05-17 11:03:51 -07004#include "verification_mock.hpp"
Patrick Venture21be45a2018-11-06 12:08:52 -08005
Patrick Venture52854622018-11-06 12:30:00 -08006#include <algorithm>
Patrick Venturea78e39f2018-11-06 18:37:06 -08007#include <vector>
Patrick Venture21be45a2018-11-06 12:08:52 -08008
9#include <gtest/gtest.h>
10
11namespace blobs
12{
Patrick Venture52854622018-11-06 12:30:00 -080013
14TEST(FirmwareHandlerTest, CreateEmptyListVerifyFails)
Patrick Venture21be45a2018-11-06 12:08:52 -080015{
Patrick Venture1cde5f92018-11-07 08:26:47 -080016 std::vector<DataHandlerPack> data = {
Patrick Venture05abf7e2018-11-09 11:02:56 -080017 {FirmwareBlobHandler::UpdateFlags::ipmi, nullptr},
Patrick Venture1cde5f92018-11-07 08:26:47 -080018 };
19
Patrick Venture4eb55952018-11-16 15:36:24 -080020 auto handler = FirmwareBlobHandler::CreateFirmwareBlobHandler(
Patrick Venture3ecb3502019-05-17 11:03:51 -070021 {}, data, CreateVerifyMock());
Patrick Venture1cde5f92018-11-07 08:26:47 -080022 EXPECT_EQ(handler, nullptr);
23}
24TEST(FirmwareHandlerTest, CreateEmptyDataHandlerListFails)
25{
26 ImageHandlerMock imageMock;
27
28 std::vector<HandlerPack> blobs = {
Patrick Venture7dad86f2019-05-17 08:52:20 -070029 {hashBlobId, &imageMock},
Patrick Venture1cde5f92018-11-07 08:26:47 -080030 {"asdf", &imageMock},
31 };
32
Patrick Venture4eb55952018-11-16 15:36:24 -080033 auto handler = FirmwareBlobHandler::CreateFirmwareBlobHandler(
Patrick Venture3ecb3502019-05-17 11:03:51 -070034 blobs, {}, CreateVerifyMock());
Patrick Venture52854622018-11-06 12:30:00 -080035 EXPECT_EQ(handler, nullptr);
36}
Patrick Venture18235e62018-11-08 10:21:09 -080037TEST(FirmwareHandlerTest, VerifyHashRequiredForHappiness)
Patrick Venture52854622018-11-06 12:30:00 -080038{
Patrick Venture18235e62018-11-08 10:21:09 -080039 /* This works fine only if you also pass in the hash handler. */
Patrick Venturea78e39f2018-11-06 18:37:06 -080040 ImageHandlerMock imageMock;
41
42 std::vector<HandlerPack> blobs = {
43 {"asdf", &imageMock},
44 };
Patrick Venture1cde5f92018-11-07 08:26:47 -080045 std::vector<DataHandlerPack> data = {
Patrick Venture05abf7e2018-11-09 11:02:56 -080046 {FirmwareBlobHandler::UpdateFlags::ipmi, nullptr},
Patrick Venture1cde5f92018-11-07 08:26:47 -080047 };
Patrick Venturea78e39f2018-11-06 18:37:06 -080048
Patrick Venture4eb55952018-11-16 15:36:24 -080049 auto handler = FirmwareBlobHandler::CreateFirmwareBlobHandler(
Patrick Venture3ecb3502019-05-17 11:03:51 -070050 blobs, data, CreateVerifyMock());
Patrick Venture18235e62018-11-08 10:21:09 -080051 EXPECT_EQ(handler, nullptr);
52
Patrick Venture7dad86f2019-05-17 08:52:20 -070053 blobs.push_back({hashBlobId, &imageMock});
Patrick Venture18235e62018-11-08 10:21:09 -080054
Patrick Venture4eb55952018-11-16 15:36:24 -080055 handler = FirmwareBlobHandler::CreateFirmwareBlobHandler(
Patrick Venture3ecb3502019-05-17 11:03:51 -070056 blobs, data, CreateVerifyMock());
Patrick Venture21be45a2018-11-06 12:08:52 -080057 auto result = handler->getBlobIds();
Patrick Ventureffcc5502018-11-16 12:32:38 -080058 EXPECT_EQ(3, result.size());
59 EXPECT_EQ(3, std::count(result.begin(), result.end(), "asdf") +
Patrick Venture7dad86f2019-05-17 08:52:20 -070060 std::count(result.begin(), result.end(), hashBlobId) +
61 std::count(result.begin(), result.end(), verifyBlobId));
Patrick Venture21be45a2018-11-06 12:08:52 -080062}
63} // namespace blobs