bmc: only add verifyBlobId if data sent for image
If data was sent to the hash only, don't add verify until they've at
least opened the image blob id.
Signed-off-by: Patrick Venture <venture@google.com>
Change-Id: Ifc03ac7090e7edbceeac414e908bc5aedb7ad1c3
diff --git a/bmc/firmware_handler.cpp b/bmc/firmware_handler.cpp
index 5f16846..855c3fa 100644
--- a/bmc/firmware_handler.cpp
+++ b/bmc/firmware_handler.cpp
@@ -642,8 +642,13 @@
/* They are closing a data pathway (image, tarball, hash). */
changeState(UpdateState::verificationPending);
- /* Add verify blob ID now that we can expect it. */
- addBlobId(verifyBlobId);
+ /* Add verify blob ID now that we can expect it, IIF they also wrote
+ * some data.
+ */
+ if (std::count(blobIDs.begin(), blobIDs.end(), activeImageBlobId))
+ {
+ addBlobId(verifyBlobId);
+ }
break;
case UpdateState::verificationPending:
/* They haven't triggered, therefore closing is uninteresting.
diff --git a/bmc/test/firmware_state_uploadinprogress_unittest.cpp b/bmc/test/firmware_state_uploadinprogress_unittest.cpp
index be3269e..63169db 100644
--- a/bmc/test/firmware_state_uploadinprogress_unittest.cpp
+++ b/bmc/test/firmware_state_uploadinprogress_unittest.cpp
@@ -193,7 +193,7 @@
handler->close(session);
expectedState(FirmwareBlobHandler::UpdateState::verificationPending);
- EXPECT_TRUE(handler->canHandleBlob(verifyBlobId));
+ EXPECT_FALSE(handler->canHandleBlob(verifyBlobId));
}
/*
diff --git a/bmc/test/firmware_state_verificationpending_unittest.cpp b/bmc/test/firmware_state_verificationpending_unittest.cpp
index fbcd73d..64d82ca 100644
--- a/bmc/test/firmware_state_verificationpending_unittest.cpp
+++ b/bmc/test/firmware_state_verificationpending_unittest.cpp
@@ -153,13 +153,23 @@
TEST_F(FirmwareHandlerVerificationPendingTest,
StatOnVerificationBlobReturnsFailure)
{
- getToVerificationPending(hashBlobId);
+ getToVerificationPending(staticLayoutBlobId);
ASSERT_TRUE(handler->canHandleBlob(verifyBlobId));
blobs::BlobMeta meta;
EXPECT_FALSE(handler->stat(verifyBlobId, &meta));
}
+TEST_F(FirmwareHandlerVerificationPendingTest,
+ VerificationBlobNotFoundWithoutStaticDataAsWell)
+{
+ /* If you only ever open the hash blob id, and never the firmware blob id,
+ * the verify blob isn't added.
+ */
+ getToVerificationPending(hashBlobId);
+ EXPECT_FALSE(handler->canHandleBlob(verifyBlobId));
+}
+
TEST_F(FirmwareHandlerVerificationPendingTest, StatOnNormalBlobsReturnsSuccess)
{
getToVerificationPending(staticLayoutBlobId);