bmc: firmware updatePending: stat(session)

Signed-off-by: Patrick Venture <venture@google.com>
Change-Id: Idb3a51af0fa94f21fc797cab518a4f7976e306c8
diff --git a/firmware_handler.cpp b/firmware_handler.cpp
index 77e0e50..15dbee8 100644
--- a/firmware_handler.cpp
+++ b/firmware_handler.cpp
@@ -200,26 +200,21 @@
 
     meta->metadata.clear();
 
-    /* TODO: Implement this for the verification blob, which is what we expect.
-     * Calling stat() on the verify blob without an active session should not
-     * provide insight.
-     */
     if (item->second->activePath == verifyBlobId)
     {
         VerifyCheckResponses value;
 
-        if (state == UpdateState::verificationPending)
+        switch (state)
         {
-            value = VerifyCheckResponses::other;
-        }
-        else if (state == UpdateState::verificationCompleted)
-        {
-            value = lastVerificationResponse;
-        }
-        else
-        {
-            value = verification->checkVerificationState();
-            lastVerificationResponse = value;
+            case UpdateState::verificationPending:
+                value = VerifyCheckResponses::other;
+                break;
+            case UpdateState::verificationCompleted:
+                value = lastVerificationResponse;
+                break;
+            default:
+                value = verification->checkVerificationState();
+                lastVerificationResponse = value;
         }
 
         meta->metadata.push_back(static_cast<std::uint8_t>(value));
@@ -243,6 +238,21 @@
             }
         }
     }
+    else if (item->second->activePath == updateBlobId)
+    {
+        UpdateStatus value;
+
+        switch (state)
+        {
+            case UpdateState::updatePending:
+                value = UpdateStatus::unknown;
+                break;
+            default:
+                break;
+        }
+
+        meta->metadata.push_back(static_cast<std::uint8_t>(value));
+    }
 
     /* The blobState here relates to an active sesion, so we should return the
      * flags used to open this session.
@@ -625,8 +635,9 @@
                     /* TODO: Verification failed, what now? */
                     state = UpdateState::notYetStarted;
                 }
+                break;
             default:
-                [[fallthrough]];
+                break;
         }
         /* Must be verificationPending... not yet started, they may re-open and
          * trigger verification.
diff --git a/test/firmware_state_updatepending_unittest.cpp b/test/firmware_state_updatepending_unittest.cpp
index 9b8b755..eb9e437 100644
--- a/test/firmware_state_updatepending_unittest.cpp
+++ b/test/firmware_state_updatepending_unittest.cpp
@@ -213,11 +213,31 @@
 }
 
 /*
- * TODO: deleteBlob(blob)
+ * stat(session)
+ * In this case, you can open updateBlobId without changing state, therefore,
+ * let's call stat() against a session against this file. This done, ahead of
+ * commit() should report the state as "other."
  */
+TEST_F(FirmwareHandlerUpdatePendingTest,
+       SessionStatOnUpdateBlobIdReturnsFailure)
+{
+    getToUpdatePending();
+    EXPECT_TRUE(handler->open(session, flags, updateBlobId));
+    expectedState(FirmwareBlobHandler::UpdateState::updatePending);
+
+    blobs::BlobMeta meta, expectedMeta = {};
+    expectedMeta.size = 0;
+    expectedMeta.blobState = flags;
+    expectedMeta.metadata.push_back(
+        static_cast<std::uint8_t>(UpdateStatus::unknown));
+
+    EXPECT_TRUE(handler->stat(session, &meta));
+    EXPECT_EQ(expectedMeta, meta);
+    expectedState(FirmwareBlobHandler::UpdateState::updatePending);
+}
 
 /*
- * stat(session)
+ * TODO: deleteBlob(blob)
  */
 
 /*