test-lib.sh: set prerequisite SANITY by testing what we really need

What we wanted out of the SANITY precondition is that the filesystem behaves sensibly with permission bits settings. - You should not be able to remove a file in a read-only directory, - You should not be able to tell if a file in a directory exists if the directory lacks read or execute permission bits. We used to cheat by approximating that condition with "is the / writable?" test and/or "are we running as root?" test. Neither test is sufficient or appropriate in environments like Cygwin. Signed-off-by: Torsten Bögershausen <tboegi@web.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Torsten Bögershausen committed Jan 27, 2015 at 16:39 UTC f400e51c13eb4143e420d41d9b415d4f5ddbdb85
1 file changed +22 -3
t/test-lib.sh
+22 -3
@@ -997,9 +997,28 @@ test_lazy_prereq NOT_ROOT '
997 test "$uid" != 0
998 '
999
1000 -# When the tests are run as root, permission tests will report that
1001 -# things are writable when they shouldn't be.
1002 -test -w / || test_set_prereq SANITY
1000 +# On a filesystem that lacks SANITY, a file can be deleted even if
1001 +# the containing directory doesn't have write permissions, or a file
1002 +# can be accessed even if the containing directory doesn't have read
1003 +# or execute permissions, causing our tests that validate that Git
1004 +# works sensibly in such situations.
1005 +test_lazy_prereq SANITY '
1006 + mkdir SANETESTD.1 SANETESTD.2 &&
1007 +
1008 + chmod +w SANETESTD.1 SANETESTD.2 &&
1009 + >SANETESTD.1/x 2>SANETESTD.2/x &&
1010 + chmod -w SANETESTD.1 &&
1011 + chmod -rx SANETESTD.2 ||
1012 + error "bug in test sript: cannot prepare SANETESTD"
1013 +
1014 + ! rm SANETESTD.1/x && ! test -f SANETESTD.2/x
1015 + status=$?
1016 +
1017 + chmod +rwx SANETESTD.1 SANETESTD.2 &&
1018 + rm -rf SANETESTD.1 SANETESTD.2 ||
1019 + error "bug in test sript: cannot clean SANETESTD"
1020 + return $status
1021 +'
1022
1023 GIT_UNZIP=${GIT_UNZIP:-unzip}
1024 test_lazy_prereq UNZIP '