blob: b64a2d3fc1f497f1f86c1cd6737cd0a40da1ef3c [file] [log] [blame]
Ed Tanous40e9b922024-09-10 13:50:16 -07001// SPDX-License-Identifier: Apache-2.0
2// SPDX-FileCopyrightText: Copyright OpenBMC Authors
Nan Zhoud5c80ad2022-07-11 01:16:31 +00003#include "http_response.hpp"
Ed Tanous3b28fa22024-09-23 14:51:55 -07004#include "ibm_management_console_rest.hpp"
Sunitha Harish7c0bbe72020-07-30 08:25:28 -05005
6#include <string>
7
Ed Tanous478b7ad2024-07-15 19:11:54 -07008#include <gtest/gtest.h>
Sunitha Harish7c0bbe72020-07-30 08:25:28 -05009
10namespace crow
11{
12namespace ibm_mc
13{
14
Nan Zhou7ea46432022-07-03 23:55:10 +000015TEST(IsValidConfigFileName, FileNameValidCharReturnsTrue)
Sunitha Harish7c0bbe72020-07-30 08:25:28 -050016{
17 crow::Response res;
18
Nan Zhou7ea46432022-07-03 23:55:10 +000019 EXPECT_TRUE(isValidConfigFileName("GoodConfigFile", res));
Sunitha Harish7c0bbe72020-07-30 08:25:28 -050020}
Nan Zhou7ea46432022-07-03 23:55:10 +000021TEST(IsValidConfigFileName, FileNameInvalidCharReturnsFalse)
Sunitha Harish7c0bbe72020-07-30 08:25:28 -050022{
23 crow::Response res;
24
Nan Zhou7ea46432022-07-03 23:55:10 +000025 EXPECT_FALSE(isValidConfigFileName("Bad@file", res));
Sunitha Harish7c0bbe72020-07-30 08:25:28 -050026}
Nan Zhou7ea46432022-07-03 23:55:10 +000027TEST(IsValidConfigFileName, FileNameInvalidPathReturnsFalse)
Sunitha Harish7c0bbe72020-07-30 08:25:28 -050028{
29 crow::Response res;
30
Nan Zhou7ea46432022-07-03 23:55:10 +000031 EXPECT_FALSE(isValidConfigFileName("/../../../../../etc/badpath", res));
32 EXPECT_FALSE(isValidConfigFileName("/../../etc/badpath", res));
33 EXPECT_FALSE(isValidConfigFileName("/mydir/configFile", res));
Sunitha Harish7c0bbe72020-07-30 08:25:28 -050034}
Nan Zhou7ea46432022-07-03 23:55:10 +000035
36TEST(IsValidConfigFileName, EmptyFileNameReturnsFalse)
Sunitha Harish7c0bbe72020-07-30 08:25:28 -050037{
38 crow::Response res;
Nan Zhou7ea46432022-07-03 23:55:10 +000039 EXPECT_FALSE(isValidConfigFileName("", res));
Sunitha Harish7c0bbe72020-07-30 08:25:28 -050040}
Nan Zhou7ea46432022-07-03 23:55:10 +000041
42TEST(IsValidConfigFileName, SlashFileNameReturnsFalse)
Sunitha Harish7c0bbe72020-07-30 08:25:28 -050043{
44 crow::Response res;
Nan Zhou7ea46432022-07-03 23:55:10 +000045 EXPECT_FALSE(isValidConfigFileName("/", res));
Sunitha Harish7c0bbe72020-07-30 08:25:28 -050046}
Nan Zhou7ea46432022-07-03 23:55:10 +000047TEST(IsValidConfigFileName, FileNameMoreThan20CharReturnsFalse)
Sunitha Harish7c0bbe72020-07-30 08:25:28 -050048{
49 crow::Response res;
Nan Zhou7ea46432022-07-03 23:55:10 +000050 EXPECT_FALSE(isValidConfigFileName("BadfileBadfileBadfile", res));
Sunitha Harish7c0bbe72020-07-30 08:25:28 -050051}
52
53} // namespace ibm_mc
54} // namespace crow