From 624b034b83a66ec2263314db9dc62ac06b1ae7e7 Mon Sep 17 00:00:00 2001 From: Phil Sutter Date: Thu, 8 Feb 2024 14:30:17 +0100 Subject: tests: shell: Pretty-print all *.json-nft dumps The problem with single line output as produced by 'nft -j list ruleset' is its incompatibility to unified diff format as any change in this single line will produce a diff which contains the old and new lines in total. This is not just unreadable but will blow up patches which may exceed mailinglists' mail size limits. Convert them all at once by feeding their contents to tests/shell/helpers/json-pretty.sh. Signed-off-by: Phil Sutter --- .../testcases/optionals/dumps/comments_0.json-nft | 59 ++++++++++++++++++- .../optionals/dumps/comments_chain_0.json-nft | 28 ++++++++- .../optionals/dumps/comments_handles_0.json-nft | 59 ++++++++++++++++++- .../dumps/comments_objects_dup_0.json-nft | 12 +++- .../optionals/dumps/comments_table_0.json-nft | 20 ++++++- .../dumps/delete_object_handles_0.json-nft | 68 +++++++++++++++++++++- .../testcases/optionals/dumps/handles_0.json-nft | 58 +++++++++++++++++- .../testcases/optionals/dumps/handles_1.json-nft | 58 +++++++++++++++++- .../optionals/dumps/log_prefix_0.json-nft | 53 ++++++++++++++++- .../dumps/update_object_handles_0.json-nft | 40 ++++++++++++- 10 files changed, 445 insertions(+), 10 deletions(-) (limited to 'tests/shell/testcases/optionals/dumps') diff --git a/tests/shell/testcases/optionals/dumps/comments_0.json-nft b/tests/shell/testcases/optionals/dumps/comments_0.json-nft index 53d33b70..aef4b3e4 100644 --- a/tests/shell/testcases/optionals/dumps/comments_0.json-nft +++ b/tests/shell/testcases/optionals/dumps/comments_0.json-nft @@ -1 +1,58 @@ -{"nftables": [{"metainfo": {"version": "VERSION", "release_name": "RELEASE_NAME", "json_schema_version": 1}}, {"table": {"family": "ip", "name": "test", "handle": 0}}, {"chain": {"family": "ip", "table": "test", "name": "test", "handle": 0}}, {"rule": {"family": "ip", "table": "test", "chain": "test", "handle": 0, "comment": "test_comment", "expr": [{"match": {"op": "==", "left": {"payload": {"protocol": "tcp", "field": "dport"}}, "right": 22}}, {"counter": {"packets": 0, "bytes": 0}}, {"accept": null}]}}]} +{ + "nftables": [ + { + "metainfo": { + "version": "VERSION", + "release_name": "RELEASE_NAME", + "json_schema_version": 1 + } + }, + { + "table": { + "family": "ip", + "name": "test", + "handle": 0 + } + }, + { + "chain": { + "family": "ip", + "table": "test", + "name": "test", + "handle": 0 + } + }, + { + "rule": { + "family": "ip", + "table": "test", + "chain": "test", + "handle": 0, + "comment": "test_comment", + "expr": [ + { + "match": { + "op": "==", + "left": { + "payload": { + "protocol": "tcp", + "field": "dport" + } + }, + "right": 22 + } + }, + { + "counter": { + "packets": 0, + "bytes": 0 + } + }, + { + "accept": null + } + ] + } + } + ] +} diff --git a/tests/shell/testcases/optionals/dumps/comments_chain_0.json-nft b/tests/shell/testcases/optionals/dumps/comments_chain_0.json-nft index c57ab0be..4c752e80 100644 --- a/tests/shell/testcases/optionals/dumps/comments_chain_0.json-nft +++ b/tests/shell/testcases/optionals/dumps/comments_chain_0.json-nft @@ -1 +1,27 @@ -{"nftables": [{"metainfo": {"version": "VERSION", "release_name": "RELEASE_NAME", "json_schema_version": 1}}, {"table": {"family": "ip", "name": "test_table", "handle": 0}}, {"chain": {"family": "ip", "table": "test_table", "name": "test_chain", "handle": 0, "comment": "test"}}]} +{ + "nftables": [ + { + "metainfo": { + "version": "VERSION", + "release_name": "RELEASE_NAME", + "json_schema_version": 1 + } + }, + { + "table": { + "family": "ip", + "name": "test_table", + "handle": 0 + } + }, + { + "chain": { + "family": "ip", + "table": "test_table", + "name": "test_chain", + "handle": 0, + "comment": "test" + } + } + ] +} diff --git a/tests/shell/testcases/optionals/dumps/comments_handles_0.json-nft b/tests/shell/testcases/optionals/dumps/comments_handles_0.json-nft index 53d33b70..aef4b3e4 100644 --- a/tests/shell/testcases/optionals/dumps/comments_handles_0.json-nft +++ b/tests/shell/testcases/optionals/dumps/comments_handles_0.json-nft @@ -1 +1,58 @@ -{"nftables": [{"metainfo": {"version": "VERSION", "release_name": "RELEASE_NAME", "json_schema_version": 1}}, {"table": {"family": "ip", "name": "test", "handle": 0}}, {"chain": {"family": "ip", "table": "test", "name": "test", "handle": 0}}, {"rule": {"family": "ip", "table": "test", "chain": "test", "handle": 0, "comment": "test_comment", "expr": [{"match": {"op": "==", "left": {"payload": {"protocol": "tcp", "field": "dport"}}, "right": 22}}, {"counter": {"packets": 0, "bytes": 0}}, {"accept": null}]}}]} +{ + "nftables": [ + { + "metainfo": { + "version": "VERSION", + "release_name": "RELEASE_NAME", + "json_schema_version": 1 + } + }, + { + "table": { + "family": "ip", + "name": "test", + "handle": 0 + } + }, + { + "chain": { + "family": "ip", + "table": "test", + "name": "test", + "handle": 0 + } + }, + { + "rule": { + "family": "ip", + "table": "test", + "chain": "test", + "handle": 0, + "comment": "test_comment", + "expr": [ + { + "match": { + "op": "==", + "left": { + "payload": { + "protocol": "tcp", + "field": "dport" + } + }, + "right": 22 + } + }, + { + "counter": { + "packets": 0, + "bytes": 0 + } + }, + { + "accept": null + } + ] + } + } + ] +} diff --git a/tests/shell/testcases/optionals/dumps/comments_objects_dup_0.json-nft b/tests/shell/testcases/optionals/dumps/comments_objects_dup_0.json-nft index 0048e6b1..546cc597 100644 --- a/tests/shell/testcases/optionals/dumps/comments_objects_dup_0.json-nft +++ b/tests/shell/testcases/optionals/dumps/comments_objects_dup_0.json-nft @@ -1 +1,11 @@ -{"nftables": [{"metainfo": {"version": "VERSION", "release_name": "RELEASE_NAME", "json_schema_version": 1}}]} +{ + "nftables": [ + { + "metainfo": { + "version": "VERSION", + "release_name": "RELEASE_NAME", + "json_schema_version": 1 + } + } + ] +} diff --git a/tests/shell/testcases/optionals/dumps/comments_table_0.json-nft b/tests/shell/testcases/optionals/dumps/comments_table_0.json-nft index 5f3c759d..8512c7de 100644 --- a/tests/shell/testcases/optionals/dumps/comments_table_0.json-nft +++ b/tests/shell/testcases/optionals/dumps/comments_table_0.json-nft @@ -1 +1,19 @@ -{"nftables": [{"metainfo": {"version": "VERSION", "release_name": "RELEASE_NAME", "json_schema_version": 1}}, {"table": {"family": "ip", "name": "test", "handle": 0, "comment": "test_comment"}}]} +{ + "nftables": [ + { + "metainfo": { + "version": "VERSION", + "release_name": "RELEASE_NAME", + "json_schema_version": 1 + } + }, + { + "table": { + "family": "ip", + "name": "test", + "handle": 0, + "comment": "test_comment" + } + } + ] +} diff --git a/tests/shell/testcases/optionals/dumps/delete_object_handles_0.json-nft b/tests/shell/testcases/optionals/dumps/delete_object_handles_0.json-nft index 8961a1e6..583ce528 100644 --- a/tests/shell/testcases/optionals/dumps/delete_object_handles_0.json-nft +++ b/tests/shell/testcases/optionals/dumps/delete_object_handles_0.json-nft @@ -1 +1,67 @@ -{"nftables": [{"metainfo": {"version": "VERSION", "release_name": "RELEASE_NAME", "json_schema_version": 1}}, {"table": {"family": "ip", "name": "test-ip", "handle": 0}}, {"quota": {"family": "ip", "name": "https-quota", "table": "test-ip", "handle": 0, "bytes": 26214400, "used": 0, "inv": false}}, {"map": {"family": "ip", "name": "ports", "table": "test-ip", "type": "inet_service", "handle": 0, "map": "quota"}}, {"table": {"family": "ip6", "name": "test-ip6", "handle": 0}}, {"quota": {"family": "ip6", "name": "http-quota", "table": "test-ip6", "handle": 0, "bytes": 26214400, "used": 0, "inv": true}}, {"counter": {"family": "ip6", "name": "http-traffic", "table": "test-ip6", "handle": 0, "packets": 0, "bytes": 0}}]} +{ + "nftables": [ + { + "metainfo": { + "version": "VERSION", + "release_name": "RELEASE_NAME", + "json_schema_version": 1 + } + }, + { + "table": { + "family": "ip", + "name": "test-ip", + "handle": 0 + } + }, + { + "quota": { + "family": "ip", + "name": "https-quota", + "table": "test-ip", + "handle": 0, + "bytes": 26214400, + "used": 0, + "inv": false + } + }, + { + "map": { + "family": "ip", + "name": "ports", + "table": "test-ip", + "type": "inet_service", + "handle": 0, + "map": "quota" + } + }, + { + "table": { + "family": "ip6", + "name": "test-ip6", + "handle": 0 + } + }, + { + "quota": { + "family": "ip6", + "name": "http-quota", + "table": "test-ip6", + "handle": 0, + "bytes": 26214400, + "used": 0, + "inv": true + } + }, + { + "counter": { + "family": "ip6", + "name": "http-traffic", + "table": "test-ip6", + "handle": 0, + "packets": 0, + "bytes": 0 + } + } + ] +} diff --git a/tests/shell/testcases/optionals/dumps/handles_0.json-nft b/tests/shell/testcases/optionals/dumps/handles_0.json-nft index bd3fd867..ff06af30 100644 --- a/tests/shell/testcases/optionals/dumps/handles_0.json-nft +++ b/tests/shell/testcases/optionals/dumps/handles_0.json-nft @@ -1 +1,57 @@ -{"nftables": [{"metainfo": {"version": "VERSION", "release_name": "RELEASE_NAME", "json_schema_version": 1}}, {"table": {"family": "ip", "name": "test", "handle": 0}}, {"chain": {"family": "ip", "table": "test", "name": "test", "handle": 0}}, {"rule": {"family": "ip", "table": "test", "chain": "test", "handle": 0, "expr": [{"match": {"op": "==", "left": {"payload": {"protocol": "tcp", "field": "dport"}}, "right": 22}}, {"counter": {"packets": 0, "bytes": 0}}, {"accept": null}]}}]} +{ + "nftables": [ + { + "metainfo": { + "version": "VERSION", + "release_name": "RELEASE_NAME", + "json_schema_version": 1 + } + }, + { + "table": { + "family": "ip", + "name": "test", + "handle": 0 + } + }, + { + "chain": { + "family": "ip", + "table": "test", + "name": "test", + "handle": 0 + } + }, + { + "rule": { + "family": "ip", + "table": "test", + "chain": "test", + "handle": 0, + "expr": [ + { + "match": { + "op": "==", + "left": { + "payload": { + "protocol": "tcp", + "field": "dport" + } + }, + "right": 22 + } + }, + { + "counter": { + "packets": 0, + "bytes": 0 + } + }, + { + "accept": null + } + ] + } + } + ] +} diff --git a/tests/shell/testcases/optionals/dumps/handles_1.json-nft b/tests/shell/testcases/optionals/dumps/handles_1.json-nft index bd3fd867..ff06af30 100644 --- a/tests/shell/testcases/optionals/dumps/handles_1.json-nft +++ b/tests/shell/testcases/optionals/dumps/handles_1.json-nft @@ -1 +1,57 @@ -{"nftables": [{"metainfo": {"version": "VERSION", "release_name": "RELEASE_NAME", "json_schema_version": 1}}, {"table": {"family": "ip", "name": "test", "handle": 0}}, {"chain": {"family": "ip", "table": "test", "name": "test", "handle": 0}}, {"rule": {"family": "ip", "table": "test", "chain": "test", "handle": 0, "expr": [{"match": {"op": "==", "left": {"payload": {"protocol": "tcp", "field": "dport"}}, "right": 22}}, {"counter": {"packets": 0, "bytes": 0}}, {"accept": null}]}}]} +{ + "nftables": [ + { + "metainfo": { + "version": "VERSION", + "release_name": "RELEASE_NAME", + "json_schema_version": 1 + } + }, + { + "table": { + "family": "ip", + "name": "test", + "handle": 0 + } + }, + { + "chain": { + "family": "ip", + "table": "test", + "name": "test", + "handle": 0 + } + }, + { + "rule": { + "family": "ip", + "table": "test", + "chain": "test", + "handle": 0, + "expr": [ + { + "match": { + "op": "==", + "left": { + "payload": { + "protocol": "tcp", + "field": "dport" + } + }, + "right": 22 + } + }, + { + "counter": { + "packets": 0, + "bytes": 0 + } + }, + { + "accept": null + } + ] + } + } + ] +} diff --git a/tests/shell/testcases/optionals/dumps/log_prefix_0.json-nft b/tests/shell/testcases/optionals/dumps/log_prefix_0.json-nft index 86b5be26..161a58d4 100644 --- a/tests/shell/testcases/optionals/dumps/log_prefix_0.json-nft +++ b/tests/shell/testcases/optionals/dumps/log_prefix_0.json-nft @@ -1 +1,52 @@ -{"nftables": [{"metainfo": {"version": "VERSION", "release_name": "RELEASE_NAME", "json_schema_version": 1}}, {"table": {"family": "ip", "name": "x", "handle": 0}}, {"chain": {"family": "ip", "table": "x", "name": "y", "handle": 0}}, {"rule": {"family": "ip", "table": "x", "chain": "y", "handle": 0, "expr": [{"match": {"op": "in", "left": {"ct": {"key": "state"}}, "right": "invalid"}}, {"log": {"prefix": "invalid state match, logging:"}}]}}]} +{ + "nftables": [ + { + "metainfo": { + "version": "VERSION", + "release_name": "RELEASE_NAME", + "json_schema_version": 1 + } + }, + { + "table": { + "family": "ip", + "name": "x", + "handle": 0 + } + }, + { + "chain": { + "family": "ip", + "table": "x", + "name": "y", + "handle": 0 + } + }, + { + "rule": { + "family": "ip", + "table": "x", + "chain": "y", + "handle": 0, + "expr": [ + { + "match": { + "op": "in", + "left": { + "ct": { + "key": "state" + } + }, + "right": "invalid" + } + }, + { + "log": { + "prefix": "invalid state match, logging:" + } + } + ] + } + } + ] +} diff --git a/tests/shell/testcases/optionals/dumps/update_object_handles_0.json-nft b/tests/shell/testcases/optionals/dumps/update_object_handles_0.json-nft index 4ba1692a..ba78f8d7 100644 --- a/tests/shell/testcases/optionals/dumps/update_object_handles_0.json-nft +++ b/tests/shell/testcases/optionals/dumps/update_object_handles_0.json-nft @@ -1 +1,39 @@ -{"nftables": [{"metainfo": {"version": "VERSION", "release_name": "RELEASE_NAME", "json_schema_version": 1}}, {"table": {"family": "ip", "name": "test-ip", "handle": 0}}, {"counter": {"family": "ip", "name": "traffic-counter", "table": "test-ip", "handle": 0, "packets": 0, "bytes": 0}}, {"quota": {"family": "ip", "name": "traffic-quota", "table": "test-ip", "handle": 0, "bytes": 52428800, "used": 0, "inv": false}}]} +{ + "nftables": [ + { + "metainfo": { + "version": "VERSION", + "release_name": "RELEASE_NAME", + "json_schema_version": 1 + } + }, + { + "table": { + "family": "ip", + "name": "test-ip", + "handle": 0 + } + }, + { + "counter": { + "family": "ip", + "name": "traffic-counter", + "table": "test-ip", + "handle": 0, + "packets": 0, + "bytes": 0 + } + }, + { + "quota": { + "family": "ip", + "name": "traffic-quota", + "table": "test-ip", + "handle": 0, + "bytes": 52428800, + "used": 0, + "inv": false + } + } + ] +} -- cgit v1.2.3