blob: 1d95a79066808df97e5ea5f6133359998e11db86 [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
Nan Zhoud5c80ad2022-07-11 01:16:31 +00006#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 Harish7c0bbe72020-07-30 08:25:28 -050011
12namespace crow
13{
14namespace ibm_mc
15{
16
Nan Zhou7ea46432022-07-03 23:55:10 +000017TEST(IsValidConfigFileName, FileNameValidCharReturnsTrue)
Sunitha Harish7c0bbe72020-07-30 08:25:28 -050018{
19 crow::Response res;
20
Nan Zhou7ea46432022-07-03 23:55:10 +000021 EXPECT_TRUE(isValidConfigFileName("GoodConfigFile", res));
Sunitha Harish7c0bbe72020-07-30 08:25:28 -050022}
Nan Zhou7ea46432022-07-03 23:55:10 +000023TEST(IsValidConfigFileName, FileNameInvalidCharReturnsFalse)
Sunitha Harish7c0bbe72020-07-30 08:25:28 -050024{
25 crow::Response res;
26
Nan Zhou7ea46432022-07-03 23:55:10 +000027 EXPECT_FALSE(isValidConfigFileName("Bad@file", res));
Sunitha Harish7c0bbe72020-07-30 08:25:28 -050028}
Nan Zhou7ea46432022-07-03 23:55:10 +000029TEST(IsValidConfigFileName, FileNameInvalidPathReturnsFalse)
Sunitha Harish7c0bbe72020-07-30 08:25:28 -050030{
31 crow::Response res;
32
Nan Zhou7ea46432022-07-03 23:55:10 +000033 EXPECT_FALSE(isValidConfigFileName("/../../../../../etc/badpath", res));
34 EXPECT_FALSE(isValidConfigFileName("/../../etc/badpath", res));
35 EXPECT_FALSE(isValidConfigFileName("/mydir/configFile", res));
Sunitha Harish7c0bbe72020-07-30 08:25:28 -050036}
Nan Zhou7ea46432022-07-03 23:55:10 +000037
38TEST(IsValidConfigFileName, EmptyFileNameReturnsFalse)
Sunitha Harish7c0bbe72020-07-30 08:25:28 -050039{
40 crow::Response res;
Nan Zhou7ea46432022-07-03 23:55:10 +000041 EXPECT_FALSE(isValidConfigFileName("", res));
Sunitha Harish7c0bbe72020-07-30 08:25:28 -050042}
Nan Zhou7ea46432022-07-03 23:55:10 +000043
44TEST(IsValidConfigFileName, SlashFileNameReturnsFalse)
Sunitha Harish7c0bbe72020-07-30 08:25:28 -050045{
46 crow::Response res;
Nan Zhou7ea46432022-07-03 23:55:10 +000047 EXPECT_FALSE(isValidConfigFileName("/", res));
Sunitha Harish7c0bbe72020-07-30 08:25:28 -050048}
Nan Zhou7ea46432022-07-03 23:55:10 +000049TEST(IsValidConfigFileName, FileNameMoreThan20CharReturnsFalse)
Sunitha Harish7c0bbe72020-07-30 08:25:28 -050050{
51 crow::Response res;
Nan Zhou7ea46432022-07-03 23:55:10 +000052 EXPECT_FALSE(isValidConfigFileName("BadfileBadfileBadfile", res));
Sunitha Harish7c0bbe72020-07-30 08:25:28 -050053}
54
55} // namespace ibm_mc
56} // namespace crow