From 6e5a5a3b27257f212fcd10a3580cfca3ea224fab Mon Sep 17 00:00:00 2001 From: dzwdz Date: Wed, 4 Aug 2021 12:27:02 +0200 Subject: partial path_simplify implementation it currently only checks if the path is valid, it's the bare minimum needed to write tests --- src/kernel/tests/main.c | 1 + src/kernel/tests/tests.h | 1 + src/kernel/tests/vfs.c | 35 +++++++++++++++++++++++++++++++++++ 3 files changed, 37 insertions(+) create mode 100644 src/kernel/tests/vfs.c (limited to 'src/kernel/tests') diff --git a/src/kernel/tests/main.c b/src/kernel/tests/main.c index 8e5842b..db4363f 100644 --- a/src/kernel/tests/main.c +++ b/src/kernel/tests/main.c @@ -8,6 +8,7 @@ void tests_all() { _did_tests_fail = false; tests_utils(); + tests_vfs(); if (_did_tests_fail) panic(); diff --git a/src/kernel/tests/tests.h b/src/kernel/tests/tests.h index 78397da..5b9697c 100644 --- a/src/kernel/tests/tests.h +++ b/src/kernel/tests/tests.h @@ -3,3 +3,4 @@ void tests_all(); void tests_utils(); +void tests_vfs(); diff --git a/src/kernel/tests/vfs.c b/src/kernel/tests/vfs.c new file mode 100644 index 0000000..a5a6848 --- /dev/null +++ b/src/kernel/tests/vfs.c @@ -0,0 +1,35 @@ +#include +#include +#include + +TEST(path_simplify) { + char buf[256]; + + // some easy valid cases + TEST_COND( path_simplify("/asdf", buf, 5)); + TEST_COND( path_simplify("/asd/", buf, 5)); + TEST_COND( path_simplify("/a/./", buf, 5)); + TEST_COND( path_simplify("/a/..", buf, 5)); + TEST_COND( path_simplify("/a//.", buf, 5)); + + // .. going under the root or close to it + TEST_COND(!path_simplify("/../123456", buf, 10)); + TEST_COND(!path_simplify("/./a/../..", buf, 10)); + TEST_COND( path_simplify("/a/a/../..", buf, 10)); + TEST_COND(!path_simplify("/////../..", buf, 10)); + TEST_COND(!path_simplify("//a//../..", buf, 10)); + + // relative paths aren't allowed + TEST_COND(!path_simplify("apath", buf, 5)); + TEST_COND(!path_simplify("a/pth", buf, 5)); + TEST_COND(!path_simplify("../th", buf, 5)); + + // this includes empty paths + TEST_COND(!path_simplify("", buf, 1)); + + // TODO test if the paths are simplified correctly +} + +void tests_vfs() { + TEST_RUN(path_simplify); +} -- cgit v1.2.3