File: dirtest.sh

package info (click to toggle)
apparmor 4.1.7-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 29,908 kB
  • sloc: ansic: 24,959; python: 24,916; cpp: 9,143; sh: 8,175; yacc: 2,061; makefile: 1,908; lex: 1,215; pascal: 1,147; perl: 1,033; ruby: 365; lisp: 282; exp: 250; java: 212; xml: 159
file content (73 lines) | stat: -rwxr-xr-x 1,997 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#!/bin/sh
#
#   Copyright (c) 2022
#   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.unsorted" 2>/dev/null
	rc=$?
	LC_ALL=C sort "$tmpdir/out.unsorted" > "$tmpdir/out"
	if [ $rc -ne 0 ] && [ "$expected" != "fail" ] ; then
		echo "failed: expected \"$expected\" but parser returned error"
		return 1
	fi
	if [ $rc -eq 0 ] && [ "$expected" = "fail" ] ; then
		echo "succeeded unexpectedly: expected \"$expected\" but parser returned success"
		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