#!/bin/bash
+# Including files in an empty directory must not fail.
+
set -e
tmpdir=$(mktemp -d)
# cleanup if aborted
trap "rm -rf $tmpfile1 && rmdir $tmpdir" EXIT
-RULESET1="include \"$tmpdir/\""
+RULESET1="include \"$tmpdir/*\""
echo "$RULESET1" > $tmpfile1
trap "rm -rf $tmpfile1 $tmpfile2 && rmdir $tmpdir" EXIT
RULESET1="add table x"
-RULESET2="include \"$tmpdir/\""
+RULESET2="include \"$tmpdir/*\""
echo "$RULESET1" > $tmpfile1
echo "$RULESET2" > $tmpfile2
RULESET1="add table x"
RULESET2="add table y"
-RULESET3="include \"$tmpdir/\""
+RULESET3="include \"$tmpdir/*\""
echo "$RULESET1" > $tmpfile1
echo "$RULESET2" > $tmpfile2
#!/bin/bash
+# When using wildcards, not having any match is not an error.
+
set -e
tmpdir=$(mktemp -d)
exit 0
fi
-tmpfile1=$(mktemp -p $tmpdir)
+# remove the directory
+rmdir $tmpdir
+
+tmpfile1=$(mktemp)
if [ ! -w $tmpfile1 ] ; then
echo "Failed to create tmp file" >&2
exit 0
fi
# cleanup if aborted
-trap "rm -rf $tmpfile1 && rmdir $tmpdir" EXIT
+trap "rm -rf $tmpfile1" EXIT
-RULESET1="include \"$tmpdir\""
+RULESET1="include \"$tmpdir/non_existent_file*.nft\""
echo "$RULESET1" > $tmpfile1
$NFT -f $tmpfile1
-
-if [ $? -eq 0 ] ; then
- echo "E: did not catch missing slash in directory name" >&2
+if [ $? -ne 0 ] ; then
+ echo "E: unable to load good ruleset" >&2
exit 1
fi
#!/bin/bash
+# When not using wildcards, not having any match is an error.
+
set -e
tmpdir=$(mktemp -d)
# cleanup if aborted
trap "rm -rf $tmpfile1" EXIT
-RULESET1="include \"$tmpdir/\""
+RULESET1="include \"$tmpdir/non_existent_file.nft\""
echo "$RULESET1" > $tmpfile1
#!/bin/bash
+# Loading broken files must fail.
+
set -e
tmpdir=$(mktemp -d)
# do an error in a file
RULESET2="intentionally broken file"
-RULESET3="include \"$tmpdir/\""
+RULESET3="include \"$tmpdir/*\""
echo "$RULESET1" > $tmpfile1
echo "$RULESET2" > $tmpfile2
#!/bin/bash
+# Files are included in alphabetical order.
+
set -e
tmpdir=$(mktemp -d)
# add interdependent rulesets
RULESET1="add table x"
RULESET2="add chain x y"
-RULESET3="include \"$tmpdir/\""
+RULESET3="include \"$tmpdir/*\""
echo "$RULESET1" > $tmpfile1
echo "$RULESET2" > $tmpfile2
#!/bin/bash
+# Files are included in alphabetical order.
+
set -e
tmpdir=$(mktemp -d)
# add interdependent rulesets
RULESET1="add table x"
RULESET2="add chain x y"
-RULESET3="include \"$tmpdir/\""
+RULESET3="include \"$tmpdir/*\""
# Note different order when compared with 0011dir_depencency_0. The idea
# here is to introduce wrong order to get the loading fail.
--- /dev/null
+#!/bin/bash
+
+# Must not load a dot file in globbed directory.
+
+set -e
+
+tmpdir=$(mktemp -d)
+if [ ! -d $tmpdir ] ; then
+ echo "Failed to create tmp directory" >&2
+ exit 0
+fi
+
+tmpfile1=$(mktemp -p $tmpdir)
+if [ ! -w $tmpfile1 ] ; then
+ echo "Failed to create tmp file" >&2
+ exit 0
+fi
+
+tmpfile2=$(mktemp -p $tmpdir ".XXXXXXXX")
+if [ ! -w $tmpfile2 ] ; then
+ echo "Failed to create tmp file" >&2
+ exit 0
+fi
+
+tmpfile3=$(mktemp)
+if [ ! -w $tmpfile3 ] ; then
+ echo "Failed to create tmp file" >&2
+ exit 0
+fi
+
+# cleanup if aborted
+trap "rm -rf $tmpfile1 $tmpfile2 $tmpfile3 && rmdir $tmpdir" EXIT
+
+RULESET1="add table x"
+
+# an error in a dot file
+RULESET2="intentionally broken file"
+RULESET3="include \"$tmpdir/*\""
+
+echo "$RULESET1" > $tmpfile1
+echo "$RULESET2" > $tmpfile2
+echo "$RULESET3" > $tmpfile3
+
+$NFT -f $tmpfile3
+
+if [ $? -ne 0 ] ; then
+ echo "E: tried to load a .dot file" >&2
+ exit 1
+fi
--- /dev/null
+#!/bin/bash
+
+# Must not be confused in matched subdirectories.
+
+set -e
+
+tmpdir1=$(mktemp -d)
+if [ ! -d $tmpdir1 ] ; then
+ echo "Failed to create tmp directory" >&2
+ exit 0
+fi
+
+tmpfile1=$(mktemp -p $tmpdir1)
+if [ ! -w $tmpfile1 ] ; then
+ echo "Failed to create tmp file" >&2
+ exit 0
+fi
+
+tmpdir2=$(mktemp -p $tmpdir1 -d)
+if [ ! -w $tmpdir2 ] ; then
+ echo "Failed to create the second tmp directory" >&2
+ exit 0
+fi
+
+tmpdir3=$(mktemp -p $tmpdir2 -d)
+if [ ! -w $tmpdir3 ] ; then
+ echo "Failed to create the third tmp directory" >&2
+ exit 0
+fi
+
+# cleanup if aborted
+trap "rm -rf $tmpfile1 && rmdir $tmpdir3 && rmdir $tmpdir2 && rmdir $tmpdir1" EXIT
+
+RULESET1="include \"$tmpdir2/*\""
+
+echo "$RULESET1" > $tmpfile1
+
+$NFT -f $tmpfile1
+
+if [ $? -ne 0 ] ; then
+ echo "E: tried to include a matched directory" >&2
+ exit 1
+fi
--- /dev/null
+#!/bin/bash
+
+set -e
+
+tmpfile=$(mktemp)
+if [ ! -w $tmpfile ] ; then
+ echo "Failed to create tmp file" >&2
+ exit 0
+fi
+
+tmpdir1=$(mktemp -d)
+if [ ! -d $tmpdir1 ] ; then
+ echo "Failed to create tmp directory" >&2
+ exit 0
+fi
+
+tmpdir2=$(mktemp -d)
+if [ ! -d $tmpdir2 ] ; then
+ echo "Failed to create tmp directory" >&2
+ exit 0
+fi
+
+tmpfile1=$(mktemp -p $tmpdir1)
+if [ ! -w $tmpfile1 ] ; then
+ echo "Failed to create tmp file" >&2
+ exit 0
+fi
+
+tmpfile2=$(mktemp -p $tmpdir2)
+if [ ! -w $tmpfile2 ] ; then
+ echo "Failed to create tmp file" >&2
+ exit 0
+fi
+
+trap "rm -rf $tmpdfile $tmpfile1 $tmpfile2 && rmdir $tmpdir1 && rmdir $tmpdir2" EXIT # cleanup if aborted
+
+RULESET1="add table x"
+RULESET2="add chain x y"
+RULESET3=" \
+include \"$(basename $tmpfile1)\"
+include \"$(basename $tmpfile2)\"
+"
+
+echo "$RULESET1" > $tmpfile1
+echo "$RULESET2" > $tmpfile2
+echo "$RULESET3" > $tmpfile
+
+$NFT -I $tmpdir1 -I $tmpdir2 -f $tmpfile
+if [ $? -ne 0 ] ; then
+ echo "E: unable to load good ruleset" >&2
+ exit 1
+fi