Skip to content

Commit 75b49bb

Browse files
committed
Merge branch 'jk/sanity'
The tests that wanted to see that file becomes unreadable after running "chmod a-r file", and the tests that wanted to make sure it is not run as root, we used "can we write into the / directory?" as a cheap substitute, but on some platforms that is not a good heuristics. The tests and their prerequisites have been updated to check what they really require. * jk/sanity: test-lib.sh: set prerequisite SANITY by testing what we really need tests: correct misuses of POSIXPERM t/lib-httpd: switch SANITY check for NOT_ROOT
2 parents 4f5a427 + f400e51 commit 75b49bb

File tree

4 files changed

+42
-9
lines changed

4 files changed

+42
-9
lines changed

t/lib-httpd.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ then
3737
test_done
3838
fi
3939

40-
if ! test_have_prereq SANITY; then
40+
if ! test_have_prereq NOT_ROOT; then
4141
test_skip_or_die $GIT_TEST_HTTPD \
4242
"Cannot run httpd tests as root"
4343
fi

t/t0061-run-command.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ test_expect_success POSIXPERM 'run_command reports EACCES' '
3434
grep "fatal: cannot exec.*hello.sh" err
3535
'
3636

37-
test_expect_success POSIXPERM 'unreadable directory in PATH' '
37+
test_expect_success POSIXPERM,SANITY 'unreadable directory in PATH' '
3838
mkdir local-command &&
3939
test_when_finished "chmod u+rwx local-command && rm -fr local-command" &&
4040
git config alias.nitfol "!echo frotz" &&

t/t1509-root-worktree.sh

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,16 @@ test_foobar_foobar() {
9898
'
9999
}
100100

101-
if ! test_have_prereq POSIXPERM || ! [ -w / ]; then
102-
skip_all="Dangerous test skipped. Read this test if you want to execute it"
101+
if ! test -w /
102+
then
103+
skip_all="Test requiring writable / skipped. Read this test if you want to run it"
104+
test_done
105+
fi
106+
107+
if test -e /refs || test -e /objects || test -e /info || test -e /hooks ||
108+
test -e /.git || test -e /foo || test -e /me
109+
then
110+
skip_all="Skip test that clobbers existing files in /"
103111
test_done
104112
fi
105113

@@ -108,8 +116,9 @@ if [ "$IKNOWWHATIAMDOING" != "YES" ]; then
108116
test_done
109117
fi
110118

111-
if [ "$UID" = 0 ]; then
112-
skip_all="No you can't run this with root"
119+
if ! test_have_prereq NOT_ROOT
120+
then
121+
skip_all="No you can't run this as root"
113122
test_done
114123
fi
115124

t/test-lib.sh

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1031,9 +1031,33 @@ test_lazy_prereq USR_BIN_TIME '
10311031
test -x /usr/bin/time
10321032
'
10331033

1034-
# When the tests are run as root, permission tests will report that
1035-
# things are writable when they shouldn't be.
1036-
test -w / || test_set_prereq SANITY
1034+
test_lazy_prereq NOT_ROOT '
1035+
uid=$(id -u) &&
1036+
test "$uid" != 0
1037+
'
1038+
1039+
# On a filesystem that lacks SANITY, a file can be deleted even if
1040+
# the containing directory doesn't have write permissions, or a file
1041+
# can be accessed even if the containing directory doesn't have read
1042+
# or execute permissions, causing our tests that validate that Git
1043+
# works sensibly in such situations.
1044+
test_lazy_prereq SANITY '
1045+
mkdir SANETESTD.1 SANETESTD.2 &&
1046+
1047+
chmod +w SANETESTD.1 SANETESTD.2 &&
1048+
>SANETESTD.1/x 2>SANETESTD.2/x &&
1049+
chmod -w SANETESTD.1 &&
1050+
chmod -rx SANETESTD.2 ||
1051+
error "bug in test sript: cannot prepare SANETESTD"
1052+
1053+
! rm SANETESTD.1/x && ! test -f SANETESTD.2/x
1054+
status=$?
1055+
1056+
chmod +rwx SANETESTD.1 SANETESTD.2 &&
1057+
rm -rf SANETESTD.1 SANETESTD.2 ||
1058+
error "bug in test sript: cannot clean SANETESTD"
1059+
return $status
1060+
'
10371061

10381062
GIT_UNZIP=${GIT_UNZIP:-unzip}
10391063
test_lazy_prereq UNZIP '

0 commit comments

Comments
 (0)