Josh Lehan | 482c45a | 2022-03-29 17:10:44 -0700 | [diff] [blame^] | 1 | #include "include/openbmc_dbus_rest.hpp" |
| 2 | |
| 3 | #include "gtest/gtest.h" |
| 4 | |
| 5 | // Also see redfish-core/ut/configfile_test.cpp |
| 6 | TEST(OpenbmcDbusRestTest, ValidFilenameGood) |
| 7 | { |
| 8 | EXPECT_TRUE(crow::openbmc_mapper::validateFilename("GoodConfigFile")); |
| 9 | EXPECT_TRUE(crow::openbmc_mapper::validateFilename("_Underlines_")); |
| 10 | EXPECT_TRUE(crow::openbmc_mapper::validateFilename("8675309")); |
| 11 | EXPECT_TRUE(crow::openbmc_mapper::validateFilename("-Dashes-")); |
| 12 | EXPECT_TRUE(crow::openbmc_mapper::validateFilename("With Spaces")); |
| 13 | EXPECT_TRUE(crow::openbmc_mapper::validateFilename("One.Dot")); |
| 14 | EXPECT_TRUE(crow::openbmc_mapper::validateFilename("trailingdot.")); |
| 15 | EXPECT_TRUE(crow::openbmc_mapper::validateFilename("-_ o _-")); |
| 16 | EXPECT_TRUE(crow::openbmc_mapper::validateFilename(" ")); |
| 17 | EXPECT_TRUE(crow::openbmc_mapper::validateFilename(" .")); |
| 18 | } |
| 19 | |
| 20 | // There is no length test yet because validateFilename() does not care yet |
| 21 | TEST(OpenbmcDbusRestTest, ValidFilenameBad) |
| 22 | { |
| 23 | EXPECT_FALSE(crow::openbmc_mapper::validateFilename("")); |
| 24 | EXPECT_FALSE(crow::openbmc_mapper::validateFilename("Bad@file")); |
| 25 | EXPECT_FALSE( |
| 26 | crow::openbmc_mapper::validateFilename("/../../../../../etc/badpath")); |
| 27 | EXPECT_FALSE(crow::openbmc_mapper::validateFilename("/../../etc/badpath")); |
| 28 | EXPECT_FALSE(crow::openbmc_mapper::validateFilename("/mydir/configFile")); |
| 29 | EXPECT_FALSE(crow::openbmc_mapper::validateFilename("/")); |
| 30 | EXPECT_FALSE(crow::openbmc_mapper::validateFilename(".leadingdot")); |
| 31 | EXPECT_FALSE(crow::openbmc_mapper::validateFilename("Two..Dots")); |
| 32 | EXPECT_FALSE( |
| 33 | crow::openbmc_mapper::validateFilename("../../../../../../etc/shadow")); |
| 34 | EXPECT_FALSE(crow::openbmc_mapper::validateFilename(".")); |
| 35 | } |