Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.kernel.org/pub/scm/git/git.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 't/t0034-root-safe-directory.sh')
-rwxr-xr-xt/t0034-root-safe-directory.sh62
1 files changed, 62 insertions, 0 deletions
diff --git a/t/t0034-root-safe-directory.sh b/t/t0034-root-safe-directory.sh
index 6b8ea5357f..a621f1ea5e 100755
--- a/t/t0034-root-safe-directory.sh
+++ b/t/t0034-root-safe-directory.sh
@@ -3,6 +3,7 @@
test_description='verify safe.directory checks while running as root'
. ./test-lib.sh
+. "$TEST_DIRECTORY"/lib-sudo.sh
if [ "$GIT_TEST_ALLOW_SUDO" != "YES" ]
then
@@ -10,6 +11,12 @@ then
test_done
fi
+if ! test_have_prereq NOT_ROOT
+then
+ skip_all="These tests do not support running as root"
+ test_done
+fi
+
test_lazy_prereq SUDO '
sudo -n id -u >u &&
id -u root >r &&
@@ -19,6 +26,12 @@ test_lazy_prereq SUDO '
test_cmp u r
'
+if ! test_have_prereq SUDO
+then
+ skip_all="Your sudo/system configuration is either too strict or unsupported"
+ test_done
+fi
+
test_expect_success SUDO 'setup' '
sudo rm -rf root &&
mkdir -p root/r &&
@@ -36,6 +49,55 @@ test_expect_success SUDO 'sudo git status as original owner' '
)
'
+test_expect_success SUDO 'setup root owned repository' '
+ sudo mkdir -p root/p &&
+ sudo git init root/p
+'
+
+test_expect_success 'cannot access if owned by root' '
+ (
+ cd root/p &&
+ test_must_fail git status
+ )
+'
+
+test_expect_success 'can access if addressed explicitly' '
+ (
+ cd root/p &&
+ GIT_DIR=.git GIT_WORK_TREE=. git status
+ )
+'
+
+test_expect_failure SUDO 'can access with sudo if root' '
+ (
+ cd root/p &&
+ sudo git status
+ )
+'
+
+test_expect_success SUDO 'can access with sudo if root by removing SUDO_UID' '
+ (
+ cd root/p &&
+ run_with_sudo <<-END
+ unset SUDO_UID &&
+ git status
+ END
+ )
+'
+
+test_lazy_prereq SUDO_SUDO '
+ sudo sudo id -u >u &&
+ id -u root >r &&
+ test_cmp u r
+'
+
+test_expect_success SUDO_SUDO 'can access with sudo abusing SUDO_UID' '
+ (
+ cd root/p &&
+ sudo sudo git status
+ )
+'
+
# this MUST be always the last test
test_expect_success SUDO 'cleanup' '
sudo rm -rf root