bmc: verificationCompleted::close(success)
Signed-off-by: Patrick Venture <venture@google.com>
Change-Id: I9c9b04f814827586428a31453693a53a6c00a473
diff --git a/firmware_handler.cpp b/firmware_handler.cpp
index 0f08ee7..413c54d 100644
--- a/firmware_handler.cpp
+++ b/firmware_handler.cpp
@@ -592,21 +592,26 @@
/* Are you closing the verify blob? */
if (item->second->activePath == verifyBlobId)
{
- if (state == UpdateState::verificationStarted)
+ switch (state)
{
- /* TODO: If they close this blob before verification finishes,
- * that's an abort.
- */
- return false;
- }
- else if (state == UpdateState::verificationCompleted)
- {
- /* TODO: Should this delete the verification artifact? */
- state = UpdateState::notYetStarted;
-
- /* A this point, delete the active blob IDs from the blob_list. */
- removeBlobId(activeImageBlobId);
- removeBlobId(activeHashBlobId);
+ case UpdateState::verificationStarted:
+ /* TODO: If they close this blob before verification finishes,
+ * that's an abort.
+ */
+ return false;
+ case UpdateState::verificationCompleted:
+ if (lastVerificationResponse == VerifyCheckResponses::success)
+ {
+ state = UpdateState::updatePending;
+ addBlobId(updateBlobId);
+ }
+ else
+ {
+ /* TODO: Verification failed, what now? */
+ state = UpdateState::notYetStarted;
+ }
+ default:
+ [[fallthrough]];
}
/* Must be verificationPending... not yet started, they may re-open and
* trigger verification.
@@ -631,14 +636,8 @@
}
item->second->state = Session::State::closed;
- /* Do not delete the active blob_id from the list of blob_ids, because that
- * blob_id indicates there is data stored. Delete will destroy it.
- */
-
lookup.erase(item);
-
fileOpen = false;
-
return true;
}
diff --git a/test/firmware_state_verificationcompleted_unittest.cpp b/test/firmware_state_verificationcompleted_unittest.cpp
index 24ad9ad..e82a011 100644
--- a/test/firmware_state_verificationcompleted_unittest.cpp
+++ b/test/firmware_state_verificationcompleted_unittest.cpp
@@ -299,7 +299,21 @@
/*
* close(session) - close on the verify blobid:
* 1. if successful adds update blob id, changes state to UpdatePending
- * 2. if unsuccessful doesn't add update blob id, changes state to?
+ */
+TEST_F(FirmwareHandlerVerificationCompletedTest,
+ CloseAfterSuccessChangesStateAddsUpdateBlob)
+{
+ getToVerificationCompleted(VerifyCheckResponses::success);
+ ASSERT_FALSE(handler->canHandleBlob(updateBlobId));
+
+ handler->close(session);
+ EXPECT_TRUE(handler->canHandleBlob(updateBlobId));
+ expectedState(FirmwareBlobHandler::UpdateState::updatePending);
+}
+
+/*
+ * close(session) - close on the verify blobid:
+ * TODO: 2. if unsuccessful doesn't add update blob id, changes state to?
*/
} // namespace