From: Todd C. Miller Date: Mon, 21 Mar 2011 19:08:49 +0000 (-0400) Subject: Move parser tests to sudoers directory and test the tokenizer output too. X-Git-Tag: SUDO_1_8_1~64^2 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=830fce0f1968554a810996edb4b25118c301e538;p=sudo Move parser tests to sudoers directory and test the tokenizer output too. --- diff --git a/plugins/sudoers/Makefile.in b/plugins/sudoers/Makefile.in index ff70bdc5f..4a08e7f84 100644 --- a/plugins/sudoers/Makefile.in +++ b/plugins/sudoers/Makefile.in @@ -365,7 +365,66 @@ uninstall: check: $(TEST_PROGS) visudo testsudoers @./check_iolog_path $(srcdir)/regress/iolog_path/data @./check_fill - @for t in $(srcdir)/regress/*/test*.sh; do SRCDIR=$(srcdir) $(SHELL) $$t; done + @passed=0; failed=0; total=0; \ + for t in $(srcdir)/regress/sudoers/*.in; do \ + dir=`dirname $$t`; \ + dirbase=`basename $$dir`; \ + base=`basename $$t .in`; \ + out="$${base}.out"; \ + toke="$${base}.toke"; \ + ./testsudoers -dt <$$t >$$out 2>$$toke; \ + if cmp $$out $$dir/$$out.ok >/dev/null; then \ + passed=`expr $$passed + 1`; \ + echo "$$dirbase/$$base (parse): OK"; \ + else \ + failed=`expr $$failed + 1`; \ + echo "$$dirbase/$$base: FAIL"; \ + diff $$out $$dir/$$out.ok; \ + fi; \ + total=`expr $$total + 1`; \ + if cmp $$toke $$dir/$$toke.ok >/dev/null; then \ + passed=`expr $$passed + 1`; \ + echo "$$dirbase/$$base (toke): OK"; \ + else \ + failed=`expr $$failed + 1`; \ + echo "$$dirbase/$$base (toke): FAIL"; \ + diff $$out $$dir/$$out.ok; \ + fi; \ + total=`expr $$total + 1`; \ + done; \ + echo "$$dirbase: $$passed/$$total tests passed; $$failed/$$total tests failed" + @passed=0; failed=0; total=0; \ + for t in $(srcdir)/regress/*/*.sh; do \ + dir=`dirname $$t`; \ + dirbase=`basename $$dir`; \ + base=`basename $$t .sh`; \ + out="$${base}.out"; \ + err="$${base}.err"; \ + $(SHELL) $$t >$$out 2>$$err; \ + if cmp $$out $$dir/$$out.ok >/dev/null; then \ + passed=`expr $$passed + 1`; \ + echo "$$dirbase/$$base: OK"; \ + else \ + failed=`expr $$failed + 1`; \ + echo "$$dirbase/$$base: FAIL"; \ + diff $$out $$dir/$$out.ok; \ + fi; \ + total=`expr $$total + 1`; \ + if test -s $$dir/$$err.ok; then \ + if cmp $$err $$dir/$$err.ok >/dev/null; then \ + passed=`expr $$passed + 1`; \ + echo "$$dirbase/$$base (stderr): OK"; \ + else \ + failed=`expr $$failed + 1`; \ + echo "$$dirbase/$$base (stderr): FAIL"; \ + diff $$out $$dir/$$out.ok; \ + fi; \ + total=`expr $$total + 1`; \ + elif test -s $$err; then \ + cat $$err 1>&2; \ + fi; \ + done; \ + echo "$$dirbase: $$passed/$$total tests passed; $$failed/$$total tests failed" clean: -$(LIBTOOL) --mode=clean rm -f $(PROGS) *.lo *.o *.la *.a stamp-* core *.core core.* *.out diff --git a/plugins/sudoers/regress/visudo/test1.sh b/plugins/sudoers/regress/sudoers/test1.in old mode 100755 new mode 100644 similarity index 56% rename from plugins/sudoers/regress/visudo/test1.sh rename to plugins/sudoers/regress/sudoers/test1.in index 27d0dd724..872925ce5 --- a/plugins/sudoers/regress/visudo/test1.sh +++ b/plugins/sudoers/regress/sudoers/test1.in @@ -1,22 +1,8 @@ -#!/bin/sh # # Verify that all command tags are parsed OK. # See http://www.sudo.ws/bugs/show_bug.cgi?id=437 # - -WANT=${SRCDIR-.}/regress/visudo/test1.ok -GOT=vs_test1.out -./visudo -c -f- > $GOT </dev/null; then - echo "visudo 1: OK" -else - echo "visudo 1: FAILED" - diff $WANT $GOT -fi diff --git a/plugins/sudoers/regress/sudoers/test1.out.ok b/plugins/sudoers/regress/sudoers/test1.out.ok new file mode 100644 index 000000000..44cb6526e --- /dev/null +++ b/plugins/sudoers/regress/sudoers/test1.out.ok @@ -0,0 +1,6 @@ +Parses OK. + + + +user1 ALL = /usr/bin/su - : ALL = /usr/bin/id +user2 ALL = NOPASSWD: NOEXEC: /usr/bin/vi : ALL = PASSWD: EXEC: /usr/bin/echo diff --git a/plugins/sudoers/regress/sudoers/test1.toke.ok b/plugins/sudoers/regress/sudoers/test1.toke.ok new file mode 100644 index 000000000..3f3a7ad34 --- /dev/null +++ b/plugins/sudoers/regress/sudoers/test1.toke.ok @@ -0,0 +1,6 @@ +# +# +# +# +WORD(5) ALL = LOG_INPUT LOG_OUTPUT COMMAND ARG : ALL = NOLOG_INPUT NOLOG_OUTPUT COMMAND +WORD(5) ALL = NOPASSWD NOEXEC SETENV COMMAND : ALL = PASSWD EXEC NOSETENV COMMAND diff --git a/plugins/sudoers/regress/testsudoers/test2.sh b/plugins/sudoers/regress/sudoers/test2.in old mode 100755 new mode 100644 similarity index 81% rename from plugins/sudoers/regress/testsudoers/test2.sh rename to plugins/sudoers/regress/sudoers/test2.in index 892f0cdac..cfdfaa34a --- a/plugins/sudoers/regress/testsudoers/test2.sh +++ b/plugins/sudoers/regress/sudoers/test2.in @@ -1,13 +1,3 @@ -#!/bin/sh -# -# Test quoted words in sudoers. -# Note that a backslash in double quotes is treated literally unless -# it is escaping a double quote. -# - -WANT=${SRCDIR-.}/regress/testsudoers/test2.out -GOT=ts_test2.out -./testsudoers -d > $GOT <"some one" set_home "%:C/non_UNIX_0 c" "hostf" = ("root") ALL "%:C/non\'UNIX_3 c" "hostg" = ("root") ALL "+netgr" "hosth" = ("root") ALL -EOF - -# Check results -if cmp $WANT $GOT >/dev/null; then - echo "testsudoers 2: OK" -else - echo "testsudoers 2: FAILED" - diff $WANT $GOT -fi diff --git a/plugins/sudoers/regress/testsudoers/test2.out b/plugins/sudoers/regress/sudoers/test2.out.ok similarity index 100% rename from plugins/sudoers/regress/testsudoers/test2.out rename to plugins/sudoers/regress/sudoers/test2.out.ok diff --git a/plugins/sudoers/regress/sudoers/test2.toke.ok b/plugins/sudoers/regress/sudoers/test2.toke.ok new file mode 100644 index 000000000..fcd7b73e3 --- /dev/null +++ b/plugins/sudoers/regress/sudoers/test2.toke.ok @@ -0,0 +1,60 @@ +# +USERALIAS ALIAS = BEGINSTR STRBODY ENDSTR WORD(4) +USERALIAS ALIAS = BEGINSTR STRBODY ENDSTR WORD(4) +USERALIAS ALIAS = BEGINSTR STRBODY ENDSTR WORD(4) +USERALIAS ALIAS = BEGINSTR STRBODY ENDSTR WORD(4) +USERALIAS ALIAS = BEGINSTR STRBODY ENDSTR WORD(4) + +# +USERALIAS ALIAS = BEGINSTR STRBODY ENDSTR USERGROUP +USERALIAS ALIAS = BEGINSTR STRBODY ENDSTR USERGROUP + +# +USERALIAS ALIAS = BEGINSTR STRBODY ENDSTR USERGROUP +USERALIAS ALIAS = BEGINSTR STRBODY BACKSLASH STRBODY BACKSLASH STRBODY ENDSTR USERGROUP +USERALIAS ALIAS = BEGINSTR STRBODY ENDSTR USERGROUP +USERALIAS ALIAS = BEGINSTR STRBODY ENDSTR USERGROUP +USERALIAS ALIAS = BEGINSTR STRBODY BACKSLASH STRBODY ENDSTR USERGROUP + +# +RUNASALIAS ALIAS = BEGINSTR STRBODY ENDSTR WORD(4) +RUNASALIAS ALIAS = BEGINSTR STRBODY ENDSTR WORD(4) +RUNASALIAS ALIAS = BEGINSTR STRBODY ENDSTR WORD(4) +RUNASALIAS ALIAS = BEGINSTR STRBODY ENDSTR WORD(4) + +# +DEFAULTS_HOST BEGINSTR STRBODY ENDSTR WORD(4) DEFVAR +DEFAULTS_HOST BEGINSTR STRBODY ENDSTR WORD(4) DEFVAR + +# +DEFAULTS_USER BEGINSTR STRBODY ENDSTR WORD(4) DEFVAR +DEFAULTS_USER BEGINSTR STRBODY ENDSTR WORD(4) DEFVAR +DEFAULTS_USER BEGINSTR STRBODY ENDSTR WORD(4) DEFVAR +DEFAULTS_USER BEGINSTR STRBODY ENDSTR WORD(4) DEFVAR +DEFAULTS_USER BEGINSTR STRBODY ENDSTR WORD(4) DEFVAR + +# +DEFAULTS_RUNAS BEGINSTR STRBODY ENDSTR WORD(4) DEFVAR +DEFAULTS_RUNAS BEGINSTR STRBODY ENDSTR WORD(4) DEFVAR + +# +# +# +# + +# +BEGINSTR STRBODY ENDSTR WORD(4) BEGINSTR STRBODY ENDSTR WORD(4) = ( BEGINSTR STRBODY ENDSTR WORD(4) ) ALL +BEGINSTR STRBODY ENDSTR WORD(4) BEGINSTR STRBODY ENDSTR WORD(4) = ( BEGINSTR STRBODY ENDSTR WORD(4) ) ALL +BEGINSTR STRBODY ENDSTR WORD(4) BEGINSTR STRBODY ENDSTR WORD(4) = ( BEGINSTR STRBODY ENDSTR WORD(4) ) ALL +BEGINSTR STRBODY ENDSTR WORD(4) BEGINSTR STRBODY ENDSTR WORD(4) = ( BEGINSTR STRBODY ENDSTR WORD(4) ) ALL +BEGINSTR STRBODY ENDSTR WORD(4) BEGINSTR STRBODY ENDSTR WORD(4) = ( BEGINSTR STRBODY ENDSTR WORD(4) ) ALL + +# +BEGINSTR STRBODY ENDSTR USERGROUP BEGINSTR STRBODY ENDSTR WORD(4) = ( BEGINSTR STRBODY ENDSTR WORD(4) ) ALL +BEGINSTR STRBODY ENDSTR USERGROUP BEGINSTR STRBODY ENDSTR WORD(4) = ( BEGINSTR STRBODY ENDSTR WORD(4) ) ALL +BEGINSTR STRBODY ENDSTR USERGROUP BEGINSTR STRBODY ENDSTR WORD(4) = ( BEGINSTR STRBODY ENDSTR WORD(4) ) ALL +BEGINSTR STRBODY BACKSLASH STRBODY BACKSLASH STRBODY ENDSTR USERGROUP BEGINSTR STRBODY ENDSTR WORD(4) = ( BEGINSTR STRBODY ENDSTR WORD(4) ) ALL +BEGINSTR STRBODY ENDSTR USERGROUP BEGINSTR STRBODY ENDSTR WORD(4) = ( BEGINSTR STRBODY ENDSTR WORD(4) ) ALL +BEGINSTR STRBODY ENDSTR USERGROUP BEGINSTR STRBODY ENDSTR WORD(4) = ( BEGINSTR STRBODY ENDSTR WORD(4) ) ALL +BEGINSTR STRBODY BACKSLASH STRBODY ENDSTR USERGROUP BEGINSTR STRBODY ENDSTR WORD(4) = ( BEGINSTR STRBODY ENDSTR WORD(4) ) ALL +BEGINSTR STRBODY ENDSTR NETGROUP BEGINSTR STRBODY ENDSTR WORD(4) = ( BEGINSTR STRBODY ENDSTR WORD(4) ) ALL diff --git a/plugins/sudoers/regress/sudoers/test3.in b/plugins/sudoers/regress/sudoers/test3.in new file mode 100644 index 000000000..82fcd8385 --- /dev/null +++ b/plugins/sudoers/regress/sudoers/test3.in @@ -0,0 +1,6 @@ +# Test whitespace in User_List as part of a per-user Defaults entry +User_Alias FOO = foo, bar +Defaults:FOO env_reset +Defaults:foo,bar env_reset +Defaults:foo,\ bar env_reset +Defaults:foo, bar env_reset diff --git a/plugins/sudoers/regress/testsudoers/test3.ok b/plugins/sudoers/regress/sudoers/test3.out.ok similarity index 100% rename from plugins/sudoers/regress/testsudoers/test3.ok rename to plugins/sudoers/regress/sudoers/test3.out.ok diff --git a/plugins/sudoers/regress/sudoers/test3.toke.ok b/plugins/sudoers/regress/sudoers/test3.toke.ok new file mode 100644 index 000000000..49f2e51af --- /dev/null +++ b/plugins/sudoers/regress/sudoers/test3.toke.ok @@ -0,0 +1,6 @@ +# +USERALIAS ALIAS = WORD(5) , WORD(5) +DEFAULTS_USER ALIAS DEFVAR +DEFAULTS_USER WORD(5) , WORD(5) DEFVAR +DEFAULTS_USER WORD(5) , WORD(5) DEFVAR +DEFAULTS_USER WORD(5) , WORD(5) DEFVAR diff --git a/plugins/sudoers/regress/testsudoers/test1.ok b/plugins/sudoers/regress/testsudoers/test1.out.ok similarity index 100% rename from plugins/sudoers/regress/testsudoers/test1.ok rename to plugins/sudoers/regress/testsudoers/test1.out.ok diff --git a/plugins/sudoers/regress/testsudoers/test1.sh b/plugins/sudoers/regress/testsudoers/test1.sh index c64c718f5..88eb9c431 100755 --- a/plugins/sudoers/regress/testsudoers/test1.sh +++ b/plugins/sudoers/regress/testsudoers/test1.sh @@ -5,16 +5,6 @@ # This is RedHat bug Bug 667103. # -WANT=${SRCDIR-.}/regress/testsudoers/test1.ok -GOT=ts_test1.out -./testsudoers -g wheel root id > $GOT </dev/null; then - echo "testsudoers 1: OK" -else - echo "testsudoers 1: FAILED" - diff $WANT $GOT -fi diff --git a/plugins/sudoers/regress/testsudoers/test3.sh b/plugins/sudoers/regress/testsudoers/test3.sh deleted file mode 100755 index c6b67054e..000000000 --- a/plugins/sudoers/regress/testsudoers/test3.sh +++ /dev/null @@ -1,22 +0,0 @@ -#!/bin/sh -# -# Test whitespace in User_List as part of a per-user Defaults entry -# - -WANT=${SRCDIR-.}/regress/testsudoers/test3.ok -GOT=ts_test3.out -./testsudoers -d > $GOT </dev/null; then - echo "testsudoers 3: OK" -else - echo "testsudoers 3: FAILED" - diff $WANT $GOT -fi diff --git a/plugins/sudoers/regress/visudo/test1.ok b/plugins/sudoers/regress/visudo/test1.ok deleted file mode 100644 index e5c355c2e..000000000 --- a/plugins/sudoers/regress/visudo/test1.ok +++ /dev/null @@ -1 +0,0 @@ -stdin: parsed OK