Add path traversal unit test

This commit is contained in:
Maurice Heumann
2025-03-18 08:33:14 +01:00
parent b746fc17ee
commit a5073a6ddf

View File

@@ -0,0 +1,17 @@
#include <gtest/gtest.h>
#include <file_system.hpp>
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"})));
}
}