Ed Tanous | 40e9b92 | 2024-09-10 13:50:16 -0700 | [diff] [blame] | 1 | // SPDX-License-Identifier: Apache-2.0 |
| 2 | // SPDX-FileCopyrightText: Copyright OpenBMC Authors |
Nan Zhou | d5c80ad | 2022-07-11 01:16:31 +0000 | [diff] [blame] | 3 | #include "http_response.hpp" |
Ed Tanous | 3b28fa2 | 2024-09-23 14:51:55 -0700 | [diff] [blame^] | 4 | #include "ibm_management_console_rest.hpp" |
Sunitha Harish | 7c0bbe7 | 2020-07-30 08:25:28 -0500 | [diff] [blame] | 5 | |
| 6 | #include <string> |
| 7 | |
Ed Tanous | 478b7ad | 2024-07-15 19:11:54 -0700 | [diff] [blame] | 8 | #include <gtest/gtest.h> |
Sunitha Harish | 7c0bbe7 | 2020-07-30 08:25:28 -0500 | [diff] [blame] | 9 | |
| 10 | namespace crow |
| 11 | { |
| 12 | namespace ibm_mc |
| 13 | { |
| 14 | |
Nan Zhou | 7ea4643 | 2022-07-03 23:55:10 +0000 | [diff] [blame] | 15 | TEST(IsValidConfigFileName, FileNameValidCharReturnsTrue) |
Sunitha Harish | 7c0bbe7 | 2020-07-30 08:25:28 -0500 | [diff] [blame] | 16 | { |
| 17 | crow::Response res; |
| 18 | |
Nan Zhou | 7ea4643 | 2022-07-03 23:55:10 +0000 | [diff] [blame] | 19 | EXPECT_TRUE(isValidConfigFileName("GoodConfigFile", res)); |
Sunitha Harish | 7c0bbe7 | 2020-07-30 08:25:28 -0500 | [diff] [blame] | 20 | } |
Nan Zhou | 7ea4643 | 2022-07-03 23:55:10 +0000 | [diff] [blame] | 21 | TEST(IsValidConfigFileName, FileNameInvalidCharReturnsFalse) |
Sunitha Harish | 7c0bbe7 | 2020-07-30 08:25:28 -0500 | [diff] [blame] | 22 | { |
| 23 | crow::Response res; |
| 24 | |
Nan Zhou | 7ea4643 | 2022-07-03 23:55:10 +0000 | [diff] [blame] | 25 | EXPECT_FALSE(isValidConfigFileName("Bad@file", res)); |
Sunitha Harish | 7c0bbe7 | 2020-07-30 08:25:28 -0500 | [diff] [blame] | 26 | } |
Nan Zhou | 7ea4643 | 2022-07-03 23:55:10 +0000 | [diff] [blame] | 27 | TEST(IsValidConfigFileName, FileNameInvalidPathReturnsFalse) |
Sunitha Harish | 7c0bbe7 | 2020-07-30 08:25:28 -0500 | [diff] [blame] | 28 | { |
| 29 | crow::Response res; |
| 30 | |
Nan Zhou | 7ea4643 | 2022-07-03 23:55:10 +0000 | [diff] [blame] | 31 | EXPECT_FALSE(isValidConfigFileName("/../../../../../etc/badpath", res)); |
| 32 | EXPECT_FALSE(isValidConfigFileName("/../../etc/badpath", res)); |
| 33 | EXPECT_FALSE(isValidConfigFileName("/mydir/configFile", res)); |
Sunitha Harish | 7c0bbe7 | 2020-07-30 08:25:28 -0500 | [diff] [blame] | 34 | } |
Nan Zhou | 7ea4643 | 2022-07-03 23:55:10 +0000 | [diff] [blame] | 35 | |
| 36 | TEST(IsValidConfigFileName, EmptyFileNameReturnsFalse) |
Sunitha Harish | 7c0bbe7 | 2020-07-30 08:25:28 -0500 | [diff] [blame] | 37 | { |
| 38 | crow::Response res; |
Nan Zhou | 7ea4643 | 2022-07-03 23:55:10 +0000 | [diff] [blame] | 39 | EXPECT_FALSE(isValidConfigFileName("", res)); |
Sunitha Harish | 7c0bbe7 | 2020-07-30 08:25:28 -0500 | [diff] [blame] | 40 | } |
Nan Zhou | 7ea4643 | 2022-07-03 23:55:10 +0000 | [diff] [blame] | 41 | |
| 42 | TEST(IsValidConfigFileName, SlashFileNameReturnsFalse) |
Sunitha Harish | 7c0bbe7 | 2020-07-30 08:25:28 -0500 | [diff] [blame] | 43 | { |
| 44 | crow::Response res; |
Nan Zhou | 7ea4643 | 2022-07-03 23:55:10 +0000 | [diff] [blame] | 45 | EXPECT_FALSE(isValidConfigFileName("/", res)); |
Sunitha Harish | 7c0bbe7 | 2020-07-30 08:25:28 -0500 | [diff] [blame] | 46 | } |
Nan Zhou | 7ea4643 | 2022-07-03 23:55:10 +0000 | [diff] [blame] | 47 | TEST(IsValidConfigFileName, FileNameMoreThan20CharReturnsFalse) |
Sunitha Harish | 7c0bbe7 | 2020-07-30 08:25:28 -0500 | [diff] [blame] | 48 | { |
| 49 | crow::Response res; |
Nan Zhou | 7ea4643 | 2022-07-03 23:55:10 +0000 | [diff] [blame] | 50 | EXPECT_FALSE(isValidConfigFileName("BadfileBadfileBadfile", res)); |
Sunitha Harish | 7c0bbe7 | 2020-07-30 08:25:28 -0500 | [diff] [blame] | 51 | } |
| 52 | |
| 53 | } // namespace ibm_mc |
| 54 | } // namespace crow |