tools: blob: implement get blob stat command

The firmware update process requires implementing the stat command, so
that one can verify the firmware mechanism requested is available.

Change-Id: I582f344124767975ee305c420657f991d2223889
Signed-off-by: Patrick Venture <venture@google.com>
diff --git a/test/tools_blob_unittest.cpp b/test/tools_blob_unittest.cpp
index 020c2fc..0d5787e 100644
--- a/test/tools_blob_unittest.cpp
+++ b/test/tools_blob_unittest.cpp
@@ -94,3 +94,49 @@
 
     EXPECT_EQ(expectedList, blob.getBlobList());
 }
+
+TEST(BlobHandler, getStatWithMetadata)
+{
+    /* Stat received metadata. */
+    IpmiInterfaceMock ipmiMock;
+    BlobHandler blob(&ipmiMock);
+    std::vector<std::uint8_t> request = {
+        0xcf, 0xc2, 0x00, BlobHandler::BlobOEMCommands::bmcBlobStat,
+        0x00, 0x00, 'a',  'b',
+        'c',  'd'};
+
+    /* return blob_state: 0xffff, size: 0x00, metadata 0x3445 */
+    std::vector<std::uint8_t> resp = {0xcf, 0xc2, 0x00, 0x00, 0x00, 0xff, 0xff,
+                                      0x00, 0x00, 0x00, 0x00, 0x02, 0x34, 0x45};
+
+    EXPECT_CALL(ipmiMock, sendPacket(Eq(request))).WillOnce(Return(resp));
+
+    auto meta = blob.getStat("abcd");
+    EXPECT_EQ(meta.blob_state, 0xffff);
+    EXPECT_EQ(meta.size, 0x00);
+    std::vector<std::uint8_t> metadata = {0x34, 0x45};
+    EXPECT_EQ(metadata, meta.metadata);
+}
+
+TEST(BlobHandler, getStatNoMetadata)
+{
+    /* Stat received no metadata. */
+    IpmiInterfaceMock ipmiMock;
+    BlobHandler blob(&ipmiMock);
+    std::vector<std::uint8_t> request = {
+        0xcf, 0xc2, 0x00, BlobHandler::BlobOEMCommands::bmcBlobStat,
+        0x00, 0x00, 'a',  'b',
+        'c',  'd'};
+
+    /* return blob_state: 0xffff, size: 0x00, metadata 0x3445 */
+    std::vector<std::uint8_t> resp = {0xcf, 0xc2, 0x00, 0x00, 0x00, 0xff,
+                                      0xff, 0x00, 0x00, 0x00, 0x00, 0x00};
+
+    EXPECT_CALL(ipmiMock, sendPacket(Eq(request))).WillOnce(Return(resp));
+
+    auto meta = blob.getStat("abcd");
+    EXPECT_EQ(meta.blob_state, 0xffff);
+    EXPECT_EQ(meta.size, 0x00);
+    std::vector<std::uint8_t> metadata = {};
+    EXPECT_EQ(metadata, meta.metadata);
+}