coreutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] test: avoid FP in chroot-credentials.sh for different group list


From: Bernhard Voelker
Subject: [PATCH] test: avoid FP in chroot-credentials.sh for different group list order
Date: Sat, 20 Oct 2018 02:03:01 +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 (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
+id -G $NON_ROOT_USERNAME > out1 || fail=1
+chroot --userspec=$NON_ROOT_USERNAME / id -G > out2 || fail=1
+numSort out1 out2 || framework_failure_
+compare out1 out2 || fail=1
 
 # Ditto with trailing : on the user name.
-test "$(chroot --userspec=$NON_ROOT_USERNAME: / id -G)" = \
-     "$(id -G $NON_ROOT_USERNAME)" || fail=1
+id -G $NON_ROOT_USERNAME > out1 || fail=1
+chroot --userspec=$NON_ROOT_USERNAME: / id -G > out2 || fail=1
+numSort out1 out2 || framework_failure_
+compare out1 out2 || fail=1
 
 # Verify that when specifying only the user and clearing supplemental groups
 # that we only get the primary group
@@ -83,8 +99,10 @@ 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
+id -G $NON_ROOT_USERNAME > out1 || fail=1
+chroot --userspec=$NON_ROOT_UID / id -G  > out2 || fail=1
+numSort out1 out2 || framework_failure_
+compare out1 out2 || 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 '+'
-- 
2.19.1




reply via email to

[Prev in Thread] Current Thread [Next in Thread]