From a5073a6ddf83fb88fcbca7dbdc1190174b703308 Mon Sep 17 00:00:00 2001 From: Maurice Heumann Date: Tue, 18 Mar 2025 08:33:14 +0100 Subject: [PATCH] Add path traversal unit test --- src/windows-emulator-test/file_system_test.cpp | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 src/windows-emulator-test/file_system_test.cpp diff --git a/src/windows-emulator-test/file_system_test.cpp b/src/windows-emulator-test/file_system_test.cpp new file mode 100644 index 00000000..8487395f --- /dev/null +++ b/src/windows-emulator-test/file_system_test.cpp @@ -0,0 +1,17 @@ +#include + +#include + +namespace test +{ + TEST(FileSystemTest, PathTraversalIsNotPossible) + { + const auto current_dir = std::filesystem::current_path(); + + const file_system fs{current_dir}; + + EXPECT_EQ(current_dir / "a", fs.translate(windows_path('a', {u"..", u"..", u"..", u"..", u"a.txt"}))); + EXPECT_EQ(current_dir / "a", fs.translate(windows_path('a', {u"b", u"..", u"..", u"b", u"..", u"a.txt"}))); + EXPECT_EQ(current_dir / "a", fs.translate(windows_path('a', {u"..", u"b"}))); + } +}