Prevent testsuite runs from non-root users.
authorHarald Hoyer <harald@redhat.com>
Tue, 31 Jul 2012 11:46:51 +0000 (13:46 +0200)
committerHarald Hoyer <harald@redhat.com>
Tue, 31 Jul 2012 11:49:04 +0000 (13:49 +0200)
Makefile
test/Makefile
test/test-functions

index cd15009..2c9dd60 100644 (file)
--- 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)
index f4881b5..3411035 100644 (file)
@@ -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 ; \
index 13e23b2..5b03a23 100644 (file)
@@ -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