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 | |
Nan Zhou | 7ea4643 | 2022-07-03 23:55:10 +0000 | [diff] [blame^] | 13 | TEST(IsValidConfigFileName, FileNameValidCharReturnsTrue) |
Sunitha Harish | 7c0bbe7 | 2020-07-30 08:25:28 -0500 | [diff] [blame] | 14 | { |
| 15 | crow::Response res; |
| 16 | |
Nan Zhou | 7ea4643 | 2022-07-03 23:55:10 +0000 | [diff] [blame^] | 17 | EXPECT_TRUE(isValidConfigFileName("GoodConfigFile", res)); |
Sunitha Harish | 7c0bbe7 | 2020-07-30 08:25:28 -0500 | [diff] [blame] | 18 | } |
Nan Zhou | 7ea4643 | 2022-07-03 23:55:10 +0000 | [diff] [blame^] | 19 | TEST(IsValidConfigFileName, FileNameInvalidCharReturnsFalse) |
Sunitha Harish | 7c0bbe7 | 2020-07-30 08:25:28 -0500 | [diff] [blame] | 20 | { |
| 21 | crow::Response res; |
| 22 | |
Nan Zhou | 7ea4643 | 2022-07-03 23:55:10 +0000 | [diff] [blame^] | 23 | EXPECT_FALSE(isValidConfigFileName("Bad@file", res)); |
Sunitha Harish | 7c0bbe7 | 2020-07-30 08:25:28 -0500 | [diff] [blame] | 24 | } |
Nan Zhou | 7ea4643 | 2022-07-03 23:55:10 +0000 | [diff] [blame^] | 25 | TEST(IsValidConfigFileName, FileNameInvalidPathReturnsFalse) |
Sunitha Harish | 7c0bbe7 | 2020-07-30 08:25:28 -0500 | [diff] [blame] | 26 | { |
| 27 | crow::Response res; |
| 28 | |
Nan Zhou | 7ea4643 | 2022-07-03 23:55:10 +0000 | [diff] [blame^] | 29 | EXPECT_FALSE(isValidConfigFileName("/../../../../../etc/badpath", res)); |
| 30 | EXPECT_FALSE(isValidConfigFileName("/../../etc/badpath", res)); |
| 31 | EXPECT_FALSE(isValidConfigFileName("/mydir/configFile", res)); |
Sunitha Harish | 7c0bbe7 | 2020-07-30 08:25:28 -0500 | [diff] [blame] | 32 | } |
Nan Zhou | 7ea4643 | 2022-07-03 23:55:10 +0000 | [diff] [blame^] | 33 | |
| 34 | TEST(IsValidConfigFileName, EmptyFileNameReturnsFalse) |
Sunitha Harish | 7c0bbe7 | 2020-07-30 08:25:28 -0500 | [diff] [blame] | 35 | { |
| 36 | crow::Response res; |
Nan Zhou | 7ea4643 | 2022-07-03 23:55:10 +0000 | [diff] [blame^] | 37 | EXPECT_FALSE(isValidConfigFileName("", res)); |
Sunitha Harish | 7c0bbe7 | 2020-07-30 08:25:28 -0500 | [diff] [blame] | 38 | } |
Nan Zhou | 7ea4643 | 2022-07-03 23:55:10 +0000 | [diff] [blame^] | 39 | |
| 40 | TEST(IsValidConfigFileName, SlashFileNameReturnsFalse) |
Sunitha Harish | 7c0bbe7 | 2020-07-30 08:25:28 -0500 | [diff] [blame] | 41 | { |
| 42 | crow::Response res; |
Nan Zhou | 7ea4643 | 2022-07-03 23:55:10 +0000 | [diff] [blame^] | 43 | EXPECT_FALSE(isValidConfigFileName("/", res)); |
Sunitha Harish | 7c0bbe7 | 2020-07-30 08:25:28 -0500 | [diff] [blame] | 44 | } |
Nan Zhou | 7ea4643 | 2022-07-03 23:55:10 +0000 | [diff] [blame^] | 45 | TEST(IsValidConfigFileName, FileNameMoreThan20CharReturnsFalse) |
Sunitha Harish | 7c0bbe7 | 2020-07-30 08:25:28 -0500 | [diff] [blame] | 46 | { |
| 47 | crow::Response res; |
Nan Zhou | 7ea4643 | 2022-07-03 23:55:10 +0000 | [diff] [blame^] | 48 | EXPECT_FALSE(isValidConfigFileName("BadfileBadfileBadfile", res)); |
Sunitha Harish | 7c0bbe7 | 2020-07-30 08:25:28 -0500 | [diff] [blame] | 49 | } |
| 50 | |
| 51 | } // namespace ibm_mc |
| 52 | } // namespace crow |