Sunitha Harish | 7c0bbe7 | 2020-07-30 08:25:28 -0500 | [diff] [blame] | 1 | #include "ibm/management_console_rest.hpp" |
| 2 | #include "nlohmann/json.hpp" |
| 3 | |
| 4 | #include <string> |
| 5 | |
| 6 | #include "gmock/gmock.h" |
| 7 | |
| 8 | namespace crow |
| 9 | { |
| 10 | namespace ibm_mc |
| 11 | { |
| 12 | |
| 13 | TEST(ConfigFileTest, FileNameValidChar) |
| 14 | { |
| 15 | crow::Response res; |
| 16 | |
| 17 | const std::string fileName = "GoodConfigFile"; |
| 18 | EXPECT_TRUE(isValidConfigFileName(fileName, res)); |
| 19 | } |
| 20 | TEST(ConfigFileTest, FileNameInvalidChar) |
| 21 | { |
| 22 | crow::Response res; |
| 23 | |
| 24 | const std::string fileName = "Bad@file"; |
| 25 | EXPECT_FALSE(isValidConfigFileName(fileName, res)); |
| 26 | } |
| 27 | TEST(ConfigFileTest, FileNameInvalidPath1) |
| 28 | { |
| 29 | crow::Response res; |
| 30 | |
| 31 | const std::string fileName = "/../../../../../etc/badpath"; |
| 32 | EXPECT_FALSE(isValidConfigFileName(fileName, res)); |
| 33 | } |
| 34 | TEST(ConfigFileTest, FileNameInvalidPath2) |
| 35 | { |
| 36 | crow::Response res; |
| 37 | |
| 38 | const std::string fileName = "/../../etc/badpath"; |
| 39 | EXPECT_FALSE(isValidConfigFileName(fileName, res)); |
| 40 | } |
| 41 | TEST(ConfigFileTest, FileNameInvalidPath3) |
| 42 | { |
| 43 | crow::Response res; |
| 44 | |
| 45 | const std::string fileName = "/mydir/configFile"; |
| 46 | EXPECT_FALSE(isValidConfigFileName(fileName, res)); |
| 47 | } |
| 48 | TEST(ConfigFileTest, FileNameNull) |
| 49 | { |
| 50 | crow::Response res; |
| 51 | |
| 52 | const std::string fileName = ""; |
| 53 | EXPECT_FALSE(isValidConfigFileName(fileName, res)); |
| 54 | } |
| 55 | TEST(ConfigFileTest, FileNameSlash) |
| 56 | { |
| 57 | crow::Response res; |
| 58 | |
| 59 | const std::string fileName = "/"; |
| 60 | EXPECT_FALSE(isValidConfigFileName(fileName, res)); |
| 61 | } |
| 62 | TEST(ConfigFileTest, FileNameMorethan20Char) |
| 63 | { |
| 64 | crow::Response res; |
| 65 | |
| 66 | const std::string fileName = "BadfileBadfileBadfile"; |
| 67 | EXPECT_FALSE(isValidConfigFileName(fileName, res)); |
| 68 | } |
| 69 | |
| 70 | } // namespace ibm_mc |
| 71 | } // namespace crow |