test: firmware verificationCompleted: commit

Signed-off-by: Patrick Venture <venture@google.com>
Change-Id: I929fdc480b127dcda4b80b9a4d7153ce5cc8f5f4
diff --git a/firmware_handler.cpp b/firmware_handler.cpp
index 57fd24d..0f08ee7 100644
--- a/firmware_handler.cpp
+++ b/firmware_handler.cpp
@@ -554,16 +554,20 @@
         return false;
     }
 
-    /* Calling repeatedly has no effect within an update process. */
-    if (state == UpdateState::verificationStarted)
+    switch (state)
     {
-        return true;
+        case UpdateState::verificationStarted:
+            /* Calling repeatedly has no effect within an update process. */
+            return true;
+        case UpdateState::verificationCompleted:
+            /* Calling after the verification process has completed returns
+             * failure. */
+            return false;
+        default:
+            /* Set state to committing. */
+            item->second->flags |= blobs::StateFlags::committing;
+            return triggerVerification();
     }
-
-    /* Set state to committing. */
-    item->second->flags |= blobs::StateFlags::committing;
-
-    return triggerVerification();
 }
 
 /*
diff --git a/test/firmware_state_verificationcompleted_unittest.cpp b/test/firmware_state_verificationcompleted_unittest.cpp
index c162c5b..24ad9ad 100644
--- a/test/firmware_state_verificationcompleted_unittest.cpp
+++ b/test/firmware_state_verificationcompleted_unittest.cpp
@@ -273,8 +273,28 @@
 }
 
 /*
- * commit(session) - ?
+ * commit(session) - returns failure
  */
+TEST_F(FirmwareHandlerVerificationCompletedTest,
+       CommitOnVerifyBlobAfterSuccessReturnsFailure)
+{
+    /* If you've started this'll return success, but if it's finished, it won't
+     * let you try-again.
+     */
+    getToVerificationCompleted(VerifyCheckResponses::success);
+    EXPECT_CALL(*verifyMockPtr, triggerVerification()).Times(0);
+
+    EXPECT_FALSE(handler->commit(session, {}));
+}
+
+TEST_F(FirmwareHandlerVerificationCompletedTest,
+       CommitOnVerifyBlobAfterFailureReturnsFailure)
+{
+    getToVerificationCompleted(VerifyCheckResponses::failed);
+    EXPECT_CALL(*verifyMockPtr, triggerVerification()).Times(0);
+
+    EXPECT_FALSE(handler->commit(session, {}));
+}
 
 /*
  * close(session) - close on the verify blobid: