mirror of
https://github.com/momo5502/emulator.git
synced 2026-01-11 16:46:16 +00:00
Add path traversal unit test
This commit is contained in:
17
src/windows-emulator-test/file_system_test.cpp
Normal file
17
src/windows-emulator-test/file_system_test.cpp
Normal 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"})));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user