mirror of
https://gitlab.com/apparmor/apparmor
synced 2025-08-22 10:07:12 +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:
parent
acc6ba1cb7
commit
bd78b6b292
68
parser/tst/dirtest.sh
Executable file
68
parser/tst/dirtest.sh
Executable 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
|
1
parser/tst/dirtest/badlink/bar
Symbolic link
1
parser/tst/dirtest/badlink/bar
Symbolic link
@ -0,0 +1 @@
|
|||||||
|
foo
|
1
parser/tst/dirtest/badlink/good_link
Symbolic link
1
parser/tst/dirtest/badlink/good_link
Symbolic link
@ -0,0 +1 @@
|
|||||||
|
../goodtarget
|
2
parser/tst/dirtest/badlink/profileA
Normal file
2
parser/tst/dirtest/badlink/profileA
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
profile a_profile {
|
||||||
|
}
|
2
parser/tst/dirtest/badlink/profileB
Normal file
2
parser/tst/dirtest/badlink/profileB
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
profile b_profile {
|
||||||
|
}
|
3
parser/tst/dirtest/badprofile/bad
Normal file
3
parser/tst/dirtest/badprofile/bad
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
profile bad_profile {
|
||||||
|
file
|
||||||
|
}
|
1
parser/tst/dirtest/badprofile/good_link
Symbolic link
1
parser/tst/dirtest/badprofile/good_link
Symbolic link
@ -0,0 +1 @@
|
|||||||
|
../goodtarget
|
2
parser/tst/dirtest/badprofile/profileA
Normal file
2
parser/tst/dirtest/badprofile/profileA
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
profile a_profile {
|
||||||
|
}
|
2
parser/tst/dirtest/badprofile/profileB
Normal file
2
parser/tst/dirtest/badprofile/profileB
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
profile b_profile {
|
||||||
|
}
|
3
parser/tst/dirtest/dirtest.out
Normal file
3
parser/tst/dirtest/dirtest.out
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
good_target
|
||||||
|
a_profile
|
||||||
|
b_profile
|
1
parser/tst/dirtest/gooddir/good_link
Symbolic link
1
parser/tst/dirtest/gooddir/good_link
Symbolic link
@ -0,0 +1 @@
|
|||||||
|
../goodtarget
|
2
parser/tst/dirtest/gooddir/profileA
Normal file
2
parser/tst/dirtest/gooddir/profileA
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
profile a_profile {
|
||||||
|
}
|
2
parser/tst/dirtest/gooddir/profileB
Normal file
2
parser/tst/dirtest/gooddir/profileB
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
profile b_profile {
|
||||||
|
}
|
2
parser/tst/dirtest/goodtarget
Normal file
2
parser/tst/dirtest/goodtarget
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
profile good_target {
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user