From aaa796d4b47c4d44e313621aba3be5d6e6e660a4 Mon Sep 17 00:00:00 2001 From: Martin Winkler Date: Mon, 28 Mar 2022 22:39:40 +0200 Subject: [PATCH] Replicated competition tests to assertion tests --- test/totest.sh | 73 +++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 72 insertions(+), 1 deletion(-) diff --git a/test/totest.sh b/test/totest.sh index dda2ea4..112049f 100644 --- a/test/totest.sh +++ b/test/totest.sh @@ -132,12 +132,44 @@ _ta_tmp="${test_dir:-"/tmp"}/tmp_assert" # [1] input == [2] expected # [3] input == [4] expected # ... +assert_canonicalize=( "Canonicalize invalid path" + "///tmp//./b" "/tmp/b" + "//tmp//./b/.." "" + "//tmp//./b/." "" + "//tmp//./b/" "/tmp/b" + "///notthere//...../help/." "" +) + + toassert_init() { { + # Base directory for the test initialization mkdir -p "${_ta_tmp}" - } + cd "${_ta_tmp}" + # assert_no_permission + mkdir -p "nopermdir" + chmod 400 "nopermdir" + ln -s "nopermdir" "nopermdirl" + ln -s "/" "lroot" + ln -s "/root" "lroothome" + + # assert_links + touch "a" + ln -s "a" "a 2" + ln -s "a 2" "a 3" + mkdir -p "dir_1" + mkdir -p "dir_2/dir_22" + touch "dir_2/dir_22/file" + ln -s "dir_2/dir_22" "dir_3_l" + ln -s "../dir_3_l/file" "dir_1/file" + + # assert_relative + ln -s "../nofile" "nofile_l" + ln -s "../nodir/nofile" "nopath_l" + } + # Base directory for the test cd "${_ta_tmp}" @@ -150,6 +182,41 @@ toassert_init() { "${_ta_tmp}/miss c" "${_ta_tmp}/miss c" "rel_a" "${_ta_tmp}/rel_a" "../rel_b" "$(cd ".." && pwd)/rel_b" + "-v" "$PWD/-v" # Not recommended file naming + "../-v" "$(cd "$PWD/.." && pwd)/-v" # Not recommended file naming + "-v/.." "" # Not recommended file naming + ) + + assert_relative=( "Resolving of relative links" + # Invalid + "nofile_l" "$(cd "$PWD/.." && pwd)/nofile" + "nopath_l" "" + # Valid + "dir_1/file" "$PWD/dir_2/dir_22/file" # Valid relative link to path with relative element + ) + + assert_no_permission=( "No permission to enter directory (direct and link)" + "nopermdir" "$PWD/nopermdir" + "nopermdirl" "$PWD/nopermdir" + "lroot" "/" + "lroothome" "/root" + "/" "/" + "/root" "/root" + "/root/" "/root" + "/root/." "/root" + "/root/.." "/" + ) + + assert_links=( "Test - Valid links" + "${_ta_tmp}/a 3" "$PWD/a" # slink chain a3 -> a2 -> a + "${_ta_tmp}/a" "$PWD/a" + "${_ta_tmp}/a 2" "$PWD/a" + "/dev/stdin" "/dev/pts/0" + #"/dev/stdout" "" # skip - Always different ( add for assert ) + #"/dev/fd" # Test skip - /dev/fd is different on every call + #"/etc/mtab" # skip - Always different + #"/proc/mounts" # skip - Always different + #"/proc/net/"* # skip - Always different ) assert_force_fail=( "Force fail" @@ -158,7 +225,11 @@ toassert_init() { # Add test arrays to global test array from test_rdlink toassert+=( + assert_canonicalize + assert_relative + assert_no_permission assert_invalid_files + assert_links #assert_force_fail ) }