]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
test: avoid FP in chroot-credentials.sh for different group list order
authorBernhard Voelker <mail@bernhard-voelker.de>
Sat, 20 Oct 2018 00:00:11 +0000 (02:00 +0200)
committerBernhard Voelker <mail@bernhard-voelker.de>
Sun, 21 Oct 2018 12:55:51 +0000 (14:55 +0200)
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 (num_sort): Add function to sort
group lists, and use it in the test cases which test multiple groups.

tests/misc/chroot-credentials.sh

index 89d68451efa6b791be460e30311be7ed1373fc15..0c156820e25c012f0fd55a8f4f2d181340194640 100755 (executable)
@@ -61,6 +61,9 @@ if ! test "$HAVE_SETGROUPS"; then
   Exit $fail
 fi
 
+# Change all whitespaces to newlines, then sort the input.
+# Use for tests with more groups in 'id' output.
+num_sort() { tr -s ' ' '\n' | sort -n; }
 
 # Verify that there are no additional groups.
 id_G_after_chroot=$(
@@ -70,12 +73,12 @@ id_G_after_chroot=$(
 test "$id_G_after_chroot" = $NON_ROOT_GID || fail=1
 
 # 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
+test "$(chroot --userspec=$NON_ROOT_USERNAME / id -G | num_sort)" = \
+     "$(id -G $NON_ROOT_USERNAME | num_sort)" || fail=1
 
 # Ditto with trailing : on the user name.
-test "$(chroot --userspec=$NON_ROOT_USERNAME: / id -G)" = \
-     "$(id -G $NON_ROOT_USERNAME)" || fail=1
+test "$(chroot --userspec=$NON_ROOT_USERNAME: / id -G | num_sort)" = \
+     "$(id -G $NON_ROOT_USERNAME | num_sort)" || fail=1
 
 # Verify that when specifying only the user and clearing supplemental groups
 # that we only get the primary group
@@ -83,8 +86,8 @@ test "$(chroot --userspec=$NON_ROOT_USERNAME --groups='' / id -G)" = \
      $NON_ROOT_GID || fail=1
 
 # Verify that when specifying only the UID we get all their groups
-test "$(chroot --userspec=$NON_ROOT_UID / id -G)" = \
-     "$(id -G $NON_ROOT_USERNAME)" || fail=1
+test "$(chroot --userspec=$NON_ROOT_UID / id -G | num_sort)" = \
+     "$(id -G $NON_ROOT_USERNAME | num_sort)" || fail=1
 
 # Verify that when specifying only the user and clearing supplemental groups
 # that we only get the primary group. Note this variant with prepended '+'