]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
tests: use predetermined NON_ROOT_GID
authorPádraig Brady <P@draigBrady.com>
Thu, 26 Jun 2014 11:41:01 +0000 (12:41 +0100)
committerPádraig Brady <P@draigBrady.com>
Thu, 26 Jun 2014 14:30:41 +0000 (15:30 +0100)
* HACKING: GID is more useful in tests than group name, so rename
input param from NON_ROOT_GROUP to NON_ROOT_GID to make it obvious
that only a group ID is now acceptable, thus allowing GID lookups
to be avoided throughout the tests.
* init.cfg (require_root_): Likewise.
* tests/misc/truncate-owned-by-other.sh: Avoid looking up the GID.
* tests/touch/now-owned-by-other.sh: Likewise.
* tests/misc/chroot-credentials.sh: Likewise.  Also fix an instance
of comparison against NON_ROOT_GROUP which would have given a false
failure if a non numeric value was passed in.
* tests/id/setgid.sh: Use previously looked up gid as a more
accurate base for the subsequent adjustment, and move
the uid lookup within chroot, rather than having the overhead
of a separate `id` invocation.

HACKING
init.cfg
tests/id/setgid.sh
tests/misc/chroot-credentials.sh
tests/misc/truncate-owned-by-other.sh
tests/touch/now-owned-by-other.sh

diff --git a/HACKING b/HACKING
index 0b0c6d698050614c40d7780419dfc6ae64cc5cc3..393a6236f28c1825615f3a944d1637ba6f16b549 100644 (file)
--- a/HACKING
+++ b/HACKING
@@ -453,7 +453,7 @@ Variables that are significant for tests with their default values are:
   RUN_VERY_EXPENSIVE_TESTS=no
   SHELL=/bin/sh
   NON_ROOT_USERNAME=nobody
-  NON_ROOT_GROUP=$(id -g $NON_ROOT_USERNAME)
+  NON_ROOT_GID=$(id -g $NON_ROOT_USERNAME)
   COREUTILS_GROUPS=$(id -G)
 
 There are hundreds of tests in the tests/ directories.  You can use
index e225bd6d635f2f9565d9dcf5cff6ace11a4589aa..725ee1213faa18ad7d6a2c95d4702c0c07b1f72b 100644 (file)
--- a/init.cfg
+++ b/init.cfg
@@ -413,7 +413,7 @@ require_root_()
 {
   uid_is_privileged_ || skip_ "must be run as root"
   NON_ROOT_USERNAME=${NON_ROOT_USERNAME=nobody}
-  NON_ROOT_GROUP=${NON_ROOT_GROUP=$(id -g $NON_ROOT_USERNAME)}
+  NON_ROOT_GID=${NON_ROOT_GID=$(id -g $NON_ROOT_USERNAME)}
 
   # When the current test invokes chroot, call nonroot_has_perm_
   # to check for a common problem.
index 0664c47a2d9f62e135125e85b09d3a473e398838..6d9d74f43e3b456573ca28e9bec7205b65f6bfed 100755 (executable)
 print_ver_ id
 require_root_
 
-u=$(id -u $NON_ROOT_USERNAME) || framework_failure_
-g=$u
-
-# Construct a different group number.
-gp1=$(expr $g + 1)
+# Construct a different group number
+gp1=$(expr $NON_ROOT_GID + 1)
 
 echo $gp1 > exp || framework_failure_
 
-# With coreutils-8.16 and earlier, id -G would print both: $gp1 $g
-chroot --user=+$u:+$gp1 --groups='' / env PATH="$PATH" \
+# With coreutils-8.16 and earlier, id -G would print both:
+#  $gp1 $NON_ROOT_GID
+chroot --user=$NON_ROOT_USERNAME:+$gp1 --groups='' / env PATH="$PATH" \
   id -G > out || fail=1
-compare exp out || { cat out; fail=1; }
+compare exp out || fail=1
 
-# With coreutils-8.22 and earlier, id would erroneously print groups=$g
-chroot --user=+$u:+$gp1 --groups='' / env PATH="$PATH" \
+# With coreutils-8.22 and earlier, id would erroneously print
+#  groups=$NON_ROOT_GID
+chroot --user=$NON_ROOT_USERNAME:+$gp1 --groups='' / env PATH="$PATH" \
   id > out || fail=1
 grep -F "groups=$gp1" out || { cat out; fail=1; }
 
index d50704cccab24f84649053a0ca306804f6ad4b73..b06e8b7f098825d33ee7d86f756d49534375dd4a 100755 (executable)
@@ -29,7 +29,7 @@ root=$(id -nu 0) || skip_ "Couldn't look up root username"
 
 # verify numeric IDs looked up similarly to names
 NON_ROOT_UID=$(id -u $NON_ROOT_USERNAME)
-NON_ROOT_GID=$(id -g $NON_ROOT_USERNAME)
+NON_ROOT_GROUP=$NON_ROOT_GID # Used where we want name lookups to occur
 
 # "uid:" is supported (unlike chown etc.) since we treat it like "uid"
 chroot --userspec=$NON_ROOT_UID: / true || fail=1
@@ -64,7 +64,7 @@ id_G_after_chroot=$(
   chroot --userspec=$NON_ROOT_USERNAME:$NON_ROOT_GROUP \
     --groups=$NON_ROOT_GROUP / id -G
 )
-test "$id_G_after_chroot" = $NON_ROOT_GROUP || fail=1
+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)" = \
@@ -77,7 +77,7 @@ test "$(chroot --userspec=$NON_ROOT_USERNAME: / id -G)" = \
 # Verify that when specifying only the user and clearing supplemental groups
 # that we only get the primary group
 test "$(chroot --userspec=$NON_ROOT_USERNAME --groups='' / id -G)" = \
-     "$(id -g $NON_ROOT_USERNAME)" || fail=1
+     $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)" = \
@@ -88,7 +88,7 @@ test "$(chroot --userspec=$NON_ROOT_UID / id -G)" = \
 # results in no lookups in the name database which could be useful depending
 # on your chroot setup.
 test "$(chroot --userspec=+$NON_ROOT_UID:+$NON_ROOT_GID --groups='' / id -G)" =\
-     "$(id -g $NON_ROOT_USERNAME)" || fail=1
+     $NON_ROOT_GID || fail=1
 
 # Verify that when specifying only a group we get the current user ID
 test "$(chroot --userspec=:$NON_ROOT_GROUP / id -u)" = "$(id -u)" \
index e93b7f13604afd6d48239757684c1ec9ed9031a8..e70badb6b72a25c03045b6ad2b16053ca8a8d535 100755 (executable)
@@ -21,11 +21,9 @@ print_ver_ truncate
 
 require_root_
 
-group_num=$(id -g $NON_ROOT_USERNAME)
-
 # Create a file owned by root, and writable by $NON_ROOT_USERNAME.
 echo > root-owned || framework_failure_
-chgrp +$group_num . root-owned || framework_failure_
+chgrp +$NON_ROOT_GID . root-owned || framework_failure_
 chmod g+w root-owned
 
 # Ensure that the current directory is searchable by $NON_ROOT_USERNAME.
index f5eeda6040c7e0ef9d3ae061700bd9bb54cb8228..d01097edb90fdbc48aab238e0ef60e95cbdfa1ad 100755 (executable)
 print_ver_ touch
 require_root_
 
-group_num=$(id -g $NON_ROOT_USERNAME)
-
 # Create a file owned by root, and writable by $NON_ROOT_USERNAME.
 echo > root-owned || framework_failure_
-chgrp +$group_num . root-owned || framework_failure_
+chgrp +$NON_ROOT_GID . root-owned || framework_failure_
 chmod g+w root-owned
 
 # Ensure that the current directory is searchable by $NON_ROOT_USERNAME.