xref: /openbmc/phosphor-ipmi-blobs/test/ipmi_validate_unittest.cpp (revision 5250957212ebf851d49df046acd6416a0d17c749)
1 #include "ipmi.hpp"
2 #include "manager_mock.hpp"
3 
4 #include <vector>
5 
6 #include <gtest/gtest.h>
7 
8 namespace blobs
9 {
10 
TEST(IpmiValidateTest,VerifyCommandMinimumLengths)11 TEST(IpmiValidateTest, VerifyCommandMinimumLengths)
12 {
13     struct TestCase
14     {
15         BlobOEMCommands cmd;
16         size_t len;
17         bool expect;
18     };
19 
20     std::vector<TestCase> tests = {
21         {BlobOEMCommands::bmcBlobClose, sizeof(struct BmcBlobCloseTx) - 1,
22          false},
23         {BlobOEMCommands::bmcBlobCommit, sizeof(struct BmcBlobCommitTx) - 1,
24          false},
25         {BlobOEMCommands::bmcBlobDelete, sizeof(struct BmcBlobDeleteTx) + 1,
26          false},
27         {BlobOEMCommands::bmcBlobEnumerate,
28          sizeof(struct BmcBlobEnumerateTx) - 1, false},
29         {BlobOEMCommands::bmcBlobOpen, sizeof(struct BmcBlobOpenTx) + 1, false},
30         {BlobOEMCommands::bmcBlobRead, sizeof(struct BmcBlobReadTx) - 1, false},
31         {BlobOEMCommands::bmcBlobSessionStat,
32          sizeof(struct BmcBlobSessionStatTx) - 1, false},
33         {BlobOEMCommands::bmcBlobStat, sizeof(struct BmcBlobStatTx) + 1, false},
34         {BlobOEMCommands::bmcBlobWrite, sizeof(struct BmcBlobWriteTx), false},
35     };
36 
37     for (const auto& test : tests)
38     {
39         bool result = validateRequestLength(test.cmd, test.len);
40         EXPECT_EQ(result, test.expect);
41     }
42 }
43 } // namespace blobs
44