blob: ac21a1ec1d257fa5413cd32c017cf577706b61a8 [file] [log] [blame]
Patrick Ventureaa32a362018-12-13 10:52:33 -08001#include "data_interface_mock.hpp"
Patrick Venture84778b82019-06-26 20:11:09 -07002#include "flags.hpp"
Patrick Venture1f09d412019-06-19 16:01:06 -07003#include "status.hpp"
Patrick Venture5f2fcc42019-06-20 07:21:05 -07004#include "tool_errors.hpp"
Patrick Ventureaa32a362018-12-13 10:52:33 -08005#include "updater.hpp"
Patrick Venture55646de2019-05-16 10:06:26 -07006#include "updater_mock.hpp"
Patrick Venture7dad86f2019-05-17 08:52:20 -07007#include "util.hpp"
Patrick Ventureaa32a362018-12-13 10:52:33 -08008
Jie Yang328f5202021-03-16 00:52:07 -07009#include <blobs-ipmid/blobs.hpp>
Patrick Venture8cdf9642020-09-30 09:41:51 -070010#include <ipmiblob/blob_errors.hpp>
Patrick Venture664c5bc2019-03-07 08:09:45 -080011#include <ipmiblob/test/blob_interface_mock.hpp>
Patrick Venture9b37b092020-05-28 20:58:57 -070012
Patrick Ventureaa32a362018-12-13 10:52:33 -080013#include <string>
Patrick Venture8cdf9642020-09-30 09:41:51 -070014#include <vector>
Patrick Ventureaa32a362018-12-13 10:52:33 -080015
Patrick Venture8cdf9642020-09-30 09:41:51 -070016#include <gmock/gmock.h>
Patrick Ventureaa32a362018-12-13 10:52:33 -080017#include <gtest/gtest.h>
18
Patrick Venture9b534f02018-12-13 16:10:02 -080019namespace host_tool
20{
21
Patrick Venture7dcca5d2019-05-15 12:32:33 -070022using ::testing::_;
Patrick Ventureaa32a362018-12-13 10:52:33 -080023using ::testing::Return;
Patrick Venture8cdf9642020-09-30 09:41:51 -070024using ::testing::Throw;
Patrick Ventureb58f5612019-05-07 09:22:07 -070025using ::testing::TypedEq;
Patrick Ventureaa32a362018-12-13 10:52:33 -080026
Patrick Venture1f09d412019-06-19 16:01:06 -070027class UpdateHandlerTest : public ::testing::Test
Patrick Venture55646de2019-05-16 10:06:26 -070028{
Patrick Venture1f09d412019-06-19 16:01:06 -070029 protected:
30 const std::uint16_t session = 0xbeef;
31
Patrick Venture55646de2019-05-16 10:06:26 -070032 DataInterfaceMock handlerMock;
33 ipmiblob::BlobInterfaceMock blobMock;
Patrick Venture1f09d412019-06-19 16:01:06 -070034 UpdateHandler updater{&blobMock, &handlerMock};
35};
Patrick Venture55646de2019-05-16 10:06:26 -070036
Patrick Venture1f09d412019-06-19 16:01:06 -070037TEST_F(UpdateHandlerTest, CheckAvailableSuccess)
38{
Patrick Venture55646de2019-05-16 10:06:26 -070039 EXPECT_CALL(blobMock, getBlobList())
Patrick Venture7dad86f2019-05-17 08:52:20 -070040 .WillOnce(
Patrick Venture1d5a31c2019-05-20 11:38:22 -070041 Return(std::vector<std::string>({ipmi_flash::staticLayoutBlobId})));
Patrick Venture55646de2019-05-16 10:06:26 -070042
Patrick Venture1d5a31c2019-05-20 11:38:22 -070043 EXPECT_TRUE(updater.checkAvailable(ipmi_flash::staticLayoutBlobId));
Patrick Venture55646de2019-05-16 10:06:26 -070044}
45
Patrick Venture8cdf9642020-09-30 09:41:51 -070046TEST_F(UpdateHandlerTest, CheckAvailableFailure)
47{
48 EXPECT_CALL(blobMock, getBlobList())
49 .WillOnce(Return(std::vector<std::string>()));
50
51 EXPECT_FALSE(updater.checkAvailable(ipmi_flash::staticLayoutBlobId));
52}
53
Patrick Venture1f09d412019-06-19 16:01:06 -070054TEST_F(UpdateHandlerTest, SendFileSuccess)
Patrick Venture55646de2019-05-16 10:06:26 -070055{
56 /* Call sendFile to verify it does what we expect. */
Patrick Venture55646de2019-05-16 10:06:26 -070057 std::string firmwareImage = "image.bin";
58
59 std::uint16_t supported =
60 static_cast<std::uint16_t>(
Patrick Venture84778b82019-06-26 20:11:09 -070061 ipmi_flash::FirmwareFlags::UpdateFlags::lpc) |
62 static_cast<std::uint16_t>(
63 ipmi_flash::FirmwareFlags::UpdateFlags::openWrite);
Patrick Venture55646de2019-05-16 10:06:26 -070064
65 EXPECT_CALL(handlerMock, supportedType())
Patrick Venture84778b82019-06-26 20:11:09 -070066 .WillOnce(Return(ipmi_flash::FirmwareFlags::UpdateFlags::lpc));
Patrick Venture55646de2019-05-16 10:06:26 -070067
Patrick Venture1f09d412019-06-19 16:01:06 -070068 EXPECT_CALL(blobMock, openBlob(ipmi_flash::staticLayoutBlobId, supported))
Patrick Venture55646de2019-05-16 10:06:26 -070069 .WillOnce(Return(session));
70
Patrick Venture1f09d412019-06-19 16:01:06 -070071 EXPECT_CALL(handlerMock, sendContents(firmwareImage, session))
Patrick Venture55646de2019-05-16 10:06:26 -070072 .WillOnce(Return(true));
73
74 EXPECT_CALL(blobMock, closeBlob(session)).Times(1);
75
Patrick Venture1d5a31c2019-05-20 11:38:22 -070076 updater.sendFile(ipmi_flash::staticLayoutBlobId, firmwareImage);
Patrick Venture55646de2019-05-16 10:06:26 -070077}
78
Patrick Venture8cdf9642020-09-30 09:41:51 -070079TEST_F(UpdateHandlerTest, SendFileExceptsOnBlobOpening)
80{
81 std::string firmwareImage = "image.bin";
82
83 std::uint16_t supported =
84 static_cast<std::uint16_t>(
85 ipmi_flash::FirmwareFlags::UpdateFlags::lpc) |
86 static_cast<std::uint16_t>(
87 ipmi_flash::FirmwareFlags::UpdateFlags::openWrite);
88
89 EXPECT_CALL(handlerMock, supportedType())
90 .WillOnce(Return(ipmi_flash::FirmwareFlags::UpdateFlags::lpc));
91
92 EXPECT_CALL(blobMock, openBlob(ipmi_flash::staticLayoutBlobId, supported))
93 .WillOnce(Throw(ipmiblob::BlobException("asdf")));
94
95 EXPECT_THROW(
96 updater.sendFile(ipmi_flash::staticLayoutBlobId, firmwareImage),
97 ToolException);
98}
99
100TEST_F(UpdateHandlerTest, SendFileHandlerFailureCausesException)
101{
102 std::string firmwareImage = "image.bin";
103
104 std::uint16_t supported =
105 static_cast<std::uint16_t>(
106 ipmi_flash::FirmwareFlags::UpdateFlags::lpc) |
107 static_cast<std::uint16_t>(
108 ipmi_flash::FirmwareFlags::UpdateFlags::openWrite);
109
110 EXPECT_CALL(handlerMock, supportedType())
Willy Tu1b23b772023-03-15 01:33:03 -0700111 .WillRepeatedly(Return(ipmi_flash::FirmwareFlags::UpdateFlags::lpc));
Patrick Venture8cdf9642020-09-30 09:41:51 -0700112
113 EXPECT_CALL(blobMock, openBlob(ipmi_flash::staticLayoutBlobId, supported))
Willy Tu1b23b772023-03-15 01:33:03 -0700114 .WillRepeatedly(Return(session));
Patrick Venture8cdf9642020-09-30 09:41:51 -0700115
116 EXPECT_CALL(handlerMock, sendContents(firmwareImage, session))
Willy Tu1b23b772023-03-15 01:33:03 -0700117 .WillRepeatedly(Return(false));
Patrick Venture8cdf9642020-09-30 09:41:51 -0700118
Willy Tu1b23b772023-03-15 01:33:03 -0700119 EXPECT_CALL(blobMock, closeBlob(session)).Times(3);
Patrick Venture8cdf9642020-09-30 09:41:51 -0700120
121 EXPECT_THROW(
122 updater.sendFile(ipmi_flash::staticLayoutBlobId, firmwareImage),
123 ToolException);
124}
125
Willy Tu1b23b772023-03-15 01:33:03 -0700126TEST_F(UpdateHandlerTest, SendFileHandlerPassWithRetries)
127{
128 std::string firmwareImage = "image.bin";
129
130 std::uint16_t supported =
131 static_cast<std::uint16_t>(
132 ipmi_flash::FirmwareFlags::UpdateFlags::lpc) |
133 static_cast<std::uint16_t>(
134 ipmi_flash::FirmwareFlags::UpdateFlags::openWrite);
135
136 EXPECT_CALL(handlerMock, supportedType())
137 .WillRepeatedly(Return(ipmi_flash::FirmwareFlags::UpdateFlags::lpc));
138
139 EXPECT_CALL(blobMock, openBlob(ipmi_flash::staticLayoutBlobId, supported))
140 .WillRepeatedly(Return(session));
141
142 EXPECT_CALL(handlerMock, sendContents(firmwareImage, session))
143 .WillOnce(Return(false))
144 .WillOnce(Return(false))
145 .WillOnce(Return(true));
146
147 EXPECT_CALL(blobMock, closeBlob(session)).Times(3);
148
149 updater.sendFile(ipmi_flash::staticLayoutBlobId, firmwareImage);
150}
151
Patrick Venture1f09d412019-06-19 16:01:06 -0700152TEST_F(UpdateHandlerTest, VerifyFileHandleReturnsTrueOnSuccess)
Patrick Ventureaa32a362018-12-13 10:52:33 -0800153{
Patrick Venture1f09d412019-06-19 16:01:06 -0700154 EXPECT_CALL(blobMock, openBlob(ipmi_flash::verifyBlobId, _))
Patrick Ventureaa32a362018-12-13 10:52:33 -0800155 .WillOnce(Return(session));
Patrick Venture55646de2019-05-16 10:06:26 -0700156 EXPECT_CALL(blobMock, commit(session, _)).WillOnce(Return());
Patrick Venture1f09d412019-06-19 16:01:06 -0700157 ipmiblob::StatResponse verificationResponse = {};
158 /* the other details of the response are ignored, and should be. */
159 verificationResponse.metadata.push_back(
160 static_cast<std::uint8_t>(ipmi_flash::ActionStatus::success));
Patrick Venture7dcca5d2019-05-15 12:32:33 -0700161
Patrick Venture1f09d412019-06-19 16:01:06 -0700162 EXPECT_CALL(blobMock, getStat(TypedEq<std::uint16_t>(session)))
163 .WillOnce(Return(verificationResponse));
164 EXPECT_CALL(blobMock, closeBlob(session)).WillOnce(Return());
165
Brandon Kim6749ba12019-09-19 13:31:37 -0700166 EXPECT_TRUE(updater.verifyFile(ipmi_flash::verifyBlobId, false));
Patrick Venture1f09d412019-06-19 16:01:06 -0700167}
168
Patrick Venture8cdf9642020-09-30 09:41:51 -0700169TEST_F(UpdateHandlerTest, VerifyFileHandleSkipsPollingIfIgnoreStatus)
170{
171 /* if ignoreStatus, it'll skip polling for a verification result. */
172 EXPECT_CALL(blobMock, openBlob(ipmi_flash::verifyBlobId, _))
173 .WillOnce(Return(session));
174 EXPECT_CALL(blobMock, commit(session, _)).WillOnce(Return());
175
176 EXPECT_CALL(blobMock, closeBlob(session)).WillOnce(Return());
177
178 EXPECT_TRUE(updater.verifyFile(ipmi_flash::verifyBlobId, true));
179}
180
181TEST_F(UpdateHandlerTest, VerifyFileConvertsOpenBlobExceptionToToolException)
182{
183 /* On open, it can except and this is converted to a ToolException. */
184 EXPECT_CALL(blobMock, openBlob(ipmi_flash::verifyBlobId, _))
185 .WillOnce(Throw(ipmiblob::BlobException("asdf")));
186 EXPECT_THROW(updater.verifyFile(ipmi_flash::verifyBlobId, false),
187 ToolException);
188}
189
190TEST_F(UpdateHandlerTest, VerifyFileCommitExceptionForwards)
191{
192 /* On commit, it can except. */
193 EXPECT_CALL(blobMock, openBlob(ipmi_flash::verifyBlobId, _))
194 .WillOnce(Return(session));
195 EXPECT_CALL(blobMock, commit(session, _))
196 .WillOnce(Throw(ipmiblob::BlobException("asdf")));
197 EXPECT_THROW(updater.verifyFile(ipmi_flash::verifyBlobId, false),
198 ToolException);
199}
200
Jie Yang328f5202021-03-16 00:52:07 -0700201TEST_F(UpdateHandlerTest, ReadVerisonReturnExpected)
202{
203 /* It can return as expected, when polling and readBytes succeeds. */
204 EXPECT_CALL(blobMock, openBlob(ipmi_flash::biosVersionBlobId, _))
205 .WillOnce(Return(session));
206 ipmiblob::StatResponse readVersionResponse = {};
Patrick Williams10388362023-05-10 07:51:09 -0500207 readVersionResponse.blob_state = blobs::StateFlags::open_read |
208 blobs::StateFlags::committed;
Jie Yang328f5202021-03-16 00:52:07 -0700209 readVersionResponse.size = 10;
210 EXPECT_CALL(blobMock, getStat(TypedEq<std::uint16_t>(session)))
211 .WillOnce(Return(readVersionResponse));
212 std::vector<uint8_t> resp = {0x2d, 0xfe};
213 EXPECT_CALL(blobMock, readBytes(session, 0, _)).WillOnce(Return(resp));
214
215 EXPECT_CALL(blobMock, closeBlob(session)).WillOnce(Return());
216 EXPECT_EQ(resp, updater.readVersion(ipmi_flash::biosVersionBlobId));
217}
218
219TEST_F(UpdateHandlerTest, ReadVersionExceptionWhenPollingSucceedsReadBytesFails)
220{
221 /* On readBytes, it can except. */
222 EXPECT_CALL(blobMock, openBlob(ipmi_flash::biosVersionBlobId, _))
223 .WillOnce(Return(session));
224 ipmiblob::StatResponse readVersionResponse = {};
Patrick Williams10388362023-05-10 07:51:09 -0500225 readVersionResponse.blob_state = blobs::StateFlags::open_read |
226 blobs::StateFlags::committed;
Jie Yang328f5202021-03-16 00:52:07 -0700227 readVersionResponse.size = 10;
228 EXPECT_CALL(blobMock, getStat(TypedEq<std::uint16_t>(session)))
229 .WillOnce(Return(readVersionResponse));
230 EXPECT_CALL(blobMock, readBytes(session, 0, _))
231 .WillOnce(Throw(ipmiblob::BlobException("asdf")));
232 EXPECT_CALL(blobMock, closeBlob(session)).WillOnce(Return());
233 EXPECT_THROW(updater.readVersion(ipmi_flash::biosVersionBlobId),
234 ToolException);
235}
236
William A. Kennington IIIf88bcf32021-10-14 02:15:10 -0700237TEST_F(UpdateHandlerTest, ReadVersionReturnsErrorIfPollingFails)
Jie Yang328f5202021-03-16 00:52:07 -0700238{
William A. Kennington IIIf88bcf32021-10-14 02:15:10 -0700239 /* It can throw an error, when polling fails. */
Jie Yang328f5202021-03-16 00:52:07 -0700240 EXPECT_CALL(blobMock, openBlob(ipmi_flash::biosVersionBlobId, _))
241 .WillOnce(Return(session));
242 ipmiblob::StatResponse readVersionResponse = {};
243 readVersionResponse.blob_state = blobs::StateFlags::commit_error;
244 EXPECT_CALL(blobMock, getStat(TypedEq<std::uint16_t>(session)))
245 .WillOnce(Return(readVersionResponse));
246 EXPECT_CALL(blobMock, closeBlob(session)).WillOnce(Return());
William A. Kennington IIIf88bcf32021-10-14 02:15:10 -0700247 EXPECT_THROW(updater.readVersion(ipmi_flash::biosVersionBlobId),
248 ToolException);
Jie Yang328f5202021-03-16 00:52:07 -0700249}
250
251TEST_F(UpdateHandlerTest, ReadVersionCovertsOpenBlobExceptionToToolException)
252{
253 /* On open, it can except and this is converted to a ToolException. */
254 EXPECT_CALL(blobMock, openBlob(ipmi_flash::biosVersionBlobId, _))
255 .WillOnce(Throw(ipmiblob::BlobException("asdf")));
256 EXPECT_THROW(updater.readVersion(ipmi_flash::biosVersionBlobId),
257 ToolException);
258}
259
Patrick Venture8cdf9642020-09-30 09:41:51 -0700260TEST_F(UpdateHandlerTest, CleanArtifactsSkipsCleanupIfUnableToOpen)
261{
262 /* It only tries to commit if it's able to open the blob. However, if
263 * committing fails, this error is ignored.
264 */
265 EXPECT_CALL(blobMock, openBlob(ipmi_flash::cleanupBlobId, _))
266 .WillOnce(Throw(ipmiblob::BlobException("asdf")));
267 EXPECT_CALL(blobMock, commit(_, _)).Times(0);
268 EXPECT_CALL(blobMock, closeBlob(_)).Times(0);
269
270 updater.cleanArtifacts();
271}
272
273TEST_F(UpdateHandlerTest, CleanArtifactsIfOpenDoesClose)
274{
275 /* The closeBlob call is called even if commit excepts. */
276 std::uint16_t session = 0xa5eb;
277 EXPECT_CALL(blobMock, openBlob(ipmi_flash::cleanupBlobId, _))
278 .WillOnce(Return(session));
279 EXPECT_CALL(blobMock, commit(session, _))
280 .WillOnce(Throw(ipmiblob::BlobException("asdf")));
281 EXPECT_CALL(blobMock, closeBlob(session));
282
283 updater.cleanArtifacts();
284}
285
286TEST_F(UpdateHandlerTest, CleanArtifactsSuccessPath)
287{
288 std::uint16_t session = 0xa5eb;
289 EXPECT_CALL(blobMock, openBlob(ipmi_flash::cleanupBlobId, _))
290 .WillOnce(Return(session));
291 EXPECT_CALL(blobMock, commit(session, _));
292 EXPECT_CALL(blobMock, closeBlob(session));
293
294 updater.cleanArtifacts();
295}
296
Patrick Venture1f09d412019-06-19 16:01:06 -0700297class UpdaterTest : public ::testing::Test
298{
299 protected:
Patrick Venture8cdf9642020-09-30 09:41:51 -0700300 static constexpr char image[] = "image.bin";
301 static constexpr char signature[] = "signature.bin";
302 static constexpr char layout[] = "static";
303 static constexpr char path[] = "/flash/static";
304
Patrick Venture1f09d412019-06-19 16:01:06 -0700305 ipmiblob::BlobInterfaceMock blobMock;
306 std::uint16_t session = 0xbeef;
Brandon Kim6749ba12019-09-19 13:31:37 -0700307 bool defaultIgnore = false;
Patrick Venture1f09d412019-06-19 16:01:06 -0700308};
309
Patrick Venture1f09d412019-06-19 16:01:06 -0700310TEST_F(UpdaterTest, UpdateMainReturnsSuccessIfAllSuccess)
311{
Patrick Venture1f09d412019-06-19 16:01:06 -0700312 UpdateHandlerMock handler;
313
Patrick Venture8cdf9642020-09-30 09:41:51 -0700314 EXPECT_CALL(handler, checkAvailable(path)).WillOnce(Return(true));
315 EXPECT_CALL(handler, sendFile(path, image)).WillOnce(Return());
316 EXPECT_CALL(handler, sendFile(ipmi_flash::hashBlobId, signature))
317 .WillOnce(Return());
Brandon Kim6749ba12019-09-19 13:31:37 -0700318 EXPECT_CALL(handler, verifyFile(ipmi_flash::verifyBlobId, defaultIgnore))
Patrick Venture1f09d412019-06-19 16:01:06 -0700319 .WillOnce(Return(true));
Brandon Kim6749ba12019-09-19 13:31:37 -0700320 EXPECT_CALL(handler, verifyFile(ipmi_flash::updateBlobId, defaultIgnore))
Patrick Venture1f09d412019-06-19 16:01:06 -0700321 .WillOnce(Return(true));
Willy Tu203ad802021-09-09 20:06:36 -0700322 EXPECT_CALL(blobMock, getBlobList())
323 .WillOnce(Return(std::vector<std::string>({})));
Patrick Venture1f09d412019-06-19 16:01:06 -0700324
Willy Tu203ad802021-09-09 20:06:36 -0700325 updaterMain(&handler, &blobMock, image, signature, layout, defaultIgnore);
326}
327
328TEST_F(UpdaterTest, UpdateMainReturnsSuccessIfAllSuccessWithDeleteActiveBlob)
329{
330 UpdateHandlerMock handler;
331
332 EXPECT_CALL(handler, checkAvailable(path)).WillOnce(Return(true));
333 EXPECT_CALL(handler, sendFile(path, image)).WillOnce(Return());
334 EXPECT_CALL(handler, sendFile(ipmi_flash::hashBlobId, signature))
335 .WillOnce(Return());
336 EXPECT_CALL(handler, verifyFile(ipmi_flash::verifyBlobId, defaultIgnore))
337 .WillOnce(Return(true));
338 EXPECT_CALL(handler, verifyFile(ipmi_flash::updateBlobId, defaultIgnore))
339 .WillOnce(Return(true));
340 EXPECT_CALL(handler, cleanArtifacts()).WillOnce(Return());
341 EXPECT_CALL(blobMock, deleteBlob(ipmi_flash::activeImageBlobId))
Patrick Venture28624212021-11-09 09:04:03 -0800342 .WillOnce(Return(true));
Willy Tu203ad802021-09-09 20:06:36 -0700343 EXPECT_CALL(blobMock, getBlobList())
344 .WillOnce(Return(std::vector<std::string>(
345 {ipmi_flash::staticLayoutBlobId, ipmi_flash::activeImageBlobId})));
346
347 updaterMain(&handler, &blobMock, image, signature, layout, defaultIgnore);
Brandon Kim6749ba12019-09-19 13:31:37 -0700348}
349
350TEST_F(UpdaterTest, UpdateMainReturnsSuccessWithIgnoreUpdate)
351{
Brandon Kim6749ba12019-09-19 13:31:37 -0700352 UpdateHandlerMock handler;
353 bool updateIgnore = true;
354
Patrick Venture8cdf9642020-09-30 09:41:51 -0700355 EXPECT_CALL(handler, checkAvailable(path)).WillOnce(Return(true));
356 EXPECT_CALL(handler, sendFile(path, image)).WillOnce(Return());
357 EXPECT_CALL(handler, sendFile(ipmi_flash::hashBlobId, signature))
358 .WillOnce(Return());
Brandon Kim6749ba12019-09-19 13:31:37 -0700359 EXPECT_CALL(handler, verifyFile(ipmi_flash::verifyBlobId, defaultIgnore))
360 .WillOnce(Return(true));
361 EXPECT_CALL(handler, verifyFile(ipmi_flash::updateBlobId, updateIgnore))
362 .WillOnce(Return(true));
Willy Tu203ad802021-09-09 20:06:36 -0700363 EXPECT_CALL(blobMock, getBlobList())
364 .WillOnce(Return(std::vector<std::string>({})));
Brandon Kim6749ba12019-09-19 13:31:37 -0700365
Willy Tu203ad802021-09-09 20:06:36 -0700366 updaterMain(&handler, &blobMock, image, signature, layout, updateIgnore);
Patrick Venture1f09d412019-06-19 16:01:06 -0700367}
Patrick Venture9b534f02018-12-13 16:10:02 -0800368
Patrick Venture5f2fcc42019-06-20 07:21:05 -0700369TEST_F(UpdaterTest, UpdateMainCleansUpOnFailure)
370{
Patrick Venture5f2fcc42019-06-20 07:21:05 -0700371 UpdateHandlerMock handler;
372
Patrick Venture8cdf9642020-09-30 09:41:51 -0700373 EXPECT_CALL(handler, checkAvailable(path)).WillOnce(Return(true));
374 EXPECT_CALL(handler, sendFile(path, image)).WillOnce(Return());
375 EXPECT_CALL(handler, sendFile(ipmi_flash::hashBlobId, signature))
376 .WillOnce(Return());
Brandon Kim6749ba12019-09-19 13:31:37 -0700377 EXPECT_CALL(handler, verifyFile(ipmi_flash::verifyBlobId, defaultIgnore))
Patrick Venture5f2fcc42019-06-20 07:21:05 -0700378 .WillOnce(Return(false));
379 EXPECT_CALL(handler, cleanArtifacts()).WillOnce(Return());
Willy Tu203ad802021-09-09 20:06:36 -0700380 EXPECT_CALL(blobMock, getBlobList())
381 .WillOnce(Return(std::vector<std::string>({})));
Patrick Venture5f2fcc42019-06-20 07:21:05 -0700382
Willy Tu203ad802021-09-09 20:06:36 -0700383 EXPECT_THROW(updaterMain(&handler, &blobMock, image, signature, layout,
384 defaultIgnore),
Patrick Venture8cdf9642020-09-30 09:41:51 -0700385 ToolException);
386}
387
388TEST_F(UpdaterTest, UpdateMainExceptsOnUpdateBlobFailure)
389{
390 UpdateHandlerMock handler;
391
392 EXPECT_CALL(handler, checkAvailable(path)).WillOnce(Return(true));
393 EXPECT_CALL(handler, sendFile(path, image)).WillOnce(Return());
394 EXPECT_CALL(handler, sendFile(ipmi_flash::hashBlobId, signature))
395 .WillOnce(Return());
396 EXPECT_CALL(handler, verifyFile(ipmi_flash::verifyBlobId, defaultIgnore))
397 .WillOnce(Return(true));
398 EXPECT_CALL(handler, verifyFile(ipmi_flash::updateBlobId, defaultIgnore))
399 .WillOnce(Return(false));
400 EXPECT_CALL(handler, cleanArtifacts()).WillOnce(Return());
Willy Tu203ad802021-09-09 20:06:36 -0700401 EXPECT_CALL(blobMock, getBlobList())
402 .WillOnce(Return(std::vector<std::string>({})));
Patrick Venture8cdf9642020-09-30 09:41:51 -0700403
Willy Tu203ad802021-09-09 20:06:36 -0700404 EXPECT_THROW(updaterMain(&handler, &blobMock, image, signature, layout,
405 defaultIgnore),
Patrick Venture8cdf9642020-09-30 09:41:51 -0700406 ToolException);
407}
408
409TEST_F(UpdaterTest, UpdateMainExceptsIfAvailableNotFound)
410{
411 UpdateHandlerMock handler;
412
413 EXPECT_CALL(handler, checkAvailable(path)).WillOnce(Return(false));
414
Willy Tu203ad802021-09-09 20:06:36 -0700415 EXPECT_THROW(updaterMain(&handler, &blobMock, image, signature, layout,
416 defaultIgnore),
Patrick Venture8cdf9642020-09-30 09:41:51 -0700417 ToolException);
Patrick Venture5f2fcc42019-06-20 07:21:05 -0700418}
419
Patrick Venture9b534f02018-12-13 16:10:02 -0800420} // namespace host_tool