netfilter-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Phil Sutter <phil@nwl.cc>
To: Thomas Haller <thaller@redhat.com>
Cc: NetFilter <netfilter-devel@vger.kernel.org>
Subject: Re: [PATCH nft 1/1] tests/shell: sanitize "handle" in JSON output
Date: Sat, 18 Nov 2023 03:36:28 +0100	[thread overview]
Message-ID: <ZVgjLFGvHqoXXvjd@orbyte.nwl.cc> (raw)
In-Reply-To: <20231117171948.897229-1-thaller@redhat.com>

On Fri, Nov 17, 2023 at 06:18:45PM +0100, Thomas Haller wrote:
> The "handle" in JSON output is not stable. Sanitize/normalizeit to 1216.
> 
> The number is chosen arbitrarily, but it's somewhat unique in the code
> base. So when you see it, you may guess it originates from sanitization.

Valid handles are monotonic starting at 1. Using 0 as a replacement is
too simple?

> Signed-off-by: Thomas Haller <thaller@redhat.com>
> ---
> Note that only a few .json-nft files are adjusted, because otherwise the
> patch is too large. Before applying, you need to adjust them all, by
> running `./tests/shell/run-tests.sh -g`.

Just put the bulk change into a second patch?

[...]
> diff --git a/tests/shell/helpers/json-sanitize-ruleset.sh b/tests/shell/helpers/json-sanitize-ruleset.sh
> index 270a6107e0aa..3b66adabf055 100755
> --- a/tests/shell/helpers/json-sanitize-ruleset.sh
> +++ b/tests/shell/helpers/json-sanitize-ruleset.sh
> @@ -6,7 +6,14 @@ die() {
>  }
>  
>  do_sed() {
> -	sed '1s/\({"nftables": \[{"metainfo": {"version": "\)[0-9.]\+\(", "release_name": "\)[^"]\+\(", "\)/\1VERSION\2RELEASE_NAME\3/' "$@"
> +	# Normalize the "version"/"release_name", otherwise we have to regenerate the
> +	# JSON output upon new release.
> +	#
> +	# Also, "handle" are not stable. Normalize them to 1216 (arbitrarily chosen).
> +	sed \
> +		-e '1s/\({"nftables": \[{"metainfo": {"version": "\)[0-9.]\+\(", "release_name": "\)[^"]\+\(", "\)/\1VERSION\2RELEASE_NAME\3/' \
> +		-e '1s/"handle": [0-9]\+\>/"handle": 1216/g' \
> +		"$@"
>  }

Why not just drop the whole metainfo object? A dedicated test could
still ensure its existence.

Also, scoping these replacements to line 1 is funny with single line
input. Worse is identifying the change in the resulting diff. Maybe
write a helper in python which lets you more comfortably sanitize input,
sort attributes by key and output pretty-printed?

In general, the long lines in your scripts make them quite hard to read.
Any particular reason why you don't stick to the 80 columns maxim?

Cheers, Phil

  reply	other threads:[~2023-11-18  2:36 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-11-17 17:18 [PATCH nft 1/1] tests/shell: sanitize "handle" in JSON output Thomas Haller
2023-11-18  2:36 ` Phil Sutter [this message]
2023-11-21 12:10   ` Thomas Haller
2023-11-21 12:39     ` Phil Sutter
2023-11-21 12:58       ` Thomas Haller
2023-11-21 13:40         ` Phil Sutter
2023-11-21 14:35           ` Thomas Haller
2023-11-21 15:19             ` Phil Sutter
2023-11-21 12:45     ` Pablo Neira Ayuso
     [not found]       ` <20231121132331.3401846-1-thaller@redhat.com>
2023-11-22 10:36         ` [PATCH nft v3 " Pablo Neira Ayuso
2023-11-22 10:44           ` Thomas Haller
2023-11-22 11:22             ` Pablo Neira Ayuso
2023-11-22 12:16               ` Thomas Haller
2023-11-22 12:32                 ` Pablo Neira Ayuso

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ZVgjLFGvHqoXXvjd@orbyte.nwl.cc \
    --to=phil@nwl.cc \
    --cc=netfilter-devel@vger.kernel.org \
    --cc=thaller@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).