blob: e2ef7f479de8d2b3590e1d89de83cb43c017c57a [file] [log] [blame]
Patrick Venture27ac5822019-05-20 17:39:31 -07001#include "bmc_update_mock.hpp"
Patrick Venture21be45a2018-11-06 12:08:52 -08002#include "firmware_handler.hpp"
Patrick Venturea78e39f2018-11-06 18:37:06 -08003#include "image_mock.hpp"
Patrick Venture7dad86f2019-05-17 08:52:20 -07004#include "util.hpp"
Patrick Venture3ecb3502019-05-17 11:03:51 -07005#include "verification_mock.hpp"
Patrick Venture21be45a2018-11-06 12:08:52 -08006
Patrick Venture52854622018-11-06 12:30:00 -08007#include <algorithm>
Patrick Venturea78e39f2018-11-06 18:37:06 -08008#include <vector>
Patrick Venture21be45a2018-11-06 12:08:52 -08009
10#include <gtest/gtest.h>
11
Patrick Venture1d5a31c2019-05-20 11:38:22 -070012namespace ipmi_flash
Patrick Venture21be45a2018-11-06 12:08:52 -080013{
Patrick Venture930c7b72019-05-24 11:11:08 -070014namespace
15{
16
17using ::testing::UnorderedElementsAreArray;
Patrick Venture52854622018-11-06 12:30:00 -080018
19TEST(FirmwareHandlerTest, CreateEmptyListVerifyFails)
Patrick Venture21be45a2018-11-06 12:08:52 -080020{
Patrick Venture1cde5f92018-11-07 08:26:47 -080021 std::vector<DataHandlerPack> data = {
Patrick Venture05abf7e2018-11-09 11:02:56 -080022 {FirmwareBlobHandler::UpdateFlags::ipmi, nullptr},
Patrick Venture1cde5f92018-11-07 08:26:47 -080023 };
24
Patrick Venture4eb55952018-11-16 15:36:24 -080025 auto handler = FirmwareBlobHandler::CreateFirmwareBlobHandler(
Patrick Venture27ac5822019-05-20 17:39:31 -070026 {}, data, CreateVerifyMock(), CreateUpdateMock());
Patrick Venture1cde5f92018-11-07 08:26:47 -080027 EXPECT_EQ(handler, nullptr);
28}
29TEST(FirmwareHandlerTest, CreateEmptyDataHandlerListFails)
30{
31 ImageHandlerMock imageMock;
32
33 std::vector<HandlerPack> blobs = {
Patrick Venture7dad86f2019-05-17 08:52:20 -070034 {hashBlobId, &imageMock},
Patrick Venture1cde5f92018-11-07 08:26:47 -080035 {"asdf", &imageMock},
36 };
37
Patrick Venture4eb55952018-11-16 15:36:24 -080038 auto handler = FirmwareBlobHandler::CreateFirmwareBlobHandler(
Patrick Venture27ac5822019-05-20 17:39:31 -070039 blobs, {}, CreateVerifyMock(), CreateUpdateMock());
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 auto handler = FirmwareBlobHandler::CreateFirmwareBlobHandler(
Patrick Venture27ac5822019-05-20 17:39:31 -070055 blobs, data, CreateVerifyMock(), CreateUpdateMock());
Patrick Venture18235e62018-11-08 10:21:09 -080056 EXPECT_EQ(handler, nullptr);
57
Patrick Venture7dad86f2019-05-17 08:52:20 -070058 blobs.push_back({hashBlobId, &imageMock});
Patrick Venture18235e62018-11-08 10:21:09 -080059
Patrick Venture4eb55952018-11-16 15:36:24 -080060 handler = FirmwareBlobHandler::CreateFirmwareBlobHandler(
Patrick Venture27ac5822019-05-20 17:39:31 -070061 blobs, data, CreateVerifyMock(), CreateUpdateMock());
Patrick Venture21be45a2018-11-06 12:08:52 -080062 auto result = handler->getBlobIds();
Patrick Venture930c7b72019-05-24 11:11:08 -070063 std::vector<std::string> expectedBlobs = {"asdf", hashBlobId};
64 EXPECT_THAT(result, UnorderedElementsAreArray(expectedBlobs));
Patrick Venture21be45a2018-11-06 12:08:52 -080065}
Patrick Venture930c7b72019-05-24 11:11:08 -070066
67} // namespace
Patrick Venture1d5a31c2019-05-20 11:38:22 -070068} // namespace ipmi_flash