]> git.ipfire.org Git - thirdparty/nftables.git/commitdiff
tests/shell: test for maximum length of "comment" in "comments_objects_0"
authorThomas Haller <thaller@redhat.com>
Mon, 23 Oct 2023 13:38:18 +0000 (15:38 +0200)
committerPablo Neira Ayuso <pablo@netfilter.org>
Tue, 24 Oct 2023 09:31:01 +0000 (11:31 +0200)
The comment length is limited to NFTNL_UDATA_COMMENT_MAXLEN. Test for
that.

Adjust an existing test for that.

Also rename $EXPECTED to $RULESET. We don't compare the value of
$EXPECTED against the actually configured rules. It also wouldn't work,
because the input is not normalized and wouldn't match. It also isn't
necessary, because there is a .nft dump file.

Signed-off-by: Thomas Haller <thaller@redhat.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
tests/shell/testcases/optionals/comments_objects_0
tests/shell/testcases/optionals/dumps/comments_objects_0.nft

index 7437c77beb0b47ab35c9c2af07f4896bb28d297b..301f5518fb80f3962fbaa363a448da6c4d5582de 100755 (executable)
@@ -1,9 +1,23 @@
 #!/bin/bash
 
-EXPECTED='table ip filter {
+set -e
+
+COMMENT128="12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678"
+
+# test for pass with comment that is 128 bytes long.
+rc=0
+$NFT add table ip filter \{ quota foo1 \{ comment "\"${COMMENT128}\"" \}\; \}\; || rc="$?"
+test "$rc" = 0
+
+# test for failure with comment that is 128+1 bytes long.
+rc=0
+$NFT add table ip filter \{ quota foo2 \{ comment "\"${COMMENT128}x\"" \}\; \}\; || rc="$?"
+test "$rc" = 1
+
+RULESET='table ip filter {
        quota q {
                over 1200 bytes
-               comment "test1"
+               comment "'"$COMMENT128"'"
        }
 
        counter c {
@@ -39,6 +53,4 @@ EXPECTED='table ip filter {
 }
 '
 
-set -e
-
-$NFT -f - <<< "$EXPECTED"
+$NFT -f - <<< "$RULESET"
index b760ced6042407aa2e6c1f1da086c8198dade455..13822209ebabc16215e39a492b2bfe2010433a0b 100644 (file)
@@ -1,6 +1,11 @@
 table ip filter {
+       quota foo1 {
+               comment "12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678"
+               0 bytes
+       }
+
        quota q {
-               comment "test1"
+               comment "12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678"
                over 1200 bytes
        }