blob: f6f042d7deb989dfe8661d65619bcc7d7537f671 [file] [log] [blame]
Nan Zhoud5c80ad2022-07-11 01:16:31 +00001#include "http_response.hpp"
Sunitha Harish7c0bbe72020-07-30 08:25:28 -05002#include "ibm/management_console_rest.hpp"
Sunitha Harish7c0bbe72020-07-30 08:25:28 -05003
4#include <string>
5
Ed Tanous478b7ad2024-07-15 19:11:54 -07006#include <gtest/gtest.h>
Sunitha Harish7c0bbe72020-07-30 08:25:28 -05007
8namespace crow
9{
10namespace ibm_mc
11{
12
Nan Zhou7ea46432022-07-03 23:55:10 +000013TEST(IsValidConfigFileName, FileNameValidCharReturnsTrue)
Sunitha Harish7c0bbe72020-07-30 08:25:28 -050014{
15 crow::Response res;
16
Nan Zhou7ea46432022-07-03 23:55:10 +000017 EXPECT_TRUE(isValidConfigFileName("GoodConfigFile", res));
Sunitha Harish7c0bbe72020-07-30 08:25:28 -050018}
Nan Zhou7ea46432022-07-03 23:55:10 +000019TEST(IsValidConfigFileName, FileNameInvalidCharReturnsFalse)
Sunitha Harish7c0bbe72020-07-30 08:25:28 -050020{
21 crow::Response res;
22
Nan Zhou7ea46432022-07-03 23:55:10 +000023 EXPECT_FALSE(isValidConfigFileName("Bad@file", res));
Sunitha Harish7c0bbe72020-07-30 08:25:28 -050024}
Nan Zhou7ea46432022-07-03 23:55:10 +000025TEST(IsValidConfigFileName, FileNameInvalidPathReturnsFalse)
Sunitha Harish7c0bbe72020-07-30 08:25:28 -050026{
27 crow::Response res;
28
Nan Zhou7ea46432022-07-03 23:55:10 +000029 EXPECT_FALSE(isValidConfigFileName("/../../../../../etc/badpath", res));
30 EXPECT_FALSE(isValidConfigFileName("/../../etc/badpath", res));
31 EXPECT_FALSE(isValidConfigFileName("/mydir/configFile", res));
Sunitha Harish7c0bbe72020-07-30 08:25:28 -050032}
Nan Zhou7ea46432022-07-03 23:55:10 +000033
34TEST(IsValidConfigFileName, EmptyFileNameReturnsFalse)
Sunitha Harish7c0bbe72020-07-30 08:25:28 -050035{
36 crow::Response res;
Nan Zhou7ea46432022-07-03 23:55:10 +000037 EXPECT_FALSE(isValidConfigFileName("", res));
Sunitha Harish7c0bbe72020-07-30 08:25:28 -050038}
Nan Zhou7ea46432022-07-03 23:55:10 +000039
40TEST(IsValidConfigFileName, SlashFileNameReturnsFalse)
Sunitha Harish7c0bbe72020-07-30 08:25:28 -050041{
42 crow::Response res;
Nan Zhou7ea46432022-07-03 23:55:10 +000043 EXPECT_FALSE(isValidConfigFileName("/", res));
Sunitha Harish7c0bbe72020-07-30 08:25:28 -050044}
Nan Zhou7ea46432022-07-03 23:55:10 +000045TEST(IsValidConfigFileName, FileNameMoreThan20CharReturnsFalse)
Sunitha Harish7c0bbe72020-07-30 08:25:28 -050046{
47 crow::Response res;
Nan Zhou7ea46432022-07-03 23:55:10 +000048 EXPECT_FALSE(isValidConfigFileName("BadfileBadfileBadfile", res));
Sunitha Harish7c0bbe72020-07-30 08:25:28 -050049}
50
51} // namespace ibm_mc
52} // namespace crow