From b75675297700e365cc8482b048ad9a7fc4946065 Mon Sep 17 00:00:00 2001 From: Elliott Hughes Date: Tue, 25 Jun 2019 14:23:48 -0700 Subject: Fix cp.test to pass even if you're root or have a restrictive umask. --- tests/cp.test | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'tests') diff --git a/tests/cp.test b/tests/cp.test index 9ee6cd0e..6c798b4b 100755 --- a/tests/cp.test +++ b/tests/cp.test @@ -2,6 +2,9 @@ [ -f testing.sh ] && . testing.sh +OLDUMASK=$(umask) +umask 0002 + # Create test file dd if=/dev/urandom of=random bs=64 count=1 2> /dev/null @@ -35,17 +38,20 @@ rm -rf two three walrus touch two chmod 000 two -testing "file->inaccessable [fail]" \ +skipnot [ $(id -u) -ne 0 ] # Root doesn't count. +testing "file->inaccessible [fail]" \ "cp random two 2>/dev/null || echo yes" "yes\n" "" "" rm -f two touch two chmod 000 two -testing "-f file->inaccessable" \ +skipnot [ $(id -u) -ne 0 ] # Root doesn't count. +testing "-f file->inaccessible" \ "cp -f random two && cmp random two && echo yes" "yes\n" "" "" mkdir sub chmod 000 sub -testing "file->inaccessable_dir [fail]" \ +skipnot [ $(id -u) -ne 0 ] # Root doesn't count. +testing "file->inaccessible_dir [fail]" \ "cp random sub 2>/dev/null || echo yes" "yes\n" "" "" rm two rmdir sub @@ -101,9 +107,9 @@ rm -rf one one_ touch walrus chmod 644 walrus ln -s walrus woot - testing "symlink dest permissions" "cp woot carpenter && stat -c %A carpenter" \ "-rw-r--r--\n" "" "" +rm -rf walrus woot carpenter # cp -r ../source destdir # cp -r one/two/three missing @@ -114,3 +120,5 @@ testing "symlink dest permissions" "cp woot carpenter && stat -c %A carpenter" \ # Make sure it's truncating existing file # copy with -d at top level, with -d in directory, without -d at top level, # without -d in directory + +umask $OLDUMASK -- cgit v1.2.3