]> git.ipfire.org Git - thirdparty/nftables.git/commitdiff
tests: update include directory tests to support wildcard syntax.
authorIsmo Puustinen <ismo.puustinen@intel.com>
Tue, 27 Jun 2017 12:14:59 +0000 (15:14 +0300)
committerPablo Neira Ayuso <pablo@netfilter.org>
Tue, 27 Jun 2017 16:10:25 +0000 (18:10 +0200)
Signed-off-by: Ismo Puustinen <ismo.puustinen@intel.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
tests/shell/testcases/include/0005glob_empty_0 [moved from tests/shell/testcases/include/0005dir_empty_0 with 83% similarity]
tests/shell/testcases/include/0006glob_single_0 [moved from tests/shell/testcases/include/0006dir_single_0 with 95% similarity]
tests/shell/testcases/include/0007glob_double_0 [moved from tests/shell/testcases/include/0007dir_double_0 with 96% similarity]
tests/shell/testcases/include/0008glob_nofile_wildcard_0 [moved from tests/shell/testcases/include/0008dir_no_slash_1 with 53% similarity]
tests/shell/testcases/include/0009glob_nofile_1 [moved from tests/shell/testcases/include/0009dir_nodir_1 with 81% similarity]
tests/shell/testcases/include/0010glob_broken_file_1 [moved from tests/shell/testcases/include/0010dir_broken_file_1 with 92% similarity]
tests/shell/testcases/include/0011glob_dependency_0 [moved from tests/shell/testcases/include/0011dir_dependency_0 with 91% similarity]
tests/shell/testcases/include/0012glob_dependency_1 [moved from tests/shell/testcases/include/0012dir_dependency_1 with 93% similarity]
tests/shell/testcases/include/0013glob_dotfile_0 [new file with mode: 0755]
tests/shell/testcases/include/0014glob_directory_0 [new file with mode: 0755]
tests/shell/testcases/include/0015doubleincludepath_0 [new file with mode: 0755]

similarity index 83%
rename from tests/shell/testcases/include/0005dir_empty_0
rename to tests/shell/testcases/include/0005glob_empty_0
index f16acf8288c3fb14fba11481126944c3dabef209..0743d0d707cc9b92db71755f2b572d9b04543d14 100755 (executable)
@@ -1,5 +1,7 @@
 #!/bin/bash
 
+# Including files in an empty directory must not fail.
+
 set -e
 
 tmpdir=$(mktemp -d)
@@ -17,7 +19,7 @@ fi
 # cleanup if aborted
 trap "rm -rf $tmpfile1 && rmdir $tmpdir" EXIT
 
-RULESET1="include \"$tmpdir/\""
+RULESET1="include \"$tmpdir/*\""
 
 echo "$RULESET1" > $tmpfile1
 
similarity index 95%
rename from tests/shell/testcases/include/0006dir_single_0
rename to tests/shell/testcases/include/0006glob_single_0
index ae4fd5f1079614ec0541650f5a9eeeb4bacdb276..754db6f729bcac7fe13beeaf9a3d914f4a1ddcf7 100755 (executable)
@@ -24,7 +24,7 @@ fi
 trap "rm -rf $tmpfile1 $tmpfile2 && rmdir $tmpdir" EXIT
 
 RULESET1="add table x"
-RULESET2="include \"$tmpdir/\""
+RULESET2="include \"$tmpdir/*\""
 
 echo "$RULESET1" > $tmpfile1
 echo "$RULESET2" > $tmpfile2
similarity index 96%
rename from tests/shell/testcases/include/0007dir_double_0
rename to tests/shell/testcases/include/0007glob_double_0
index 0a14adee32a20a2bb6b7d0ab5468e80ba7b8af28..9b45a62de7ac2e531c086197763189151b174093 100755 (executable)
@@ -31,7 +31,7 @@ trap "rm -rf $tmpfile1 $tmpfile2 $tmpfile3 && rmdir $tmpdir" EXIT
 
 RULESET1="add table x"
 RULESET2="add table y"
-RULESET3="include \"$tmpdir/\""
+RULESET3="include \"$tmpdir/*\""
 
 echo "$RULESET1" > $tmpfile1
 echo "$RULESET2" > $tmpfile2
similarity index 53%
rename from tests/shell/testcases/include/0008dir_no_slash_1
rename to tests/shell/testcases/include/0008glob_nofile_wildcard_0
index 2820dc9e1d576513cc481e3e99310431af851d64..f9c0aa192df4e298455dcff172dffb8b50fb1fa8 100755 (executable)
@@ -1,5 +1,7 @@
 #!/bin/bash
 
+# When using wildcards, not having any match is not an error.
+
 set -e
 
 tmpdir=$(mktemp -d)
@@ -8,22 +10,24 @@ if [ ! -d $tmpdir ] ; then
         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
similarity index 81%
rename from tests/shell/testcases/include/0009dir_nodir_1
rename to tests/shell/testcases/include/0009glob_nofile_1
index d7407f4598c77bd899af9b282e45caac5dfdcc21..bab583056b2e1fa6f0337f4c114a20bc62279a3d 100755 (executable)
@@ -1,5 +1,7 @@
 #!/bin/bash
 
+# When not using wildcards, not having any match is an error.
+
 set -e
 
 tmpdir=$(mktemp -d)
@@ -20,7 +22,7 @@ fi
 # cleanup if aborted
 trap "rm -rf $tmpfile1" EXIT
 
-RULESET1="include \"$tmpdir/\""
+RULESET1="include \"$tmpdir/non_existent_file.nft\""
 
 echo "$RULESET1" > $tmpfile1
 
similarity index 92%
rename from tests/shell/testcases/include/0010dir_broken_file_1
rename to tests/shell/testcases/include/0010glob_broken_file_1
index c09397462496007acdd339f8d0a6cd9fe7bee05c..9027f1899c33f2d89dff8704753658adad0d5ec4 100755 (executable)
@@ -1,5 +1,7 @@
 #!/bin/bash
 
+# Loading broken files must fail.
+
 set -e
 
 tmpdir=$(mktemp -d)
@@ -33,7 +35,7 @@ RULESET1="add table x"
 
 # do an error in a file
 RULESET2="intentionally broken file"
-RULESET3="include \"$tmpdir/\""
+RULESET3="include \"$tmpdir/*\""
 
 echo "$RULESET1" > $tmpfile1
 echo "$RULESET2" > $tmpfile2
similarity index 91%
rename from tests/shell/testcases/include/0011dir_dependency_0
rename to tests/shell/testcases/include/0011glob_dependency_0
index 8ee193fda0585c759195732186260ea348768381..8786850e2bd4660e47865c2c823416bc623b22a8 100755 (executable)
@@ -1,5 +1,7 @@
 #!/bin/bash
 
+# Files are included in alphabetical order.
+
 set -e
 
 tmpdir=$(mktemp -d)
@@ -34,7 +36,7 @@ trap "rm -rf $tmpfile1 $tmpfile2 $tmpfile3 && rmdir $tmpdir" EXIT
 # add interdependent rulesets
 RULESET1="add table x"
 RULESET2="add chain x y"
-RULESET3="include \"$tmpdir/\""
+RULESET3="include \"$tmpdir/*\""
 
 echo "$RULESET1" > $tmpfile1
 echo "$RULESET2" > $tmpfile2
similarity index 93%
rename from tests/shell/testcases/include/0012dir_dependency_1
rename to tests/shell/testcases/include/0012glob_dependency_1
index c81ca32793eaccae91525c7104d6ab6e69f83491..740f5ea110c9e41762af99e13597367c3e22f5f1 100755 (executable)
@@ -1,5 +1,7 @@
 #!/bin/bash
 
+# Files are included in alphabetical order.
+
 set -e
 
 tmpdir=$(mktemp -d)
@@ -34,7 +36,7 @@ trap "rm -rf $tmpfile1 $tmpfile2 $tmpfile3 && rmdir $tmpdir" EXIT
 # 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.
diff --git a/tests/shell/testcases/include/0013glob_dotfile_0 b/tests/shell/testcases/include/0013glob_dotfile_0
new file mode 100755 (executable)
index 0000000..36cfe1c
--- /dev/null
@@ -0,0 +1,49 @@
+#!/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
diff --git a/tests/shell/testcases/include/0014glob_directory_0 b/tests/shell/testcases/include/0014glob_directory_0
new file mode 100755 (executable)
index 0000000..9a2443a
--- /dev/null
@@ -0,0 +1,43 @@
+#!/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
diff --git a/tests/shell/testcases/include/0015doubleincludepath_0 b/tests/shell/testcases/include/0015doubleincludepath_0
new file mode 100755 (executable)
index 0000000..db70346
--- /dev/null
@@ -0,0 +1,52 @@
+#!/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