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