From: Harald Hoyer Date: Tue, 31 Jul 2012 11:46:51 +0000 (+0200) Subject: Prevent testsuite runs from non-root users. X-Git-Tag: 023~12 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=1f524c45440dd759ac7d9d0539001648b1b1e5c0;p=thirdparty%2Fdracut.git Prevent testsuite runs from non-root users. --- diff --git a/Makefile b/Makefile index cd1500971..2c9dd60a0 100644 --- a/Makefile +++ b/Makefile @@ -156,7 +156,8 @@ syncheck: done;exit $$ret check: all syncheck - $(MAKE) -C test check + @[ "$$EUID" == "0" ] || { echo "'check' must be run as root! Please use 'sudo'."; exit 1; } + @$(MAKE) -C test check testimage: all ./dracut.sh -l -a debug -f test-$(shell uname -r).img $(shell uname -r) diff --git a/test/Makefile b/test/Makefile index f4881b5f6..3411035ba 100644 --- a/test/Makefile +++ b/test/Makefile @@ -1,6 +1,7 @@ .PHONY: all check clean check: + @[ "$$EUID" == "0" ] || { echo "'check' must be run as root! Please use 'sudo'."; exit 1; } @for i in TEST-[0-9]*; do \ [ -d $$i ] || continue ; \ [ -f $$i/Makefile ] || continue ; \ diff --git a/test/test-functions b/test/test-functions index 13e23b22d..5b03a2391 100644 --- a/test/test-functions +++ b/test/test-functions @@ -24,14 +24,22 @@ function SETCOLOR_WARNING() { echo -en '\033[0;33m'; } # terminal sequence to reset to the default color. function SETCOLOR_NORMAL() { echo -en '\033[0;39m'; } +check_root() { + if (( $EUID != 0 )); then + SETCOLOR_FAILURE; echo "Tests must be run as root! Please use 'sudo'."; SETCOLOR_NORMAL + exit 1 + fi +} while (($# > 0)); do case $1 in --run) + check_root echo "TEST RUN: $TEST_DESCRIPTION" test_check && test_run exit $?;; --setup) + check_root echo "TEST SETUP: $TEST_DESCRIPTION" test_check && test_setup exit $?;; @@ -42,6 +50,7 @@ while (($# > 0)); do rm -f .testdir exit $?;; --all) + check_root echo -n "TEST: $TEST_DESCRIPTION "; if ! test_check 2&>test.log ; then SETCOLOR_WARNING