2
0
mirror of https://gitlab.com/apparmor/apparmor synced 2025-08-22 01:57:43 +00:00

parser: dirtest that was supposed to be part of the previous commit

libapparmor: fix handling of failed symlink traversal, fixed a couple
of directory walk issues that could cause failures. The test included
in this commit was supposed to be included in the previous commit,
but was accidentally dropped. Even worse the make file changes did
make it causing the previous commit to break the CI.

Fixes: MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/85
Signed-off-by: John Johansen <john.johansen@canonical.com>
This commit is contained in:
John Johansen 2022-02-27 01:03:22 -08:00
parent acc6ba1cb7
commit bd78b6b292
14 changed files with 92 additions and 0 deletions

68
parser/tst/dirtest.sh Executable file
View File

@ -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

View File

@ -0,0 +1 @@
foo

View File

@ -0,0 +1 @@
../goodtarget

View File

@ -0,0 +1,2 @@
profile a_profile {
}

View File

@ -0,0 +1,2 @@
profile b_profile {
}

View File

@ -0,0 +1,3 @@
profile bad_profile {
file
}

View File

@ -0,0 +1 @@
../goodtarget

View File

@ -0,0 +1,2 @@
profile a_profile {
}

View File

@ -0,0 +1,2 @@
profile b_profile {
}

View File

@ -0,0 +1,3 @@
good_target
a_profile
b_profile

View File

@ -0,0 +1 @@
../goodtarget

View File

@ -0,0 +1,2 @@
profile a_profile {
}

View File

@ -0,0 +1,2 @@
profile b_profile {
}

View File

@ -0,0 +1,2 @@
profile good_target {
}