coreutils
[Top][All Lists]
Advanced

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

[PATCH] maint: use predetermined NON_ROOT_GROUP in tests


From: Pádraig Brady
Subject: [PATCH] maint: use predetermined NON_ROOT_GROUP in tests
Date: Thu, 26 Jun 2014 12:47:39 +0100

* tests/misc/chroot-credentials.sh: Avoid gid lookup.
* tests/misc/truncate-owned-by-other.sh: Likewise.
* tests/touch/now-owned-by-other.sh: Likewise.
* tests/id/setgid.sh: Use previously looked up gid as a more
accurate base for the subseuqent adjustment, and move
the uid lookup within chroot, rather than having the overhead
of a separate `id` invocation.
---
 tests/id/setgid.sh                    |    7 +++----
 tests/misc/chroot-credentials.sh      |    6 +++---
 tests/misc/truncate-owned-by-other.sh |    4 +---
 tests/touch/now-owned-by-other.sh     |    4 +---
 4 files changed, 8 insertions(+), 13 deletions(-)

diff --git a/tests/id/setgid.sh b/tests/id/setgid.sh
index 0664c47..ce8f83a 100755
--- a/tests/id/setgid.sh
+++ b/tests/id/setgid.sh
@@ -20,8 +20,7 @@
 print_ver_ id
 require_root_
 
-u=$(id -u $NON_ROOT_USERNAME) || framework_failure_
-g=$u
+g=$NON_ROOT_GROUP
 
 # Construct a different group number.
 gp1=$(expr $g + 1)
@@ -29,12 +28,12 @@ gp1=$(expr $g + 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" \
+chroot --user=$NON_ROOT_USERNAME:+$gp1 --groups='' / env PATH="$PATH" \
   id -G > out || fail=1
 compare exp out || { cat out; fail=1; }
 
 # With coreutils-8.22 and earlier, id would erroneously print groups=$g
-chroot --user=+$u:+$gp1 --groups='' / env PATH="$PATH" \
+chroot --user=$NON_ROOT_USERNAME:+$gp1 --groups='' / env PATH="$PATH" \
   id > out || fail=1
 grep -F "groups=$gp1" out || { cat out; fail=1; }
 
diff --git a/tests/misc/chroot-credentials.sh b/tests/misc/chroot-credentials.sh
index d50704c..dd08b5c 100755
--- a/tests/misc/chroot-credentials.sh
+++ b/tests/misc/chroot-credentials.sh
@@ -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_GID=$NON_ROOT_GROUP
 
 # "uid:" is supported (unlike chown etc.) since we treat it like "uid"
 chroot --userspec=$NON_ROOT_UID: / true || fail=1
@@ -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_GROUP || 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_GROUP || 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)" \
diff --git a/tests/misc/truncate-owned-by-other.sh 
b/tests/misc/truncate-owned-by-other.sh
index e93b7f1..e8db60b 100755
--- a/tests/misc/truncate-owned-by-other.sh
+++ b/tests/misc/truncate-owned-by-other.sh
@@ -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_GROUP . root-owned || framework_failure_
 chmod g+w root-owned
 
 # Ensure that the current directory is searchable by $NON_ROOT_USERNAME.
diff --git a/tests/touch/now-owned-by-other.sh 
b/tests/touch/now-owned-by-other.sh
index f5eeda6..2fd9ef6 100755
--- a/tests/touch/now-owned-by-other.sh
+++ b/tests/touch/now-owned-by-other.sh
@@ -20,11 +20,9 @@
 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_GROUP . root-owned || framework_failure_
 chmod g+w root-owned
 
 # Ensure that the current directory is searchable by $NON_ROOT_USERNAME.
-- 
1.7.7.6




reply via email to

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