Patrick Venture | 72388d7 | 2018-11-07 15:06:36 -0800 | [diff] [blame] | 1 | #include "data_mock.hpp" |
| 2 | #include "firmware_handler.hpp" |
| 3 | #include "image_mock.hpp" |
Patrick Venture | 7dad86f | 2019-05-17 08:52:20 -0700 | [diff] [blame] | 4 | #include "util.hpp" |
Patrick Venture | 72388d7 | 2018-11-07 15:06:36 -0800 | [diff] [blame] | 5 | |
Patrick Venture | 4eb5595 | 2018-11-16 15:36:24 -0800 | [diff] [blame] | 6 | #include <sdbusplus/test/sdbus_mock.hpp> |
Patrick Venture | 72388d7 | 2018-11-07 15:06:36 -0800 | [diff] [blame] | 7 | #include <vector> |
| 8 | |
| 9 | #include <gmock/gmock.h> |
| 10 | #include <gtest/gtest.h> |
| 11 | |
| 12 | namespace blobs |
| 13 | { |
Patrick Venture | 21c62c1 | 2018-11-09 17:46:58 -0800 | [diff] [blame] | 14 | using ::testing::Eq; |
Patrick Venture | 72388d7 | 2018-11-07 15:06:36 -0800 | [diff] [blame] | 15 | using ::testing::Return; |
Patrick Venture | 991910a | 2018-11-09 19:43:48 -0800 | [diff] [blame] | 16 | using ::testing::StrEq; |
Patrick Venture | 72388d7 | 2018-11-07 15:06:36 -0800 | [diff] [blame] | 17 | |
| 18 | TEST(FirmwareHandlerOpenTest, OpenWithEverythingValid) |
| 19 | { |
| 20 | /* The client passes write set, and a transport that's supported, and a |
| 21 | * firmware image blob_id that's supported. */ |
| 22 | |
| 23 | ImageHandlerMock imageMock; |
| 24 | |
| 25 | std::vector<HandlerPack> blobs = { |
Patrick Venture | 7dad86f | 2019-05-17 08:52:20 -0700 | [diff] [blame] | 26 | {hashBlobId, &imageMock}, |
Patrick Venture | 72388d7 | 2018-11-07 15:06:36 -0800 | [diff] [blame] | 27 | {"asdf", &imageMock}, |
| 28 | }; |
| 29 | std::vector<DataHandlerPack> data = { |
Patrick Venture | 05abf7e | 2018-11-09 11:02:56 -0800 | [diff] [blame] | 30 | {FirmwareBlobHandler::UpdateFlags::ipmi, nullptr}, |
Patrick Venture | 72388d7 | 2018-11-07 15:06:36 -0800 | [diff] [blame] | 31 | }; |
| 32 | |
Patrick Venture | 4eb5595 | 2018-11-16 15:36:24 -0800 | [diff] [blame] | 33 | sdbusplus::SdBusMock sdbus_mock; |
| 34 | auto bus_mock = sdbusplus::get_mocked_new(&sdbus_mock); |
| 35 | |
| 36 | auto handler = FirmwareBlobHandler::CreateFirmwareBlobHandler( |
Patrick Venture | 74059d6 | 2019-05-17 10:40:26 -0700 | [diff] [blame] | 37 | std::move(bus_mock), blobs, data, ""); |
Patrick Venture | 72388d7 | 2018-11-07 15:06:36 -0800 | [diff] [blame] | 38 | |
| 39 | EXPECT_CALL(imageMock, open("asdf")).WillOnce(Return(true)); |
| 40 | |
| 41 | EXPECT_TRUE(handler->open( |
Patrick Venture | 05abf7e | 2018-11-09 11:02:56 -0800 | [diff] [blame] | 42 | 0, OpenFlags::write | FirmwareBlobHandler::UpdateFlags::ipmi, "asdf")); |
Patrick Venture | 21c62c1 | 2018-11-09 17:46:58 -0800 | [diff] [blame] | 43 | |
| 44 | /* The active image blob_id was added. */ |
| 45 | auto currentBlobs = handler->getBlobIds(); |
Patrick Venture | ffcc550 | 2018-11-16 12:32:38 -0800 | [diff] [blame] | 46 | EXPECT_EQ(4, currentBlobs.size()); |
Patrick Venture | 21c62c1 | 2018-11-09 17:46:58 -0800 | [diff] [blame] | 47 | EXPECT_EQ(1, std::count(currentBlobs.begin(), currentBlobs.end(), |
Patrick Venture | 7dad86f | 2019-05-17 08:52:20 -0700 | [diff] [blame] | 48 | activeImageBlobId)); |
Patrick Venture | 21c62c1 | 2018-11-09 17:46:58 -0800 | [diff] [blame] | 49 | } |
| 50 | |
| 51 | TEST(FirmwareHandlerOpenTest, OpenWithEverythingValidHashFile) |
| 52 | { |
| 53 | /* Open the hash file by blob_id. */ |
| 54 | ImageHandlerMock imageMock; |
| 55 | |
| 56 | std::vector<HandlerPack> blobs = { |
Patrick Venture | 7dad86f | 2019-05-17 08:52:20 -0700 | [diff] [blame] | 57 | {hashBlobId, &imageMock}, |
Patrick Venture | 21c62c1 | 2018-11-09 17:46:58 -0800 | [diff] [blame] | 58 | {"asdf", &imageMock}, |
| 59 | }; |
| 60 | std::vector<DataHandlerPack> data = { |
| 61 | {FirmwareBlobHandler::UpdateFlags::ipmi, nullptr}, |
| 62 | }; |
| 63 | |
Patrick Venture | 4eb5595 | 2018-11-16 15:36:24 -0800 | [diff] [blame] | 64 | sdbusplus::SdBusMock sdbus_mock; |
| 65 | auto bus_mock = sdbusplus::get_mocked_new(&sdbus_mock); |
| 66 | |
| 67 | auto handler = FirmwareBlobHandler::CreateFirmwareBlobHandler( |
Patrick Venture | 74059d6 | 2019-05-17 10:40:26 -0700 | [diff] [blame] | 68 | std::move(bus_mock), blobs, data, ""); |
Patrick Venture | 21c62c1 | 2018-11-09 17:46:58 -0800 | [diff] [blame] | 69 | |
Patrick Venture | 7dad86f | 2019-05-17 08:52:20 -0700 | [diff] [blame] | 70 | EXPECT_CALL(imageMock, open(StrEq(hashBlobId))).WillOnce(Return(true)); |
Patrick Venture | 21c62c1 | 2018-11-09 17:46:58 -0800 | [diff] [blame] | 71 | |
| 72 | EXPECT_TRUE(handler->open( |
| 73 | 0, OpenFlags::write | FirmwareBlobHandler::UpdateFlags::ipmi, |
Patrick Venture | 7dad86f | 2019-05-17 08:52:20 -0700 | [diff] [blame] | 74 | hashBlobId)); |
Patrick Venture | 21c62c1 | 2018-11-09 17:46:58 -0800 | [diff] [blame] | 75 | |
| 76 | /* The active hash blob_id was added. */ |
| 77 | auto currentBlobs = handler->getBlobIds(); |
Patrick Venture | ffcc550 | 2018-11-16 12:32:38 -0800 | [diff] [blame] | 78 | EXPECT_EQ(4, currentBlobs.size()); |
Patrick Venture | 21c62c1 | 2018-11-09 17:46:58 -0800 | [diff] [blame] | 79 | EXPECT_EQ(1, std::count(currentBlobs.begin(), currentBlobs.end(), |
Patrick Venture | 7dad86f | 2019-05-17 08:52:20 -0700 | [diff] [blame] | 80 | activeHashBlobId)); |
Patrick Venture | 21c62c1 | 2018-11-09 17:46:58 -0800 | [diff] [blame] | 81 | } |
| 82 | |
Patrick Venture | 6e307a7 | 2018-11-09 18:21:17 -0800 | [diff] [blame] | 83 | TEST(FirmwareHandlerOpenTest, OpenWithDataHandlerAllSucceeds) |
| 84 | { |
| 85 | /* Attempting to open a file that has an active handler, and use that active |
| 86 | * handler method. |
| 87 | */ |
| 88 | DataHandlerMock dataMock; |
| 89 | ImageHandlerMock imageMock; |
| 90 | |
| 91 | std::vector<HandlerPack> blobs = { |
Patrick Venture | 7dad86f | 2019-05-17 08:52:20 -0700 | [diff] [blame] | 92 | {hashBlobId, &imageMock}, |
Patrick Venture | 6e307a7 | 2018-11-09 18:21:17 -0800 | [diff] [blame] | 93 | {"asdf", &imageMock}, |
| 94 | }; |
| 95 | std::vector<DataHandlerPack> data = { |
| 96 | {FirmwareBlobHandler::UpdateFlags::ipmi, nullptr}, |
| 97 | {FirmwareBlobHandler::UpdateFlags::lpc, &dataMock}, |
| 98 | }; |
| 99 | |
Patrick Venture | 4eb5595 | 2018-11-16 15:36:24 -0800 | [diff] [blame] | 100 | sdbusplus::SdBusMock sdbus_mock; |
| 101 | auto bus_mock = sdbusplus::get_mocked_new(&sdbus_mock); |
| 102 | |
| 103 | auto handler = FirmwareBlobHandler::CreateFirmwareBlobHandler( |
Patrick Venture | 74059d6 | 2019-05-17 10:40:26 -0700 | [diff] [blame] | 104 | std::move(bus_mock), blobs, data, ""); |
Patrick Venture | 6e307a7 | 2018-11-09 18:21:17 -0800 | [diff] [blame] | 105 | |
| 106 | EXPECT_CALL(dataMock, open()).WillOnce(Return(true)); |
Patrick Venture | 7dad86f | 2019-05-17 08:52:20 -0700 | [diff] [blame] | 107 | EXPECT_CALL(imageMock, open(StrEq(hashBlobId))).WillOnce(Return(true)); |
Patrick Venture | 6e307a7 | 2018-11-09 18:21:17 -0800 | [diff] [blame] | 108 | |
| 109 | EXPECT_TRUE(handler->open( |
| 110 | 0, OpenFlags::write | FirmwareBlobHandler::UpdateFlags::lpc, |
Patrick Venture | 7dad86f | 2019-05-17 08:52:20 -0700 | [diff] [blame] | 111 | hashBlobId)); |
Patrick Venture | 6e307a7 | 2018-11-09 18:21:17 -0800 | [diff] [blame] | 112 | |
| 113 | /* The active hash blob_id was added. */ |
| 114 | auto currentBlobs = handler->getBlobIds(); |
Patrick Venture | ffcc550 | 2018-11-16 12:32:38 -0800 | [diff] [blame] | 115 | EXPECT_EQ(4, currentBlobs.size()); |
Patrick Venture | 6e307a7 | 2018-11-09 18:21:17 -0800 | [diff] [blame] | 116 | EXPECT_EQ(1, std::count(currentBlobs.begin(), currentBlobs.end(), |
Patrick Venture | 7dad86f | 2019-05-17 08:52:20 -0700 | [diff] [blame] | 117 | activeHashBlobId)); |
Patrick Venture | 6e307a7 | 2018-11-09 18:21:17 -0800 | [diff] [blame] | 118 | } |
| 119 | |
| 120 | TEST(FirmwareHandlerOpenTest, OpenWithDataHandlerReturnsFailure) |
| 121 | { |
| 122 | /* The data handler call returns failure on open, therefore open fails. */ |
| 123 | DataHandlerMock dataMock; |
| 124 | ImageHandlerMock imageMock; |
| 125 | |
| 126 | std::vector<HandlerPack> blobs = { |
Patrick Venture | 7dad86f | 2019-05-17 08:52:20 -0700 | [diff] [blame] | 127 | {hashBlobId, &imageMock}, |
Patrick Venture | 6e307a7 | 2018-11-09 18:21:17 -0800 | [diff] [blame] | 128 | {"asdf", &imageMock}, |
| 129 | }; |
| 130 | std::vector<DataHandlerPack> data = { |
| 131 | {FirmwareBlobHandler::UpdateFlags::ipmi, nullptr}, |
| 132 | {FirmwareBlobHandler::UpdateFlags::lpc, &dataMock}, |
| 133 | }; |
| 134 | |
Patrick Venture | 4eb5595 | 2018-11-16 15:36:24 -0800 | [diff] [blame] | 135 | sdbusplus::SdBusMock sdbus_mock; |
| 136 | auto bus_mock = sdbusplus::get_mocked_new(&sdbus_mock); |
| 137 | |
| 138 | auto handler = FirmwareBlobHandler::CreateFirmwareBlobHandler( |
Patrick Venture | 74059d6 | 2019-05-17 10:40:26 -0700 | [diff] [blame] | 139 | std::move(bus_mock), blobs, data, ""); |
Patrick Venture | 6e307a7 | 2018-11-09 18:21:17 -0800 | [diff] [blame] | 140 | |
| 141 | EXPECT_CALL(dataMock, open()).WillOnce(Return(false)); |
| 142 | |
| 143 | EXPECT_FALSE(handler->open( |
| 144 | 0, OpenFlags::write | FirmwareBlobHandler::UpdateFlags::lpc, |
Patrick Venture | 7dad86f | 2019-05-17 08:52:20 -0700 | [diff] [blame] | 145 | hashBlobId)); |
Patrick Venture | 6e307a7 | 2018-11-09 18:21:17 -0800 | [diff] [blame] | 146 | |
| 147 | /* The active hash blob_id was added. */ |
| 148 | auto currentBlobs = handler->getBlobIds(); |
Patrick Venture | ffcc550 | 2018-11-16 12:32:38 -0800 | [diff] [blame] | 149 | EXPECT_EQ(3, currentBlobs.size()); |
Patrick Venture | 6e307a7 | 2018-11-09 18:21:17 -0800 | [diff] [blame] | 150 | } |
| 151 | |
Patrick Venture | 991910a | 2018-11-09 19:43:48 -0800 | [diff] [blame] | 152 | TEST(FirmwareHandlerOpenTest, OpenEverythingSucceedsVerifyOpenFileCheck) |
| 153 | { |
| 154 | /* Verify only one file can be open at a time by opening a file, trying |
| 155 | * again, then closing, and trying again. |
| 156 | */ |
| 157 | ImageHandlerMock imageMock1, imageMock2; |
| 158 | |
| 159 | std::vector<HandlerPack> blobs = { |
Patrick Venture | 7dad86f | 2019-05-17 08:52:20 -0700 | [diff] [blame] | 160 | {hashBlobId, &imageMock1}, |
Patrick Venture | 991910a | 2018-11-09 19:43:48 -0800 | [diff] [blame] | 161 | {"asdf", &imageMock2}, |
| 162 | }; |
| 163 | std::vector<DataHandlerPack> data = { |
| 164 | {FirmwareBlobHandler::UpdateFlags::ipmi, nullptr}, |
| 165 | }; |
| 166 | |
Patrick Venture | 4eb5595 | 2018-11-16 15:36:24 -0800 | [diff] [blame] | 167 | sdbusplus::SdBusMock sdbus_mock; |
| 168 | auto bus_mock = sdbusplus::get_mocked_new(&sdbus_mock); |
| 169 | |
| 170 | auto handler = FirmwareBlobHandler::CreateFirmwareBlobHandler( |
Patrick Venture | 74059d6 | 2019-05-17 10:40:26 -0700 | [diff] [blame] | 171 | std::move(bus_mock), blobs, data, ""); |
Patrick Venture | 991910a | 2018-11-09 19:43:48 -0800 | [diff] [blame] | 172 | |
| 173 | EXPECT_CALL(imageMock2, open("asdf")).WillOnce(Return(true)); |
| 174 | |
| 175 | EXPECT_TRUE(handler->open( |
| 176 | 0, OpenFlags::write | FirmwareBlobHandler::UpdateFlags::ipmi, "asdf")); |
| 177 | |
| 178 | /* The active image blob_id was added. */ |
| 179 | auto currentBlobs = handler->getBlobIds(); |
Patrick Venture | ffcc550 | 2018-11-16 12:32:38 -0800 | [diff] [blame] | 180 | EXPECT_EQ(4, currentBlobs.size()); |
Patrick Venture | 991910a | 2018-11-09 19:43:48 -0800 | [diff] [blame] | 181 | EXPECT_EQ(1, std::count(currentBlobs.begin(), currentBlobs.end(), |
Patrick Venture | 7dad86f | 2019-05-17 08:52:20 -0700 | [diff] [blame] | 182 | activeImageBlobId)); |
Patrick Venture | 991910a | 2018-11-09 19:43:48 -0800 | [diff] [blame] | 183 | |
| 184 | /* Open the hash file (since we opened an image file). */ |
| 185 | EXPECT_FALSE(handler->open( |
| 186 | 1, OpenFlags::write | FirmwareBlobHandler::UpdateFlags::ipmi, |
Patrick Venture | 7dad86f | 2019-05-17 08:52:20 -0700 | [diff] [blame] | 187 | hashBlobId)); |
Patrick Venture | 991910a | 2018-11-09 19:43:48 -0800 | [diff] [blame] | 188 | |
Patrick Venture | 68bb143 | 2018-11-09 20:08:48 -0800 | [diff] [blame] | 189 | EXPECT_TRUE(handler->close(0)); |
Patrick Venture | 991910a | 2018-11-09 19:43:48 -0800 | [diff] [blame] | 190 | |
Patrick Venture | 7dad86f | 2019-05-17 08:52:20 -0700 | [diff] [blame] | 191 | EXPECT_CALL(imageMock1, open(StrEq(hashBlobId))).WillOnce(Return(true)); |
Patrick Venture | 991910a | 2018-11-09 19:43:48 -0800 | [diff] [blame] | 192 | |
| 193 | EXPECT_TRUE(handler->open( |
| 194 | 1, OpenFlags::write | FirmwareBlobHandler::UpdateFlags::ipmi, |
Patrick Venture | 7dad86f | 2019-05-17 08:52:20 -0700 | [diff] [blame] | 195 | hashBlobId)); |
Patrick Venture | 991910a | 2018-11-09 19:43:48 -0800 | [diff] [blame] | 196 | } |
| 197 | |
Patrick Venture | 21c62c1 | 2018-11-09 17:46:58 -0800 | [diff] [blame] | 198 | TEST(FirmwareHandlerOpenTest, OpenEverythingSucceedsOpenActiveFails) |
| 199 | { |
| 200 | /* Attempting to open the active image blob, when it's present will fail. |
| 201 | * |
| 202 | * TODO: We'll need another test that closes first because you can only have |
| 203 | * one file open at a time. |
| 204 | */ |
| 205 | ImageHandlerMock imageMock; |
| 206 | |
| 207 | std::vector<HandlerPack> blobs = { |
Patrick Venture | 7dad86f | 2019-05-17 08:52:20 -0700 | [diff] [blame] | 208 | {hashBlobId, &imageMock}, |
Patrick Venture | 21c62c1 | 2018-11-09 17:46:58 -0800 | [diff] [blame] | 209 | {"asdf", &imageMock}, |
| 210 | }; |
| 211 | std::vector<DataHandlerPack> data = { |
| 212 | {FirmwareBlobHandler::UpdateFlags::ipmi, nullptr}, |
| 213 | }; |
| 214 | |
Patrick Venture | 4eb5595 | 2018-11-16 15:36:24 -0800 | [diff] [blame] | 215 | sdbusplus::SdBusMock sdbus_mock; |
| 216 | auto bus_mock = sdbusplus::get_mocked_new(&sdbus_mock); |
| 217 | |
| 218 | auto handler = FirmwareBlobHandler::CreateFirmwareBlobHandler( |
Patrick Venture | 74059d6 | 2019-05-17 10:40:26 -0700 | [diff] [blame] | 219 | std::move(bus_mock), blobs, data, ""); |
Patrick Venture | 21c62c1 | 2018-11-09 17:46:58 -0800 | [diff] [blame] | 220 | |
| 221 | EXPECT_CALL(imageMock, open("asdf")).WillOnce(Return(true)); |
| 222 | |
| 223 | EXPECT_TRUE(handler->open( |
| 224 | 0, OpenFlags::write | FirmwareBlobHandler::UpdateFlags::ipmi, "asdf")); |
| 225 | |
| 226 | /* The active image blob_id was added. */ |
| 227 | auto currentBlobs = handler->getBlobIds(); |
Patrick Venture | ffcc550 | 2018-11-16 12:32:38 -0800 | [diff] [blame] | 228 | EXPECT_EQ(4, currentBlobs.size()); |
Patrick Venture | 21c62c1 | 2018-11-09 17:46:58 -0800 | [diff] [blame] | 229 | EXPECT_EQ(1, std::count(currentBlobs.begin(), currentBlobs.end(), |
Patrick Venture | 7dad86f | 2019-05-17 08:52:20 -0700 | [diff] [blame] | 230 | activeImageBlobId)); |
Patrick Venture | 21c62c1 | 2018-11-09 17:46:58 -0800 | [diff] [blame] | 231 | |
Patrick Venture | 991910a | 2018-11-09 19:43:48 -0800 | [diff] [blame] | 232 | /* Close only active session, to verify it's failing on attempt to open a |
| 233 | * specific blob_id. |
| 234 | */ |
Patrick Venture | 68bb143 | 2018-11-09 20:08:48 -0800 | [diff] [blame] | 235 | EXPECT_TRUE(handler->close(0)); |
Patrick Venture | 991910a | 2018-11-09 19:43:48 -0800 | [diff] [blame] | 236 | |
Patrick Venture | 21c62c1 | 2018-11-09 17:46:58 -0800 | [diff] [blame] | 237 | EXPECT_FALSE(handler->open( |
| 238 | 1, OpenFlags::write | FirmwareBlobHandler::UpdateFlags::ipmi, |
Patrick Venture | 7dad86f | 2019-05-17 08:52:20 -0700 | [diff] [blame] | 239 | activeImageBlobId)); |
Patrick Venture | 72388d7 | 2018-11-07 15:06:36 -0800 | [diff] [blame] | 240 | } |
| 241 | |
| 242 | TEST(FirmwareHandlerOpenTest, OpenWithEverythingValidImageHandlerFails) |
| 243 | { |
| 244 | /* The image handler for a specific type of image is allowed to return |
| 245 | * failure on open. let's simulate that. */ |
| 246 | |
| 247 | ImageHandlerMock imageMock; |
| 248 | |
| 249 | std::vector<HandlerPack> blobs = { |
Patrick Venture | 7dad86f | 2019-05-17 08:52:20 -0700 | [diff] [blame] | 250 | {hashBlobId, &imageMock}, |
Patrick Venture | 72388d7 | 2018-11-07 15:06:36 -0800 | [diff] [blame] | 251 | {"asdf", &imageMock}, |
| 252 | }; |
| 253 | std::vector<DataHandlerPack> data = { |
Patrick Venture | 05abf7e | 2018-11-09 11:02:56 -0800 | [diff] [blame] | 254 | {FirmwareBlobHandler::UpdateFlags::ipmi, nullptr}, |
Patrick Venture | 72388d7 | 2018-11-07 15:06:36 -0800 | [diff] [blame] | 255 | }; |
| 256 | |
Patrick Venture | 4eb5595 | 2018-11-16 15:36:24 -0800 | [diff] [blame] | 257 | sdbusplus::SdBusMock sdbus_mock; |
| 258 | auto bus_mock = sdbusplus::get_mocked_new(&sdbus_mock); |
| 259 | |
| 260 | auto handler = FirmwareBlobHandler::CreateFirmwareBlobHandler( |
Patrick Venture | 74059d6 | 2019-05-17 10:40:26 -0700 | [diff] [blame] | 261 | std::move(bus_mock), blobs, data, ""); |
Patrick Venture | 72388d7 | 2018-11-07 15:06:36 -0800 | [diff] [blame] | 262 | |
| 263 | EXPECT_CALL(imageMock, open("asdf")).WillOnce(Return(false)); |
| 264 | |
| 265 | EXPECT_FALSE(handler->open( |
Patrick Venture | 05abf7e | 2018-11-09 11:02:56 -0800 | [diff] [blame] | 266 | 0, OpenFlags::write | FirmwareBlobHandler::UpdateFlags::ipmi, "asdf")); |
Patrick Venture | db253bf | 2018-11-09 19:36:03 -0800 | [diff] [blame] | 267 | |
| 268 | /* Verify blob_id list doesn't grow. */ |
| 269 | auto currentBlobs = handler->getBlobIds(); |
Patrick Venture | ffcc550 | 2018-11-16 12:32:38 -0800 | [diff] [blame] | 270 | EXPECT_EQ(3, currentBlobs.size()); |
Patrick Venture | 72388d7 | 2018-11-07 15:06:36 -0800 | [diff] [blame] | 271 | } |
| 272 | |
| 273 | TEST(FirmwareHandlerOpenTest, OpenWithoutWriteFails) |
| 274 | { |
| 275 | /* The client must set the file write bit. */ |
| 276 | |
| 277 | ImageHandlerMock imageMock; |
| 278 | |
| 279 | std::vector<HandlerPack> blobs = { |
Patrick Venture | 7dad86f | 2019-05-17 08:52:20 -0700 | [diff] [blame] | 280 | {hashBlobId, &imageMock}, |
Patrick Venture | 72388d7 | 2018-11-07 15:06:36 -0800 | [diff] [blame] | 281 | {"asdf", &imageMock}, |
| 282 | }; |
| 283 | std::vector<DataHandlerPack> data = { |
Patrick Venture | 05abf7e | 2018-11-09 11:02:56 -0800 | [diff] [blame] | 284 | {FirmwareBlobHandler::UpdateFlags::ipmi, nullptr}, |
Patrick Venture | 72388d7 | 2018-11-07 15:06:36 -0800 | [diff] [blame] | 285 | }; |
| 286 | |
Patrick Venture | 4eb5595 | 2018-11-16 15:36:24 -0800 | [diff] [blame] | 287 | sdbusplus::SdBusMock sdbus_mock; |
| 288 | auto bus_mock = sdbusplus::get_mocked_new(&sdbus_mock); |
| 289 | |
| 290 | auto handler = FirmwareBlobHandler::CreateFirmwareBlobHandler( |
Patrick Venture | 74059d6 | 2019-05-17 10:40:26 -0700 | [diff] [blame] | 291 | std::move(bus_mock), blobs, data, ""); |
Patrick Venture | 72388d7 | 2018-11-07 15:06:36 -0800 | [diff] [blame] | 292 | |
Patrick Venture | 05abf7e | 2018-11-09 11:02:56 -0800 | [diff] [blame] | 293 | EXPECT_FALSE( |
| 294 | handler->open(0, FirmwareBlobHandler::UpdateFlags::ipmi, "asdf")); |
Patrick Venture | 72388d7 | 2018-11-07 15:06:36 -0800 | [diff] [blame] | 295 | } |
| 296 | |
| 297 | TEST(FirmwareHandlerOpenTest, OpenWithInvalidTransportBit) |
| 298 | { |
| 299 | /* The client sends a request with a transport mechanism not supported. */ |
| 300 | |
| 301 | ImageHandlerMock imageMock; |
| 302 | |
| 303 | std::vector<HandlerPack> blobs = { |
Patrick Venture | 7dad86f | 2019-05-17 08:52:20 -0700 | [diff] [blame] | 304 | {hashBlobId, &imageMock}, |
Patrick Venture | 72388d7 | 2018-11-07 15:06:36 -0800 | [diff] [blame] | 305 | {"asdf", &imageMock}, |
| 306 | }; |
| 307 | std::vector<DataHandlerPack> data = { |
Patrick Venture | 05abf7e | 2018-11-09 11:02:56 -0800 | [diff] [blame] | 308 | {FirmwareBlobHandler::UpdateFlags::ipmi, nullptr}, |
Patrick Venture | 72388d7 | 2018-11-07 15:06:36 -0800 | [diff] [blame] | 309 | }; |
| 310 | |
Patrick Venture | 4eb5595 | 2018-11-16 15:36:24 -0800 | [diff] [blame] | 311 | sdbusplus::SdBusMock sdbus_mock; |
| 312 | auto bus_mock = sdbusplus::get_mocked_new(&sdbus_mock); |
| 313 | |
| 314 | auto handler = FirmwareBlobHandler::CreateFirmwareBlobHandler( |
Patrick Venture | 74059d6 | 2019-05-17 10:40:26 -0700 | [diff] [blame] | 315 | std::move(bus_mock), blobs, data, ""); |
Patrick Venture | 72388d7 | 2018-11-07 15:06:36 -0800 | [diff] [blame] | 316 | |
Patrick Venture | 05abf7e | 2018-11-09 11:02:56 -0800 | [diff] [blame] | 317 | EXPECT_FALSE( |
| 318 | handler->open(0, FirmwareBlobHandler::UpdateFlags::lpc, "asdf")); |
Patrick Venture | 72388d7 | 2018-11-07 15:06:36 -0800 | [diff] [blame] | 319 | } |
| 320 | |
| 321 | TEST(FirmwareHandlerOpenTest, OpenWithInvalidImageBlobId) |
| 322 | { |
| 323 | /* The client sends a request with an invalid image blob_id. */ |
| 324 | |
| 325 | ImageHandlerMock imageMock; |
| 326 | |
| 327 | std::vector<HandlerPack> blobs = { |
Patrick Venture | 7dad86f | 2019-05-17 08:52:20 -0700 | [diff] [blame] | 328 | {hashBlobId, &imageMock}, |
Patrick Venture | 72388d7 | 2018-11-07 15:06:36 -0800 | [diff] [blame] | 329 | {"asdf", &imageMock}, |
| 330 | }; |
| 331 | std::vector<DataHandlerPack> data = { |
Patrick Venture | 05abf7e | 2018-11-09 11:02:56 -0800 | [diff] [blame] | 332 | {FirmwareBlobHandler::UpdateFlags::ipmi, nullptr}, |
Patrick Venture | 72388d7 | 2018-11-07 15:06:36 -0800 | [diff] [blame] | 333 | }; |
| 334 | |
Patrick Venture | 4eb5595 | 2018-11-16 15:36:24 -0800 | [diff] [blame] | 335 | sdbusplus::SdBusMock sdbus_mock; |
| 336 | auto bus_mock = sdbusplus::get_mocked_new(&sdbus_mock); |
| 337 | |
| 338 | auto handler = FirmwareBlobHandler::CreateFirmwareBlobHandler( |
Patrick Venture | 74059d6 | 2019-05-17 10:40:26 -0700 | [diff] [blame] | 339 | std::move(bus_mock), blobs, data, ""); |
Patrick Venture | 72388d7 | 2018-11-07 15:06:36 -0800 | [diff] [blame] | 340 | |
| 341 | EXPECT_FALSE(handler->open( |
Patrick Venture | 05abf7e | 2018-11-09 11:02:56 -0800 | [diff] [blame] | 342 | 0, OpenFlags::write | FirmwareBlobHandler::UpdateFlags::ipmi, "bcdf")); |
Patrick Venture | 72388d7 | 2018-11-07 15:06:36 -0800 | [diff] [blame] | 343 | } |
| 344 | |
| 345 | /* TODO: The client sends a request during verification. */ |
| 346 | /* TODO: The client sends a second request to open when there is already an open |
| 347 | * file. |
| 348 | */ |
| 349 | /* TODO: The client sends a request to open active image. */ |
| 350 | /* TODO: The client sends a request to open active hash. */ |
| 351 | |
| 352 | } // namespace blobs |