test.sh 868 Bytes
Newer Older
Kaarle Ritvanen's avatar
Kaarle Ritvanen committed
1 2 3 4 5 6 7 8 9 10
#!/bin/sh -e

# Alpine Wall test script
# Copyright (C) 2012-2017 Kaarle Ritvanen
# See LICENSE file for license details


cd "$(dirname "$0")"

export LUA_PATH="./?.lua;;"
11
LUA=lua${LUA_VERSION}
Kaarle Ritvanen's avatar
Kaarle Ritvanen committed
12
AWALL="$LUA ./awall-cli"
Kaarle Ritvanen's avatar
Kaarle Ritvanen committed
13

14 15
GEN_POLICIES=

Kaarle Ritvanen's avatar
Kaarle Ritvanen committed
16 17 18
for cls in mandatory optional private; do
    eval "export AWALL_PATH_$(echo $cls | tr a-z A-Z)=test/$cls"
    mkdir -p test/$cls
19
    for script in test/$cls/*.lua; do
20 21 22 23
	[ -f $script ] || continue
	policy=${script%.lua}.json
	GEN_POLICIES="$GEN_POLICIES $policy"
	$LUA $script > $policy
24
    done
Kaarle Ritvanen's avatar
Kaarle Ritvanen committed
25 26
done

Kaarle Ritvanen's avatar
Kaarle Ritvanen committed
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
POLICIES=$(ls test/optional/*.json | sed -E 's:^.*/([^/]+).json$:\1:')

for pol in $POLICIES; do
    $AWALL disable $pol 2>/dev/null
done

RC=0
for pol in $POLICIES; do
    dir=test/output/$pol
    mkdir -p $dir

    $AWALL enable $pol
    $AWALL ${1:-diff} -o $dir || RC=1
    $AWALL disable $pol
done
42 43 44

rm $GEN_POLICIES

Kaarle Ritvanen's avatar
Kaarle Ritvanen committed
45
exit $RC