chroot: don't set bogus user-ID or group-ID for --u=U: or --u=:G
[coreutils.git] / tests / chroot / credentials
blobb76edea7dbc64e055d955cbb27d68250bd3e0c38
1 #!/bin/sh
2 # Verify that the credentials are changed correctly.
4 # Copyright (C) 2009 Free Software Foundation, Inc.
6 # This program is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation, either version 3 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
20 if test "$VERBOSE" = yes; then
21 set -x
22 chroot --version
25 . $srcdir/test-lib.sh
27 require_root_
29 fail=0
31 # Verify that root credentials are kept.
32 test $(chroot / whoami) = root || fail=1
33 test "$(groups)" = "$(chroot / groups)" || fail=1
35 # Verify that credentials are changed correctly.
36 test "$(chroot --userspec=$NON_ROOT_USERNAME:$NON_ROOT_GROUP / whoami)" != root \
37 || fail=1
39 # Verify that there are no additional groups.
40 test "$(chroot --userspec=$NON_ROOT_USERNAME:$NON_ROOT_GROUP --groups= / id -nG)"\
41 = $NON_ROOT_GROUP || fail=1
43 # Verify that when specifying only the user name we get the current
44 # primary group ID.
45 test "$(chroot --userspec=$NON_ROOT_USERNAME / id -g)" = "$(id -g)" \
46 || fail=1
48 # Verify that when specifying only a group we get the current user ID
49 test "$(chroot --userspec=:$NON_ROOT_GROUP / id -u)" = "$(id -u)" \
50 || fail=1
52 Exit $fail