bmc: verificationCompleted: close: handle failure

Signed-off-by: Patrick Venture <venture@google.com>
Change-Id: I7efdc39998d4c61ec23af7eb5ed4062f0aedf190
diff --git a/firmware_handler.cpp b/firmware_handler.cpp
index fbabda0..f54ba25 100644
--- a/firmware_handler.cpp
+++ b/firmware_handler.cpp
@@ -661,7 +661,13 @@
             }
             else
             {
-                /* TODO: Verification failed, what now? */
+                /* Verification failed, and the host-tool knows this by calling
+                 * stat(), which triggered the state change to
+                 * verificationCompleted.
+                 *
+                 * Therefore, let's abort the process at this point.
+                 */
+                abortProcess();
             }
             break;
         case UpdateState::updatePending:
diff --git a/test/firmware_state_verificationcompleted_unittest.cpp b/test/firmware_state_verificationcompleted_unittest.cpp
index ac3539d..0f02cf3 100644
--- a/test/firmware_state_verificationcompleted_unittest.cpp
+++ b/test/firmware_state_verificationcompleted_unittest.cpp
@@ -297,8 +297,19 @@
 
 /*
  * close(session) - close on the verify blobid:
- * TODO:  2. if unsuccessful doesn't add update blob id, changes state to?
+ *   2. if unsuccessful it aborts.
  */
+TEST_F(FirmwareHandlerVerificationCompletedTest, CloseAfterFailureAborts)
+{
+    getToVerificationCompleted(ActionStatus::failed);
+    ASSERT_FALSE(handler->canHandleBlob(updateBlobId));
+
+    handler->close(session);
+    ASSERT_FALSE(handler->canHandleBlob(updateBlobId));
+    expectedState(FirmwareBlobHandler::UpdateState::notYetStarted);
+    std::vector<std::string> expected = {staticLayoutBlobId, hashBlobId};
+    EXPECT_THAT(handler->getBlobIds(), UnorderedElementsAreArray(expected));
+}
 
 } // namespace
 } // namespace ipmi_flash