From 02d4f58a2f7ac2db60dd2e4d16a3cbf71b3f08a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pavel=20Filipensk=C3=BD?= Date: Wed, 4 Dec 2024 11:02:18 +0100 Subject: [PATCH] selftest: Add test for vfs crossrename module MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit BUG: https://bugzilla.samba.org/show_bug.cgi?id=15724 Signed-off-by: Pavel Filipenský Reviewed-by: Ralph Boehme --- selftest/target/Samba3.pm | 12 +++++ source3/script/tests/test_recycle.sh | 80 +++++++++++++++++++++++++++- source3/selftest/tests.py | 2 +- 3 files changed, 92 insertions(+), 2 deletions(-) diff --git a/selftest/target/Samba3.pm b/selftest/target/Samba3.pm index 05027b26f46..d7abda75354 100755 --- a/selftest/target/Samba3.pm +++ b/selftest/target/Samba3.pm @@ -2783,6 +2783,9 @@ sub provision($$) my $recycle_shrdir="$shrdir/recycle"; push(@dirs,$recycle_shrdir); + my $recycle_shrdir2="$shrdir/recycle2"; + push(@dirs,$recycle_shrdir2); + my $fakedircreatetimes_shrdir="$shrdir/fakedircreatetimes"; push(@dirs,$fakedircreatetimes_shrdir); @@ -3718,6 +3721,15 @@ sub provision($$) recycle : exclude = *.tmp recycle : directory_mode = 755 +[recycle2] + copy = tmp + path = $recycle_shrdir2 + vfs objects = recycle crossrename + recycle : repository = .trash + recycle : exclude = *.tmp + recycle : directory_mode = 755 + wide links = yes + [fakedircreatetimes] copy = tmp path = $fakedircreatetimes_shrdir diff --git a/source3/script/tests/test_recycle.sh b/source3/script/tests/test_recycle.sh index ba1d0a598b1..779683f4822 100755 --- a/source3/script/tests/test_recycle.sh +++ b/source3/script/tests/test_recycle.sh @@ -29,7 +29,8 @@ export SAMBA_DEPRECATED_SUPPRESS # Define the test environment/filenames. # -share_test_dir="$LOCAL_PATH" +share_test_dir="$LOCAL_PATH/recycle" +share_test_dir2="$LOCAL_PATH/recycle2" # # Cleanup function. @@ -43,6 +44,13 @@ do_cleanup() rm -f testfile2.tmp rm -rf .trash ) + ( + #subshell. + cd "$share_test_dir2" || return + rm -f testfile3 + rm -f testfile4.tmp + rm -rf .trash + ) } # @@ -50,6 +58,25 @@ do_cleanup() # do_cleanup +# Setup .trash on a different filesystem to test crossrename +# /tmp or /dev/shm should provide tmpfs +# +for T in /tmp /dev/shm +do + if df --portability --print-type $T 2>/dev/null | grep -q tmpfs; then + TRASHDIR=$T + break + fi +done + +if [ -z $TRASHDIR ]; then + echo "No tmpfs filesystem found." + exit 1 +fi + +TRASHDIR=$(mktemp -d /$TRASHDIR/.trash_XXXXXX) +chmod 0755 $TRASHDIR +ln -s $TRASHDIR $share_test_dir2/.trash test_recycle() { @@ -90,12 +117,61 @@ quit return 0 } +test_recycle_crossrename() +{ + tmpfile=$PREFIX/smbclient_interactive_prompt_commands + echo " +put $tmpfile testfile3 +put $tmpfile testfile4.tmp +del testfile3 +del testfile4.tmp +quit +" > $tmpfile + cmd='CLI_FORCE_INTERACTIVE=yes $SMBCLIENT -U$USERNAME%$PASSWORD //$SERVER/recycle2 -I$SERVER_IP $ADDARGS < $tmpfile 2>&1' + eval echo "$cmd" + out=$(eval "$cmd") + ret=$? + rm -f "$tmpfile" + + if [ $ret != 0 ]; then + printf "%s\n" "$out" + printf "failed recycle smbclient run with error %s\n" "$ret" + return 1 + fi + + test -e "$share_test_dir2/.trash/testfile3" || { + printf ".trash/testfile3 expected to exist but does NOT exist\n" + return 1 + } + test -e "$share_test_dir2/.trash/testfile4.tmp" && { + printf ".trash/testfile4.tmp not expected to exist but DOES exist\n" + return 1 + } + deviceid1=`stat -c '%d' "$share_test_dir2/"` + deviceid2=`stat -c '%d' "$share_test_dir2/.trash/"` + test "$deviceid1=" != "$deviceid2" || { + printf ".trash/ should be on a different filesystem!\n" + return 1 + } + perm_want=755 + perm_is=`stat -c '%a' "$share_test_dir2/.trash/"` + test "$perm_is" = "$perm_want" || { + printf ".trash/ permission should be $perm_want but is $perm_is\n" + return 1 + } + return 0 +} + panic_count_0=$(grep -c PANIC $SMBD_TEST_LOG) testit "recycle" \ test_recycle || failed=$((failed + 1)) +testit "recycle_crossrename" \ + test_recycle_crossrename || + failed=$((failed + 1)) + panic_count_1=$(grep -c PANIC $SMBD_TEST_LOG) testit "check_panic" test $panic_count_0 -eq $panic_count_1 || failed=$(expr $failed + 1) @@ -103,5 +179,7 @@ testit "check_panic" test $panic_count_0 -eq $panic_count_1 || failed=$(expr $fa # # Cleanup. do_cleanup +# Cleanup above only deletes a symlink, delete also /tmp/.trash_XXXXXX dir +rm -rf "$TRASHDIR" testok "$0" "$failed" diff --git a/source3/selftest/tests.py b/source3/selftest/tests.py index 6b690e2fc1f..4540aef24b5 100755 --- a/source3/selftest/tests.py +++ b/source3/selftest/tests.py @@ -784,7 +784,7 @@ for env in ["fileserver"]: plantestsuite("samba3.blackbox.force_create_mode", env, [os.path.join(samba3srcdir, "script/tests/test_force_create_mode.sh"), '$SERVER', '$DOMAIN', '$USERNAME', '$PASSWORD', '$PREFIX', env, smbclient3]) plantestsuite("samba3.blackbox.dropbox", env, [os.path.join(samba3srcdir, "script/tests/test_dropbox.sh"), '$SERVER', '$DOMAIN', 'gooduser', '$PASSWORD', '$PREFIX', env, smbclient3]) plantestsuite("samba3.blackbox.offline", env, [os.path.join(samba3srcdir, "script/tests/test_offline.sh"), '$SERVER', '$SERVER_IP', '$DOMAIN', '$USERNAME', '$PASSWORD', '$LOCAL_PATH/offline', smbclient3]) - plantestsuite("samba3.blackbox.recycle", env, [os.path.join(samba3srcdir, "script/tests/test_recycle.sh"), '$SERVER', '$SERVER_IP', '$USERNAME', '$PASSWORD', '$LOCAL_PATH/recycle', '$PREFIX', smbclient3]) + plantestsuite("samba3.blackbox.recycle", env, [os.path.join(samba3srcdir, "script/tests/test_recycle.sh"), '$SERVER', '$SERVER_IP', '$USERNAME', '$PASSWORD', '$LOCAL_PATH', '$PREFIX', smbclient3]) plantestsuite("samba3.blackbox.fakedircreatetimes", env, [os.path.join(samba3srcdir, "script/tests/test_fakedircreatetimes.sh"), '$SERVER', '$SERVER_IP', '$USERNAME', '$PASSWORD', '$LOCAL_PATH/fakedircreatetimes', '$PREFIX', smbclient3]) plantestsuite("samba3.blackbox.shadow_copy2.NT1", env + "_smb1_done", [os.path.join(samba3srcdir, "script/tests/test_shadow_copy.sh"), '$SERVER', '$SERVER_IP', '$DOMAIN', '$USERNAME', '$PASSWORD', '$LOCAL_PATH/shadow', smbclient3, '-m', 'NT1']) plantestsuite("samba3.blackbox.shadow_copy2.SMB3", env, [os.path.join(samba3srcdir, "script/tests/test_shadow_copy.sh"), '$SERVER', '$SERVER_IP', '$DOMAIN', '$USERNAME', '$PASSWORD', '$LOCAL_PATH/shadow', smbclient3, '-m', 'SMB3'])