xref: /openbmc/bmcweb/features/ibm/configfile_test.cpp (revision 3b28fa2b201513be89807dfb76b47b3ca7ee3f9b)
1*3b28fa2bSEd Tanous // SPDX-License-Identifier: Apache-2.0
2*3b28fa2bSEd Tanous // SPDX-FileCopyrightText: Copyright OpenBMC Authors
3*3b28fa2bSEd Tanous #include "http_response.hpp"
4*3b28fa2bSEd Tanous #include "ibm_management_console_rest.hpp"
5*3b28fa2bSEd Tanous 
6*3b28fa2bSEd Tanous #include <string>
7*3b28fa2bSEd Tanous 
8*3b28fa2bSEd Tanous #include <gtest/gtest.h>
9*3b28fa2bSEd Tanous 
10*3b28fa2bSEd Tanous namespace crow
11*3b28fa2bSEd Tanous {
12*3b28fa2bSEd Tanous namespace ibm_mc
13*3b28fa2bSEd Tanous {
14*3b28fa2bSEd Tanous 
TEST(IsValidConfigFileName,FileNameValidCharReturnsTrue)15*3b28fa2bSEd Tanous TEST(IsValidConfigFileName, FileNameValidCharReturnsTrue)
16*3b28fa2bSEd Tanous {
17*3b28fa2bSEd Tanous     crow::Response res;
18*3b28fa2bSEd Tanous 
19*3b28fa2bSEd Tanous     EXPECT_TRUE(isValidConfigFileName("GoodConfigFile", res));
20*3b28fa2bSEd Tanous }
TEST(IsValidConfigFileName,FileNameInvalidCharReturnsFalse)21*3b28fa2bSEd Tanous TEST(IsValidConfigFileName, FileNameInvalidCharReturnsFalse)
22*3b28fa2bSEd Tanous {
23*3b28fa2bSEd Tanous     crow::Response res;
24*3b28fa2bSEd Tanous 
25*3b28fa2bSEd Tanous     EXPECT_FALSE(isValidConfigFileName("Bad@file", res));
26*3b28fa2bSEd Tanous }
TEST(IsValidConfigFileName,FileNameInvalidPathReturnsFalse)27*3b28fa2bSEd Tanous TEST(IsValidConfigFileName, FileNameInvalidPathReturnsFalse)
28*3b28fa2bSEd Tanous {
29*3b28fa2bSEd Tanous     crow::Response res;
30*3b28fa2bSEd Tanous 
31*3b28fa2bSEd Tanous     EXPECT_FALSE(isValidConfigFileName("/../../../../../etc/badpath", res));
32*3b28fa2bSEd Tanous     EXPECT_FALSE(isValidConfigFileName("/../../etc/badpath", res));
33*3b28fa2bSEd Tanous     EXPECT_FALSE(isValidConfigFileName("/mydir/configFile", res));
34*3b28fa2bSEd Tanous }
35*3b28fa2bSEd Tanous 
TEST(IsValidConfigFileName,EmptyFileNameReturnsFalse)36*3b28fa2bSEd Tanous TEST(IsValidConfigFileName, EmptyFileNameReturnsFalse)
37*3b28fa2bSEd Tanous {
38*3b28fa2bSEd Tanous     crow::Response res;
39*3b28fa2bSEd Tanous     EXPECT_FALSE(isValidConfigFileName("", res));
40*3b28fa2bSEd Tanous }
41*3b28fa2bSEd Tanous 
TEST(IsValidConfigFileName,SlashFileNameReturnsFalse)42*3b28fa2bSEd Tanous TEST(IsValidConfigFileName, SlashFileNameReturnsFalse)
43*3b28fa2bSEd Tanous {
44*3b28fa2bSEd Tanous     crow::Response res;
45*3b28fa2bSEd Tanous     EXPECT_FALSE(isValidConfigFileName("/", res));
46*3b28fa2bSEd Tanous }
TEST(IsValidConfigFileName,FileNameMoreThan20CharReturnsFalse)47*3b28fa2bSEd Tanous TEST(IsValidConfigFileName, FileNameMoreThan20CharReturnsFalse)
48*3b28fa2bSEd Tanous {
49*3b28fa2bSEd Tanous     crow::Response res;
50*3b28fa2bSEd Tanous     EXPECT_FALSE(isValidConfigFileName("BadfileBadfileBadfile", res));
51*3b28fa2bSEd Tanous }
52*3b28fa2bSEd Tanous 
53*3b28fa2bSEd Tanous } // namespace ibm_mc
54*3b28fa2bSEd Tanous } // namespace crow
55