Nan Zhou | d5c80ad | 2022-07-11 01:16:31 +0000 | [diff] [blame] | 1 | #include "http_response.hpp" |
Sunitha Harish | 7c0bbe7 | 2020-07-30 08:25:28 -0500 | [diff] [blame] | 2 | #include "ibm/management_console_rest.hpp" |
Sunitha Harish | 7c0bbe7 | 2020-07-30 08:25:28 -0500 | [diff] [blame] | 3 | |
| 4 | #include <string> |
| 5 | |
Nan Zhou | d5c80ad | 2022-07-11 01:16:31 +0000 | [diff] [blame] | 6 | #include <gtest/gtest.h> // IWYU pragma: keep |
| 7 | |
| 8 | // IWYU pragma: no_include <gtest/gtest-message.h> |
| 9 | // IWYU pragma: no_include <gtest/gtest-test-part.h> |
| 10 | // IWYU pragma: no_include "gtest/gtest_pred_impl.h" |
Sunitha Harish | 7c0bbe7 | 2020-07-30 08:25:28 -0500 | [diff] [blame] | 11 | |
| 12 | namespace crow |
| 13 | { |
| 14 | namespace ibm_mc |
| 15 | { |
| 16 | |
Nan Zhou | 7ea4643 | 2022-07-03 23:55:10 +0000 | [diff] [blame] | 17 | TEST(IsValidConfigFileName, FileNameValidCharReturnsTrue) |
Sunitha Harish | 7c0bbe7 | 2020-07-30 08:25:28 -0500 | [diff] [blame] | 18 | { |
| 19 | crow::Response res; |
| 20 | |
Nan Zhou | 7ea4643 | 2022-07-03 23:55:10 +0000 | [diff] [blame] | 21 | EXPECT_TRUE(isValidConfigFileName("GoodConfigFile", res)); |
Sunitha Harish | 7c0bbe7 | 2020-07-30 08:25:28 -0500 | [diff] [blame] | 22 | } |
Nan Zhou | 7ea4643 | 2022-07-03 23:55:10 +0000 | [diff] [blame] | 23 | TEST(IsValidConfigFileName, FileNameInvalidCharReturnsFalse) |
Sunitha Harish | 7c0bbe7 | 2020-07-30 08:25:28 -0500 | [diff] [blame] | 24 | { |
| 25 | crow::Response res; |
| 26 | |
Nan Zhou | 7ea4643 | 2022-07-03 23:55:10 +0000 | [diff] [blame] | 27 | EXPECT_FALSE(isValidConfigFileName("Bad@file", res)); |
Sunitha Harish | 7c0bbe7 | 2020-07-30 08:25:28 -0500 | [diff] [blame] | 28 | } |
Nan Zhou | 7ea4643 | 2022-07-03 23:55:10 +0000 | [diff] [blame] | 29 | TEST(IsValidConfigFileName, FileNameInvalidPathReturnsFalse) |
Sunitha Harish | 7c0bbe7 | 2020-07-30 08:25:28 -0500 | [diff] [blame] | 30 | { |
| 31 | crow::Response res; |
| 32 | |
Nan Zhou | 7ea4643 | 2022-07-03 23:55:10 +0000 | [diff] [blame] | 33 | EXPECT_FALSE(isValidConfigFileName("/../../../../../etc/badpath", res)); |
| 34 | EXPECT_FALSE(isValidConfigFileName("/../../etc/badpath", res)); |
| 35 | EXPECT_FALSE(isValidConfigFileName("/mydir/configFile", res)); |
Sunitha Harish | 7c0bbe7 | 2020-07-30 08:25:28 -0500 | [diff] [blame] | 36 | } |
Nan Zhou | 7ea4643 | 2022-07-03 23:55:10 +0000 | [diff] [blame] | 37 | |
| 38 | TEST(IsValidConfigFileName, EmptyFileNameReturnsFalse) |
Sunitha Harish | 7c0bbe7 | 2020-07-30 08:25:28 -0500 | [diff] [blame] | 39 | { |
| 40 | crow::Response res; |
Nan Zhou | 7ea4643 | 2022-07-03 23:55:10 +0000 | [diff] [blame] | 41 | EXPECT_FALSE(isValidConfigFileName("", res)); |
Sunitha Harish | 7c0bbe7 | 2020-07-30 08:25:28 -0500 | [diff] [blame] | 42 | } |
Nan Zhou | 7ea4643 | 2022-07-03 23:55:10 +0000 | [diff] [blame] | 43 | |
| 44 | TEST(IsValidConfigFileName, SlashFileNameReturnsFalse) |
Sunitha Harish | 7c0bbe7 | 2020-07-30 08:25:28 -0500 | [diff] [blame] | 45 | { |
| 46 | crow::Response res; |
Nan Zhou | 7ea4643 | 2022-07-03 23:55:10 +0000 | [diff] [blame] | 47 | EXPECT_FALSE(isValidConfigFileName("/", res)); |
Sunitha Harish | 7c0bbe7 | 2020-07-30 08:25:28 -0500 | [diff] [blame] | 48 | } |
Nan Zhou | 7ea4643 | 2022-07-03 23:55:10 +0000 | [diff] [blame] | 49 | TEST(IsValidConfigFileName, FileNameMoreThan20CharReturnsFalse) |
Sunitha Harish | 7c0bbe7 | 2020-07-30 08:25:28 -0500 | [diff] [blame] | 50 | { |
| 51 | crow::Response res; |
Nan Zhou | 7ea4643 | 2022-07-03 23:55:10 +0000 | [diff] [blame] | 52 | EXPECT_FALSE(isValidConfigFileName("BadfileBadfileBadfile", res)); |
Sunitha Harish | 7c0bbe7 | 2020-07-30 08:25:28 -0500 | [diff] [blame] | 53 | } |
| 54 | |
| 55 | } // namespace ibm_mc |
| 56 | } // namespace crow |