| 1 |
#!/bin/bash |
| 2 |
|
| 3 |
# This test the changes made in commit id "b14572f72aac". |
| 4 |
# When the commit was not applied, nft pointed to wrong files name. |
| 5 |
# As the commit only fixes the error messages and hence does not change the |
| 6 |
# return value so, we need to compare the "file name" in the error message |
| 7 |
# instead of return value of nft. |
| 8 |
|
| 9 |
|
| 10 |
tmpfile1=$(mktemp) |
| 11 |
if [ ! -w "$tmpfile1" ] ; then |
| 12 |
echo "Failed to create tmp file" >&2 |
| 13 |
exit 1 |
| 14 |
fi |
| 15 |
|
| 16 |
trap "rm -rf $tmpfile1 $tmpfile2 $tmpfile3 $tmpfile4" EXIT # cleanup if aborted |
| 17 |
|
| 18 |
tmpfile2=$(mktemp) |
| 19 |
if [ ! -w "$tmpfile2" ] ; then |
| 20 |
echo "Failed to create tmp file" >&2 |
| 21 |
exit 1 |
| 22 |
fi |
| 23 |
|
| 24 |
tmpfile3=$(mktemp) |
| 25 |
if [ ! -w "$tmpfile3" ] ; then |
| 26 |
echo "Failed to create tmp file" >&2 |
| 27 |
exit 1 |
| 28 |
fi |
| 29 |
|
| 30 |
tmpfile4=$(mktemp) |
| 31 |
if [ ! -w "$tmpfile4" ]; then |
| 32 |
echo "Failed to create tmp file" >&2 |
| 33 |
exit 1 |
| 34 |
fi |
| 35 |
|
| 36 |
RULESET1="include \"$tmpfile2\"" |
| 37 |
RULESET2="include \"$tmpfile3\"" |
| 38 |
RULESET3="add rule x y anything everything" # wrong nft syntax |
| 39 |
|
| 40 |
|
| 41 |
echo "$RULESET1" > $tmpfile1 |
| 42 |
echo "$RULESET2" >> $tmpfile1 |
| 43 |
echo "$RULESET3" > $tmpfile2 |
| 44 |
|
| 45 |
$NFT -f $tmpfile1 2> $tmpfile4 |
| 46 |
|
| 47 |
var=$(awk -F: '$4==" Error"{print $1;exit;}' "$tmpfile4") |
| 48 |
|
| 49 |
if [ $var == "$tmpfile3" ]; then |
| 50 |
echo "E: Test failed" >&2 |
| 51 |
exit 1 |
| 52 |
fi |