~ubuntu-branches/ubuntu/wily/apparmor/wily

« back to all changes in this revision

Viewing changes to parser/tst/caching.sh

  • Committer: Bazaar Package Importer
  • Author(s): Kees Cook
  • Date: 2011-04-27 10:38:07 UTC
  • mfrom: (5.1.118 natty)
  • Revision ID: james.westby@ubuntu.com-20110427103807-ym3rhwys6o84ith0
Tags: 2.6.1-2
debian/copyright: clarify for some full organization names.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/bin/bash
 
2
# These tests will stop running as soon as a failure is seen since they tend to build
 
3
# on the actions and results of the prior tests.
 
4
set -e
 
5
 
 
6
# This test requires introspection
 
7
if [ ! -d /sys/kernel/security/apparmor ]; then
 
8
    echo "WARNING: /sys/kernel/security/apparmor does not exist. Skipping tests"
 
9
    echo "requiring introspection."
 
10
    exit 0
 
11
fi
 
12
 
 
13
# fake base directory
 
14
basedir=$(mktemp -d -t aa-cache-XXXXXX)
 
15
trap "rm -rf $basedir" EXIT
 
16
mkdir -p $basedir/cache
 
17
 
 
18
ARGS="--base $basedir --skip-kernel-load"
 
19
 
 
20
profile=sbin.pingy
 
21
cp caching.profile $basedir/$profile
 
22
 
 
23
# Detect and slow down cache test when filesystem can't represent nanosecond delays.
 
24
timeout=0.1
 
25
touch $basedir/test1
 
26
sleep $timeout
 
27
touch $basedir/test2
 
28
TIMES=$(stat $basedir/test1 $basedir/test2 -c %z | cut -d" " -f2 | cut -d. -f2 | sort -u | wc -l)
 
29
if [ $TIMES -ne 2 ]; then
 
30
    echo "WARNING: $basedir lacks nanosecond timestamp resolution, falling back to slower test"
 
31
    timeout=1
 
32
fi
 
33
rm -f $basedir/test1 $basedir/test2
 
34
 
 
35
echo -n "Profiles are not cached by default: "
 
36
../apparmor_parser $ARGS -q -r $basedir/$profile
 
37
[ -f $basedir/cache/$profile ] && echo "FAIL ($basedir/cache/$profile exists)" && exit 1
 
38
echo "ok"
 
39
 
 
40
echo -n "Profiles are not cached when using --skip-cache: "
 
41
../apparmor_parser $ARGS -q --write-cache --skip-cache -r $basedir/$profile
 
42
[ -f $basedir/cache/$profile ] && echo "FAIL ($basedir/cache/$profile exists)" && exit 1
 
43
echo "ok"
 
44
 
 
45
sleep $timeout
 
46
 
 
47
echo -n "Profiles are cached when requested: "
 
48
../apparmor_parser $ARGS -q --write-cache -r $basedir/$profile
 
49
[ ! -f $basedir/cache/$profile ] && echo "FAIL ($basedir/cache/$profile does not exist)" && exit 1
 
50
echo "ok"
 
51
 
 
52
echo -n "Kernel features are written to cache: "
 
53
[ ! -f $basedir/cache/.features ] && echo "FAIL ($basedir/cache/.features missing)" && exit 1
 
54
read CF < $basedir/cache/.features || true
 
55
read KF < /sys/kernel/security/apparmor/features || true
 
56
[ "$CF" != "$KF" ] && echo "FAIL (feature text mismatch: cache '$CF' vs kernel '$KF')" && exit 1
 
57
echo "ok"
 
58
 
 
59
echo -n "Cache is loaded when it exists and features match: "
 
60
../apparmor_parser $ARGS -v -r $basedir/$profile | grep -q 'Cached reload succeeded' || { echo "FAIL"; exit 1; }
 
61
echo "ok"
 
62
 
 
63
echo -n "Cache is not loaded when skipping is requested: "
 
64
../apparmor_parser $ARGS -v --skip-read-cache -r $basedir/$profile | grep -q 'Replacement succeeded for' || { echo "FAIL"; exit 1; }
 
65
../apparmor_parser $ARGS -v --skip-cache -r $basedir/$profile | grep -q 'Replacement succeeded for' || { echo "FAIL"; exit 1; }
 
66
echo "ok"
 
67
 
 
68
echo -n "Cache reading is skipped when features do not match cache: "
 
69
echo -n "monkey" > $basedir/cache/.features
 
70
../apparmor_parser $ARGS -v -r $basedir/$profile | grep -q 'Replacement succeeded for' || { echo "FAIL"; exit 1; }
 
71
echo "ok"
 
72
 
 
73
echo -n "Cache writing is skipped when features do not match cache: "
 
74
rm $basedir/cache/$profile
 
75
../apparmor_parser $ARGS -v --write-cache -r $basedir/$profile | grep -q 'Replacement succeeded for' || { echo "FAIL"; exit 1; }
 
76
[ -f $basedir/cache/$profile ] && echo "FAIL ($basedir/cache/$profile exists)" && exit 1
 
77
echo "ok"
 
78
 
 
79
echo -n "Profiles are cached when requested (again): "
 
80
rm -f $basedir/cache/.features || true
 
81
rm -f $basedir/cache/$profile || true
 
82
../apparmor_parser $ARGS -q --write-cache -r $basedir/$profile
 
83
[ ! -f $basedir/cache/$profile ] && echo "FAIL ($basedir/cache/$profile does not exist)" && exit 1
 
84
echo "ok"
 
85
 
 
86
echo -n "Cache reading is skipped when profile is newer: "
 
87
sleep $timeout
 
88
touch $basedir/$profile
 
89
../apparmor_parser $ARGS -v -r $basedir/$profile | grep -q 'Replacement succeeded for' || { echo "FAIL"; exit 1; }
 
90
echo "ok"
 
91
 
 
92
echo -n "Cache is used when cache is newer: "
 
93
sleep $timeout
 
94
touch $basedir/cache/$profile
 
95
../apparmor_parser $ARGS -v -r $basedir/$profile | grep -q 'Cached reload succeeded' || { echo "FAIL"; exit 1; }
 
96
echo "ok"
 
97
 
 
98
echo -n "Cache reading is skipped when parser is newer: "
 
99
mkdir $basedir/parser
 
100
cp ../apparmor_parser $basedir/parser/
 
101
$basedir/parser/apparmor_parser $ARGS -v -r $basedir/$profile | grep -q 'Replacement succeeded for' || { echo "FAIL"; exit 1; }
 
102
echo "ok"
 
103
 
 
104
echo -n "Cache reading is skipped when parser in \$PATH is newer: "
 
105
(PATH=$basedir/parser/ /bin/sh -c "apparmor_parser $ARGS -v -r $basedir/$profile") | grep -q 'Replacement succeeded for' || { echo "FAIL"; exit 1; }
 
106
echo "ok"