| Rajashekar Gade Reddy | e702392 | 2019-07-10 16:54:55 +0000 | [diff] [blame] | 1 | #include <ipmid/sessionhelper.hpp> | 
 | 2 |  | 
 | 3 | #include <gtest/gtest.h> | 
 | 4 |  | 
 | 5 | TEST(parseSessionInputPayloadTest, ValidObjectPath) | 
 | 6 | { | 
 | 7 |     uint32_t sessionId = 0; | 
 | 8 |     uint8_t sessionHandle = 0; | 
 | 9 |     std::string objectPath = | 
 | 10 |         "/xyz/openbmc_project/ipmi/session/eth0/12a4567d_8a"; | 
 | 11 |  | 
 | 12 |     EXPECT_TRUE( | 
 | 13 |         parseCloseSessionInputPayload(objectPath, sessionId, sessionHandle)); | 
 | 14 |     EXPECT_EQ(0x12a4567d, sessionId); | 
 | 15 |     EXPECT_EQ(0x8a, sessionHandle); | 
 | 16 | } | 
 | 17 |  | 
 | 18 | TEST(parseSessionInputPayloadTest, InvalidObjectPath) | 
 | 19 | { | 
 | 20 |     uint32_t sessionId = 0; | 
 | 21 |     uint8_t sessionHandle = 0; | 
 | 22 |     // A valid object path will be like | 
 | 23 |     // "/xyz/openbmc_project/ipmi/session/channel/sessionId_sessionHandle" | 
 | 24 |     // Ex: "/xyz/openbmc_project/ipmi/session/eth0/12a4567d_8a" | 
 | 25 |     // SessionId    : 0X12a4567d | 
 | 26 |     // SessionHandle: 0X8a | 
 | 27 |     std::string objectPath = "/xyz/openbmc_project/ipmi/session/eth0/12a4567d"; | 
 | 28 |  | 
 | 29 |     EXPECT_FALSE( | 
 | 30 |         parseCloseSessionInputPayload(objectPath, sessionId, sessionHandle)); | 
 | 31 | } | 
 | 32 |  | 
 | 33 | TEST(parseSessionInputPayloadTest, NoObjectPath) | 
 | 34 | { | 
 | 35 |     uint32_t sessionId = 0; | 
 | 36 |     uint8_t sessionHandle = 0; | 
 | 37 |     std::string objectPath; | 
 | 38 |  | 
 | 39 |     EXPECT_FALSE( | 
 | 40 |         parseCloseSessionInputPayload(objectPath, sessionId, sessionHandle)); | 
 | 41 | } | 
 | 42 |  | 
 | 43 | TEST(isSessionObjectMatchedTest, ValidSessionId) | 
 | 44 | { | 
 | 45 |     std::string objectPath = | 
 | 46 |         "/xyz/openbmc_project/ipmi/session/eth0/12a4567d_8a"; | 
 | 47 |     uint32_t sessionId = 0x12a4567d; | 
 | 48 |     uint8_t sessionHandle = 0; | 
 | 49 |  | 
 | 50 |     EXPECT_TRUE(isSessionObjectMatched(objectPath, sessionId, sessionHandle)); | 
 | 51 | } | 
 | 52 |  | 
 | 53 | TEST(isSessionObjectMatchedTest, ValidSessionHandle) | 
 | 54 | { | 
 | 55 |     std::string objectPath = | 
 | 56 |         "/xyz/openbmc_project/ipmi/session/eth0/12a4567d_8a"; | 
 | 57 |     uint32_t sessionId = 0; | 
 | 58 |     uint8_t sessionHandle = 0x8a; | 
 | 59 |  | 
 | 60 |     EXPECT_TRUE(isSessionObjectMatched(objectPath, sessionId, sessionHandle)); | 
 | 61 | } | 
 | 62 |  | 
 | 63 | TEST(isSessionObjectMatchedTest, InvalidSessionId) | 
 | 64 | { | 
 | 65 |     std::string objectPath = | 
 | 66 |         "/xyz/openbmc_project/ipmi/session/eth0/12a4567d_8a"; | 
 | 67 |     uint32_t sessionId = 0x1234b67d; | 
 | 68 |     uint8_t sessionHandle = 0; | 
 | 69 |  | 
 | 70 |     EXPECT_FALSE(isSessionObjectMatched(objectPath, sessionId, sessionHandle)); | 
 | 71 | } | 
 | 72 |  | 
 | 73 | TEST(isSessionObjectMatchedTest, InvalidSessionHandle) | 
 | 74 | { | 
 | 75 |     std::string objectPath = | 
 | 76 |         "/xyz/openbmc_project/ipmi/session/eth0/12a4567d_8a"; | 
 | 77 |     uint32_t sessionId = 0; | 
 | 78 |     uint8_t sessionHandle = 0x9b; | 
 | 79 |  | 
 | 80 |     EXPECT_FALSE(isSessionObjectMatched(objectPath, sessionId, sessionHandle)); | 
 | 81 | } | 
 | 82 |  | 
 | 83 | TEST(isSessionObjectMatchedTest, ZeroSessionId_ZeroSessionHandle) | 
 | 84 | { | 
 | 85 |     std::string objectPath = | 
 | 86 |         "/xyz/openbmc_project/ipmi/session/eth0/12a4567d_8a"; | 
 | 87 |     uint32_t sessionId = 0; | 
 | 88 |     uint8_t sessionHandle = 0; | 
 | 89 |  | 
 | 90 |     EXPECT_FALSE(isSessionObjectMatched(objectPath, sessionId, sessionHandle)); | 
 | 91 | } | 
 | 92 |  | 
 | 93 | TEST(isSessionObjectMatchedTest, InvalidObjectPath) | 
 | 94 | { | 
 | 95 |     // A valid object path will be like | 
 | 96 |     // "/xyz/openbmc_project/ipmi/session/channel/sessionId_sessionHandle" | 
 | 97 |     // Ex: "/xyz/openbmc_project/ipmi/session/eth0/12a4567d_8a" | 
 | 98 |     // SessionId    : 0X12a4567d | 
 | 99 |     // SessionHandle: 0X8a | 
 | 100 |     std::string objectPath = "/xyz/openbmc_project/ipmi/session/eth0/12a4567d"; | 
 | 101 |     uint32_t sessionId = 0x12a4567d; | 
 | 102 |     uint8_t sessionHandle = 0; | 
 | 103 |  | 
 | 104 |     EXPECT_FALSE(isSessionObjectMatched(objectPath, sessionId, sessionHandle)); | 
 | 105 | } | 
 | 106 |  | 
 | 107 | TEST(isSessionObjectMatchedTest, NoObjectPath) | 
 | 108 | { | 
 | 109 |     std::string objectPath; | 
 | 110 |     uint32_t sessionId = 0x12a4567d; | 
 | 111 |     uint8_t sessionHandle = 0x8a; | 
 | 112 |  | 
 | 113 |     EXPECT_FALSE(isSessionObjectMatched(objectPath, sessionId, sessionHandle)); | 
 | 114 | } |