blob: 2c68c0bc64802ba1a1d232ba3115bf86eeb4824c [file] [log] [blame]
Sunitha Harish7c0bbe72020-07-30 08:25:28 -05001#include "ibm/management_console_rest.hpp"
2#include "nlohmann/json.hpp"
3
4#include <string>
5
6#include "gmock/gmock.h"
7
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