[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH] test: avoid FP in chroot-credentials.sh for different group
From: |
Jim Meyering |
Subject: |
Re: [PATCH] test: avoid FP in chroot-credentials.sh for different group list order |
Date: |
Sat, 20 Oct 2018 09:32:38 +0000 |
On Sat, Oct 20, 2018 at 12:04 AM Bernhard Voelker
<address@hidden> wrote:
>
> On my openSUSE:Tumbleweed system, I get a false positive test failure
> in the above 'check-root' test because the group lists inside and
> outside the chroot have a different order:
>
> ++ chroot --userspec=berny / id -G
> ++ id -G berny
> + test '100 454 457 480 492' = '100 480 492 457 454'
> + fail=1
>
> * tests/misc/chroot-credentials.sh (numSort): Add function to sort
> group list files, and use it in the test cases which test multiple
> groups.
> ---
> tests/misc/chroot-credentials.sh | 30 ++++++++++++++++++++++++------
> 1 file changed, 24 insertions(+), 6 deletions(-)
>
> diff --git a/tests/misc/chroot-credentials.sh
> b/tests/misc/chroot-credentials.sh
> index 89d68451e..1e18ef70b 100755
> --- a/tests/misc/chroot-credentials.sh
> +++ b/tests/misc/chroot-credentials.sh
> @@ -69,13 +69,29 @@ id_G_after_chroot=$(
> )
> test "$id_G_after_chroot" = $NON_ROOT_GID || fail=1
>
> +# Sort whitespace-separated list of groups for all file arguments
> +# (and convert them to newline-delimited lists).
> +numSort()
> +{
> + for f in "$@"; do
> + tr ' ' '\n' < "$f" > "$f.x" \
> + && sort -no "$f" "$f.x" \
> + && rm -f "$f.x" \
> + || return 1
> + done
> +}
> +
> # Verify that when specifying only the user name we get all their groups
> -test "$(chroot --userspec=$NON_ROOT_USERNAME / id -G)" = \
> - "$(id -G $NON_ROOT_USERNAME)" || fail=1
Thanks, Bernie.
If you adjust your function to be:
num_sort() { tr -s ' ' '\n' |sort -n; }
then you can make less invasive changes like this:
test "$(chroot --userspec=$NON_ROOT_USERNAME / id -G|num_sort)" = \
"$(id -G $NON_ROOT_USERNAME|num_sort)" || fail=1