bmc: require blob ids to start with /flash/
Signed-off-by: Patrick Venture <venture@google.com>
Change-Id: Ib6a0db91d4e2ecd7e7cc3c51ddc1953d9fd8da3c
diff --git a/bmc/test/firmware_json_unittest.cpp b/bmc/test/firmware_json_unittest.cpp
index 66b9db9..bb2585d 100644
--- a/bmc/test/firmware_json_unittest.cpp
+++ b/bmc/test/firmware_json_unittest.cpp
@@ -301,6 +301,68 @@
* TODO: Only allow unique handler blob paths (tested at a higher level).
*/
+TEST(FirmwareJsonTest, VerifyBlobNameMatches)
+{
+ /* A perfect configuration except the blob name doesn't start with "/flash/"
+ */
+ auto j2 = R"(
+ [{
+ "blob" : "bmc-image-flash",
+ "handler" : {
+ "type" : "file",
+ "path" : "/run/initramfs/bmc-image"
+ },
+ "actions" : {
+ "preparation" : {
+ "type" : "systemd",
+ "unit" : "phosphor-ipmi-flash-bmc-prepare.target"
+ },
+ "verification" : {
+ "type" : "fileSystemdVerify",
+ "unit" : "phosphor-ipmi-flash-bmc-verify.target",
+ "path" : "/tmp/bmc.verify"
+ },
+ "update" : {
+ "type" : "reboot"
+ }
+ }
+ }]
+ )"_json;
+
+ EXPECT_THAT(buildHandlerFromJson(j2), IsEmpty());
+}
+
+TEST(FirmwareJsonTest, VerifyMinimumBlobNameLength)
+{
+ /* A perfect configuration except the blob name is effectively zero length.
+ */
+ auto j2 = R"(
+ [{
+ "blob" : "/flash/",
+ "handler" : {
+ "type" : "file",
+ "path" : "/run/initramfs/bmc-image"
+ },
+ "actions" : {
+ "preparation" : {
+ "type" : "systemd",
+ "unit" : "phosphor-ipmi-flash-bmc-prepare.target"
+ },
+ "verification" : {
+ "type" : "fileSystemdVerify",
+ "unit" : "phosphor-ipmi-flash-bmc-verify.target",
+ "path" : "/tmp/bmc.verify"
+ },
+ "update" : {
+ "type" : "reboot"
+ }
+ }
+ }]
+ )"_json;
+
+ EXPECT_THAT(buildHandlerFromJson(j2), IsEmpty());
+}
+
TEST(FirmwareJsonTest, VerifySystemdWithReboot)
{
auto j2 = R"(