blob: 9f6bc13599d771bec1ec23b766693108122332b1 [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
13TEST(ConfigFileTest, FileNameValidChar)
14{
15 crow::Response res;
16
17 const std::string fileName = "GoodConfigFile";
18 EXPECT_TRUE(isValidConfigFileName(fileName, res));
19}
20TEST(ConfigFileTest, FileNameInvalidChar)
21{
22 crow::Response res;
23
24 const std::string fileName = "Bad@file";
25 EXPECT_FALSE(isValidConfigFileName(fileName, res));
26}
27TEST(ConfigFileTest, FileNameInvalidPath1)
28{
29 crow::Response res;
30
31 const std::string fileName = "/../../../../../etc/badpath";
32 EXPECT_FALSE(isValidConfigFileName(fileName, res));
33}
34TEST(ConfigFileTest, FileNameInvalidPath2)
35{
36 crow::Response res;
37
38 const std::string fileName = "/../../etc/badpath";
39 EXPECT_FALSE(isValidConfigFileName(fileName, res));
40}
41TEST(ConfigFileTest, FileNameInvalidPath3)
42{
43 crow::Response res;
44
45 const std::string fileName = "/mydir/configFile";
46 EXPECT_FALSE(isValidConfigFileName(fileName, res));
47}
48TEST(ConfigFileTest, FileNameNull)
49{
50 crow::Response res;
51
52 const std::string fileName = "";
53 EXPECT_FALSE(isValidConfigFileName(fileName, res));
54}
55TEST(ConfigFileTest, FileNameSlash)
56{
57 crow::Response res;
58
59 const std::string fileName = "/";
60 EXPECT_FALSE(isValidConfigFileName(fileName, res));
61}
62TEST(ConfigFileTest, FileNameMorethan20Char)
63{
64 crow::Response res;
65
66 const std::string fileName = "BadfileBadfileBadfile";
67 EXPECT_FALSE(isValidConfigFileName(fileName, res));
68}
69
70} // namespace ibm_mc
71} // namespace crow