]> git.ipfire.org Git - thirdparty/iptables.git/commitdiff
tests: shell: Fix and extend chain rename test
authorPhil Sutter <phil@nwl.cc>
Fri, 28 Jul 2023 11:58:46 +0000 (13:58 +0200)
committerPhil Sutter <phil@nwl.cc>
Fri, 28 Jul 2023 12:27:35 +0000 (14:27 +0200)
The old version exited unintentionally before testing ip6tables. Replace
it by a more complete variant testing for all tools, creating and
renaming of,chains with various illegal names instead of just renaming
to a clashing name.

Fixes: ed9cfe1b48526 ("tests: add initial save/restore test cases")
Signed-off-by: Phil Sutter <phil@nwl.cc>
iptables/tests/shell/testcases/chain/0003rename_0 [new file with mode: 0755]
iptables/tests/shell/testcases/chain/0003rename_1 [deleted file]

diff --git a/iptables/tests/shell/testcases/chain/0003rename_0 b/iptables/tests/shell/testcases/chain/0003rename_0
new file mode 100755 (executable)
index 0000000..4cb2745
--- /dev/null
@@ -0,0 +1,40 @@
+#!/bin/bash -x
+
+die() {
+       echo "E: $@"
+       exit 1
+}
+
+cmds="iptables ip6tables"
+[[ $XT_MULTI == *xtables-nft-multi ]] && cmds+=" arptables ebtables"
+
+declare -A invnames
+invnames["existing"]="c2"
+invnames["spaced"]="foo bar"
+invnames["dashed"]="-foo"
+invnames["negated"]="!foo"
+# XXX: ebtables-nft accepts 255 chars
+#invnames["overlong"]="thisisquitealongnameforachain"
+invnames["standard target"]="ACCEPT"
+invnames["extension target"]="DNAT"
+
+for cmd in $cmds; do
+       $XT_MULTI $cmd -N c1 || die "$cmd: can't add chain c1"
+       $XT_MULTI $cmd -N c2 || die "$cmd: can't add chain c2"
+       for key in "${!invnames[@]}"; do
+               val="${invnames[$key]}"
+               if [[ $key == "extension target" ]]; then
+                       if [[ $cmd == "arptables" ]]; then
+                               val="mangle"
+                       elif [[ $cmd == "ebtables" ]]; then
+                               val="dnat"
+                       fi
+               fi
+               $XT_MULTI $cmd -N "$val" && \
+                       die "$cmd: added chain with $key name"
+               $XT_MULTI $cmd -E c1 "$val" && \
+                       die "$cmd: renamed to $key name"
+       done
+done
+
+exit 0
diff --git a/iptables/tests/shell/testcases/chain/0003rename_1 b/iptables/tests/shell/testcases/chain/0003rename_1
deleted file mode 100755 (executable)
index 975c8e1..0000000
+++ /dev/null
@@ -1,12 +0,0 @@
-#!/bin/bash
-
-$XT_MULTI iptables -N c1 || exit 0
-$XT_MULTI iptables -N c2 || exit 0
-$XT_MULTI iptables -E c1 c2 || exit 1
-
-$XT_MULTI ip6tables -N c1 || exit 0
-$XT_MULTI ip6tables -N c2 || exit 0
-$XT_MULTI ip6tables -E c1 c2 || exit 1
-
-echo "E: Renamed with existing chain" >&2
-exit 0