diff --git a/parser/tst/dirtest.sh b/parser/tst/dirtest.sh new file mode 100755 index 000000000..38eb0bb22 --- /dev/null +++ b/parser/tst/dirtest.sh @@ -0,0 +1,68 @@ +#!/bin/sh +# +# Copyright (c) 2013 +# Canonical, Ltd. (All rights reserved) +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of version 2 of the GNU General Public +# License published by the Free Software Foundation. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, contact Canonical Ltd. +# + +# simple test to ensure dir is being iterated as expected +# yes this needs to be improved and reworked + + +# passed in by Makefile +#APPARMOR_PARSER="${APPARMOR_PARSER:-../apparmor_parser}" + + +do_tst() { + local msg="$1" + local expected="$2" + local rc=0 + shift 2 + #global tmpdir + + ${APPARMOR_PARSER} "$@" > "$tmpdir/out" 2>/dev/null + rc=$? + if [ $rc -ne 0 ] && [ "$expected" != "fail" ] ; then + echo "failed: expected \"$expected\" but parser returned error" + return 1 + fi + if ! diff -q "$tmpdir/out" dirtest/dirtest.out ; then + echo "failed: expected \"$expected\" but output comparison failed" + diff -u dirtest/dirtest.out "$tmpdir/out" + return 1 + fi + + return 0 +} + +tmpdir=$(mktemp -d "$tmpdir.XXXXXXXX") +chmod 755 "$tmpdir" +export tmpdir + +rc=0 + +# pass - no parser errors and output matches +# error - parser error and output matches +# fail - comparison out parser output failed +do_tst "good dir list" pass -N dirtest/gooddir/ || rc=1 +do_tst "bad link in dir" fail -N dirtest/badlink/ || rc=1 +do_tst "bad profile in dir" fail -N dirtest/badprofile/ || rc=1 + +rm -rf "$tmpdir" + +if [ $rc -eq 0 ] ; then + echo "PASS" +fi + +exit $rc diff --git a/parser/tst/dirtest/badlink/bar b/parser/tst/dirtest/badlink/bar new file mode 120000 index 000000000..191028156 --- /dev/null +++ b/parser/tst/dirtest/badlink/bar @@ -0,0 +1 @@ +foo \ No newline at end of file diff --git a/parser/tst/dirtest/badlink/good_link b/parser/tst/dirtest/badlink/good_link new file mode 120000 index 000000000..b00b53e5d --- /dev/null +++ b/parser/tst/dirtest/badlink/good_link @@ -0,0 +1 @@ +../goodtarget \ No newline at end of file diff --git a/parser/tst/dirtest/badlink/profileA b/parser/tst/dirtest/badlink/profileA new file mode 100644 index 000000000..6e3c2a75e --- /dev/null +++ b/parser/tst/dirtest/badlink/profileA @@ -0,0 +1,2 @@ +profile a_profile { +} diff --git a/parser/tst/dirtest/badlink/profileB b/parser/tst/dirtest/badlink/profileB new file mode 100644 index 000000000..0b5565a68 --- /dev/null +++ b/parser/tst/dirtest/badlink/profileB @@ -0,0 +1,2 @@ +profile b_profile { +} diff --git a/parser/tst/dirtest/badprofile/bad b/parser/tst/dirtest/badprofile/bad new file mode 100644 index 000000000..cd65ddcb6 --- /dev/null +++ b/parser/tst/dirtest/badprofile/bad @@ -0,0 +1,3 @@ +profile bad_profile { + file +} diff --git a/parser/tst/dirtest/badprofile/good_link b/parser/tst/dirtest/badprofile/good_link new file mode 120000 index 000000000..b00b53e5d --- /dev/null +++ b/parser/tst/dirtest/badprofile/good_link @@ -0,0 +1 @@ +../goodtarget \ No newline at end of file diff --git a/parser/tst/dirtest/badprofile/profileA b/parser/tst/dirtest/badprofile/profileA new file mode 100644 index 000000000..6e3c2a75e --- /dev/null +++ b/parser/tst/dirtest/badprofile/profileA @@ -0,0 +1,2 @@ +profile a_profile { +} diff --git a/parser/tst/dirtest/badprofile/profileB b/parser/tst/dirtest/badprofile/profileB new file mode 100644 index 000000000..0b5565a68 --- /dev/null +++ b/parser/tst/dirtest/badprofile/profileB @@ -0,0 +1,2 @@ +profile b_profile { +} diff --git a/parser/tst/dirtest/dirtest.out b/parser/tst/dirtest/dirtest.out new file mode 100644 index 000000000..e82188b84 --- /dev/null +++ b/parser/tst/dirtest/dirtest.out @@ -0,0 +1,3 @@ +good_target +a_profile +b_profile diff --git a/parser/tst/dirtest/gooddir/good_link b/parser/tst/dirtest/gooddir/good_link new file mode 120000 index 000000000..b00b53e5d --- /dev/null +++ b/parser/tst/dirtest/gooddir/good_link @@ -0,0 +1 @@ +../goodtarget \ No newline at end of file diff --git a/parser/tst/dirtest/gooddir/profileA b/parser/tst/dirtest/gooddir/profileA new file mode 100644 index 000000000..6e3c2a75e --- /dev/null +++ b/parser/tst/dirtest/gooddir/profileA @@ -0,0 +1,2 @@ +profile a_profile { +} diff --git a/parser/tst/dirtest/gooddir/profileB b/parser/tst/dirtest/gooddir/profileB new file mode 100644 index 000000000..0b5565a68 --- /dev/null +++ b/parser/tst/dirtest/gooddir/profileB @@ -0,0 +1,2 @@ +profile b_profile { +} diff --git a/parser/tst/dirtest/goodtarget b/parser/tst/dirtest/goodtarget new file mode 100644 index 000000000..04a0e795e --- /dev/null +++ b/parser/tst/dirtest/goodtarget @@ -0,0 +1,2 @@ +profile good_target { +}