git@vger.kernel.org list mirror (unofficial, one of many)
 help / color / mirror / code / Atom feed
5bc416ab81af9bcc5a3a5ca353d00f3984e8eaca blob 1781 bytes (raw)

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
 
#!/bin/sh

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
	skip_all="You must set env var GIT_TEST_ALLOW_SUDO=YES in order to run this test"
	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 &&
	test_cmp u r &&
	command -v git >u &&
	sudo command -v git >r &&
	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 &&
	sudo chown root root &&
	(
		cd root/r &&
		git init
	)
'

test_expect_success SUDO 'sudo git status as original owner' '
	(
		cd root/r &&
		git status &&
		sudo git status
	)
'

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_failure SUDO 'can access with sudo if root' '
	(
		cd root/p &&
		sudo git status
	)
'

test_expect_success SUDO 'can access with sudo using a workaround' '
	# run sudo twice; would fail is root is not in the sudoers
	(
		cd root/p &&
		sudo sudo git status
	) &&
	# provide explicit GIT_DIR
	(
		cd root/p &&
		run_with_sudo <<-END
			GIT_DIR=.git &&
			GIT_WORK_TREE=. &&
			export GIT_DIR GIT_WORK_TREE &&
			git status
		END
	) &&
	# discard SUDO_UID
	(
		cd root/p &&
		run_with_sudo <<-END
			unset SUDO_UID &&
			git status
		END
	)
'

# this MUST be always the last test
test_expect_success SUDO 'cleanup' '
	sudo rm -rf root
'

test_done
debug log:

solving 5bc416ab81 ...
found 5bc416ab81 in https://public-inbox.org/git/20220507163508.78459-4-carenas@gmail.com/
found ecd9dca6b3 in https://public-inbox.org/git/20220507163508.78459-3-carenas@gmail.com/ ||
	https://public-inbox.org/git/20220510174616.18629-3-carenas@gmail.com/
found 2e4492a66d in https://public-inbox.org/git/20220507163508.78459-2-carenas@gmail.com/ ||
	https://public-inbox.org/git/20220510174616.18629-2-carenas@gmail.com/

applying [1/5] https://public-inbox.org/git/20220507163508.78459-2-carenas@gmail.com/
diff --git a/t/t0034-root-safe-directory.sh b/t/t0034-root-safe-directory.sh
new file mode 100755
index 0000000000..2e4492a66d

Checking patch t/t0034-root-safe-directory.sh...
Applied patch t/t0034-root-safe-directory.sh cleanly.

skipping https://public-inbox.org/git/20220510174616.18629-2-carenas@gmail.com/ for 2e4492a66d
index at:
100755 2e4492a66d7faf29045c57ed48ccabdc2e0daf10	t/t0034-root-safe-directory.sh

applying [2/5] https://public-inbox.org/git/20220507163508.78459-3-carenas@gmail.com/
diff --git a/t/t0034-root-safe-directory.sh b/t/t0034-root-safe-directory.sh
index 2e4492a66d..ecd9dca6b3 100755

Checking patch t/t0034-root-safe-directory.sh...
Applied patch t/t0034-root-safe-directory.sh cleanly.

skipping https://public-inbox.org/git/20220510174616.18629-3-carenas@gmail.com/ for ecd9dca6b3
index at:
100755 ecd9dca6b35e5e97fe941eca2b2de4756c3cc261	t/t0034-root-safe-directory.sh

applying [3/5] https://public-inbox.org/git/20220507163508.78459-4-carenas@gmail.com/
diff --git a/t/t0034-root-safe-directory.sh b/t/t0034-root-safe-directory.sh
index ecd9dca6b3..5bc416ab81 100755

Checking patch t/t0034-root-safe-directory.sh...
Applied patch t/t0034-root-safe-directory.sh cleanly.

index at:
100755 5bc416ab81af9bcc5a3a5ca353d00f3984e8eaca	t/t0034-root-safe-directory.sh

Code repositories for project(s) associated with this inbox:

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).