[PATCH 2/2] t: add tests for safe.directory when running with sudo

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



In a previous commit the functionality for fixing this regression was
implemented, so add a test for it and the relevant infrastructure.

This new test file is meant to be run in CI and checks for a SUDO
prerequisite which requires a passwordless configuration if run
locally, but that is common there.

It could be run locally by first running sudo, so the credentials are
temporarily cached and then running it as :

  $ IKNOWWHATIAMDOING=YES ./t0034-root-safe-directory.sh

It is slightly ackward as it needs to clean up after itself since the
test framework would fail to do its own cleanup otherwise, and for
simplicity creates its own subtree while ignoring the one provided by
the framework, but doing some better integration has been punted.

Signed-off-by: Carlo Marcelo Arenas Belón <carenas@xxxxxxxxx>
---
 t/t0034-root-safe-directory.sh | 51 ++++++++++++++++++++++++++++++++++
 1 file changed, 51 insertions(+)
 create mode 100755 t/t0034-root-safe-directory.sh

diff --git a/t/t0034-root-safe-directory.sh b/t/t0034-root-safe-directory.sh
new file mode 100755
index 00000000000..c62bf3777c0
--- /dev/null
+++ b/t/t0034-root-safe-directory.sh
@@ -0,0 +1,51 @@
+#!/bin/sh
+
+test_description='verify safe.directory checks while running as root'
+
+. ./test-lib.sh
+
+if [ "$IKNOWWHATIAMDOING" != "YES" ]; then
+	skip_all="You must set env var IKNOWWHATIAMDOING=YES in order to run thi
+s test"
+	test_done
+fi
+
+if ! test_have_prereq NOT_ROOT
+then
+	skip_all="this test uses sudo to run as root"
+	test_done
+fi
+
+doalarm () {
+	perl -e 'alarm shift; exec @ARGV' -- "$@"
+}
+
+test_lazy_prereq SUDO '
+	doalarm 1 sudo id -u >u &&
+	id -u root >r &&
+	test_cmp u r
+'
+
+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 works' '
+	(
+		cd root/r &&
+		git status &&
+		sudo git status
+	)
+'
+
+test_expect_success SUDO 'cleanup' '
+	sudo rm -rf root
+'
+
+test_done
-- 
2.36.0.266.g59f845bde02




[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux