diff options
author | Ismo Puustinen <ismo.puustinen@intel.com> | 2017-06-27 15:14:59 +0300 |
---|---|---|
committer | Pablo Neira Ayuso <pablo@netfilter.org> | 2017-06-27 18:10:25 +0200 |
commit | 03a17f80bab09f8d9585b70464634ca50d3ffc7c (patch) | |
tree | 196bf953a444c755ee884d2d81c6523a8dc4d001 | |
parent | 8368e63eff044b78b9332f3af398a940d75e590f (diff) |
tests: update include directory tests to support wildcard syntax.
Signed-off-by: Ismo Puustinen <ismo.puustinen@intel.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
-rwxr-xr-x | tests/shell/testcases/include/0005glob_empty_0 (renamed from tests/shell/testcases/include/0005dir_empty_0) | 4 | ||||
-rwxr-xr-x | tests/shell/testcases/include/0006glob_single_0 (renamed from tests/shell/testcases/include/0006dir_single_0) | 2 | ||||
-rwxr-xr-x | tests/shell/testcases/include/0007glob_double_0 (renamed from tests/shell/testcases/include/0007dir_double_0) | 2 | ||||
-rwxr-xr-x | tests/shell/testcases/include/0008glob_nofile_wildcard_0 (renamed from tests/shell/testcases/include/0008dir_no_slash_1) | 16 | ||||
-rwxr-xr-x | tests/shell/testcases/include/0009glob_nofile_1 (renamed from tests/shell/testcases/include/0009dir_nodir_1) | 4 | ||||
-rwxr-xr-x | tests/shell/testcases/include/0010glob_broken_file_1 (renamed from tests/shell/testcases/include/0010dir_broken_file_1) | 4 | ||||
-rwxr-xr-x | tests/shell/testcases/include/0011glob_dependency_0 (renamed from tests/shell/testcases/include/0011dir_dependency_0) | 4 | ||||
-rwxr-xr-x | tests/shell/testcases/include/0012glob_dependency_1 (renamed from tests/shell/testcases/include/0012dir_dependency_1) | 4 | ||||
-rwxr-xr-x | tests/shell/testcases/include/0013glob_dotfile_0 | 49 | ||||
-rwxr-xr-x | tests/shell/testcases/include/0014glob_directory_0 | 43 | ||||
-rwxr-xr-x | tests/shell/testcases/include/0015doubleincludepath_0 | 52 |
11 files changed, 171 insertions, 13 deletions
diff --git a/tests/shell/testcases/include/0005dir_empty_0 b/tests/shell/testcases/include/0005glob_empty_0 index f16acf82..0743d0d7 100755 --- a/tests/shell/testcases/include/0005dir_empty_0 +++ b/tests/shell/testcases/include/0005glob_empty_0 @@ -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 diff --git a/tests/shell/testcases/include/0006dir_single_0 b/tests/shell/testcases/include/0006glob_single_0 index ae4fd5f1..754db6f7 100755 --- a/tests/shell/testcases/include/0006dir_single_0 +++ b/tests/shell/testcases/include/0006glob_single_0 @@ -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 diff --git a/tests/shell/testcases/include/0007dir_double_0 b/tests/shell/testcases/include/0007glob_double_0 index 0a14adee..9b45a62d 100755 --- a/tests/shell/testcases/include/0007dir_double_0 +++ b/tests/shell/testcases/include/0007glob_double_0 @@ -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 diff --git a/tests/shell/testcases/include/0008dir_no_slash_1 b/tests/shell/testcases/include/0008glob_nofile_wildcard_0 index 2820dc9e..f9c0aa19 100755 --- a/tests/shell/testcases/include/0008dir_no_slash_1 +++ b/tests/shell/testcases/include/0008glob_nofile_wildcard_0 @@ -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 diff --git a/tests/shell/testcases/include/0009dir_nodir_1 b/tests/shell/testcases/include/0009glob_nofile_1 index d7407f45..bab58305 100755 --- a/tests/shell/testcases/include/0009dir_nodir_1 +++ b/tests/shell/testcases/include/0009glob_nofile_1 @@ -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 diff --git a/tests/shell/testcases/include/0010dir_broken_file_1 b/tests/shell/testcases/include/0010glob_broken_file_1 index c0939746..9027f189 100755 --- a/tests/shell/testcases/include/0010dir_broken_file_1 +++ b/tests/shell/testcases/include/0010glob_broken_file_1 @@ -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 diff --git a/tests/shell/testcases/include/0011dir_dependency_0 b/tests/shell/testcases/include/0011glob_dependency_0 index 8ee193fd..8786850e 100755 --- a/tests/shell/testcases/include/0011dir_dependency_0 +++ b/tests/shell/testcases/include/0011glob_dependency_0 @@ -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 diff --git a/tests/shell/testcases/include/0012dir_dependency_1 b/tests/shell/testcases/include/0012glob_dependency_1 index c81ca327..740f5ea1 100755 --- a/tests/shell/testcases/include/0012dir_dependency_1 +++ b/tests/shell/testcases/include/0012glob_dependency_1 @@ -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 index 00000000..36cfe1c0 --- /dev/null +++ b/tests/shell/testcases/include/0013glob_dotfile_0 @@ -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 index 00000000..9a2443a5 --- /dev/null +++ b/tests/shell/testcases/include/0014glob_directory_0 @@ -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 index 00000000..db703468 --- /dev/null +++ b/tests/shell/testcases/include/0015doubleincludepath_0 @@ -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 |