1 # $NetBSD: t_id.sh,v 1.1 2012/03/17 16:33:14 jruoho Exp $
3 # Copyright (c) 2007, 2008 The NetBSD Foundation, Inc.
6 # Redistribution and use in source and binary forms, with or without
7 # modification, are permitted provided that the following conditions
9 # 1. Redistributions of source code must retain the above copyright
10 # notice, this list of conditions and the following disclaimer.
11 # 2. Redistributions in binary form must reproduce the above copyright
12 # notice, this list of conditions and the following disclaimer in the
13 # documentation and/or other materials provided with the distribution.
15 # THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
16 # ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
17 # TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
18 # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
19 # BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20 # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21 # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22 # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23 # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24 # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25 # POSSIBILITY OF SUCH DAMAGE.
31 [ -f ./id ] || ln -s $(atf_get_srcdir)/h_id ./id
39 atf_set
"descr" "Checks that the output without options is correct"
44 echo "uid=100(test) gid=100(users) groups=100(users),0(wheel)" >expout
45 atf_check
-s eq
:0 -o file:expout
-e empty .
/run_id.sh
46 atf_check
-s eq
:0 -o file:expout
-e empty .
/run_id.sh
100
47 atf_check
-s eq
:0 -o file:expout
-e empty .
/run_id.sh
test
49 echo "uid=0(root) gid=0(wheel) groups=0(wheel)" >expout
50 atf_check
-s eq
:0 -o file:expout
-e empty .
/run_id.sh
0
51 atf_check
-s eq
:0 -o file:expout
-e empty .
/run_id.sh root
53 export LIBFAKE_EGID_ROOT
=1 LIBFAKE_EUID_ROOT
=1
54 echo "uid=100(test) gid=100(users) euid=0(root) egid=0(wheel) groups=100(users),0(wheel)" >expout
55 atf_check
-s eq
:0 -o file:expout
-e empty .
/run_id.sh
56 unset LIBFAKE_EGID_ROOT LIBFAKE_EUID_ROOT
58 echo 'id: nonexistent: No such user' >experr
59 atf_check
-s eq
:1 -o empty
-e file:experr .
/run_id.sh nonexistent
61 atf_check
-s eq
:1 -o empty
-e save
:stderr .
/run_id.sh root nonexistent
62 atf_check
-s eq
:0 -o ignore
-e empty
grep ^usage
: stderr
65 atf_test_case primaries
67 atf_set
"descr" "Checks that giving multiple primaries" \
68 "simultaneously provides an error"
73 for p1
in -G -g -p -u; do
74 for p2
in -G -g -p -u; do
75 if [ ${p1} != ${p2} ]; then
76 atf_check
-s eq
:1 -o empty
-e save
:stderr \
77 .
/run_id.sh
${p1} ${p2}
78 atf_check
-s eq
:0 -o ignore
-e empty \
87 atf_set
"descr" "Checks that the -G primary flag works"
93 atf_check
-s eq
:0 -o file:expout
-e empty .
/run_id.sh
-G
94 atf_check
-s eq
:0 -o file:expout
-e empty .
/run_id.sh
-G 100
95 atf_check
-s eq
:0 -o file:expout
-e empty .
/run_id.sh
-G test
97 echo "users wheel" >expout
98 atf_check
-s eq
:0 -o file:expout
-e empty .
/run_id.sh
-G -n
99 atf_check
-s eq
:0 -o file:expout
-e empty .
/run_id.sh
-G -n 100
100 atf_check
-s eq
:0 -o file:expout
-e empty .
/run_id.sh
-G -n test
103 atf_check
-s eq
:0 -o file:expout
-e empty .
/run_id.sh
-G 0
104 atf_check
-s eq
:0 -o file:expout
-e empty .
/run_id.sh
-G root
107 atf_check
-s eq
:0 -o file:expout
-e empty .
/run_id.sh
-G -n 0
108 atf_check
-s eq
:0 -o file:expout
-e empty .
/run_id.sh
-G -n root
110 echo 'id: nonexistent: No such user' >experr
111 atf_check
-s eq
:1 -o empty
-e file:experr .
/run_id.sh
-G nonexistent
113 atf_check
-s eq
:1 -o empty
-e save
:stderr .
/run_id.sh
-G root nonexistent
114 atf_check
-s eq
:0 -o ignore
-e empty
grep ^usage
: stderr
119 atf_set
"descr" "Checks that the -g primary flag works"
125 atf_check
-s eq
:0 -o file:expout
-e empty .
/run_id.sh
-g
126 atf_check
-s eq
:0 -o file:expout
-e empty .
/run_id.sh
-g 100
127 atf_check
-s eq
:0 -o file:expout
-e empty .
/run_id.sh
-g test
130 atf_check
-s eq
:0 -o file:expout
-e empty .
/run_id.sh
-g -n
131 atf_check
-s eq
:0 -o file:expout
-e empty .
/run_id.sh
-g -n 100
132 atf_check
-s eq
:0 -o file:expout
-e empty .
/run_id.sh
-g -n test
135 atf_check
-s eq
:0 -o file:expout
-e empty .
/run_id.sh
-g 0
136 atf_check
-s eq
:0 -o file:expout
-e empty .
/run_id.sh
-g root
139 atf_check
-s eq
:0 -o file:expout
-e empty .
/run_id.sh
-g -n 0
140 atf_check
-s eq
:0 -o file:expout
-e empty .
/run_id.sh
-g -n root
143 atf_check
-s eq
:0 -o file:expout
-e empty .
/run_id.sh
-g -r
146 atf_check
-s eq
:0 -o file:expout
-e empty .
/run_id.sh
-g -r -n
149 atf_check
-s eq
:0 -o file:expout
-e empty .
/run_id.sh
-g -r 100
150 atf_check
-s eq
:0 -o file:expout
-e empty .
/run_id.sh
-g -r test
153 atf_check
-s eq
:0 -o file:expout
-e empty .
/run_id.sh
-g -r -n 100
154 atf_check
-s eq
:0 -o file:expout
-e empty .
/run_id.sh
-g -r -n test
156 export LIBFAKE_EGID_ROOT
=1 LIBFAKE_EUID_ROOT
=1
159 atf_check
-s eq
:0 -o file:expout
-e empty .
/run_id.sh
-g
162 atf_check
-s eq
:0 -o file:expout
-e empty .
/run_id.sh
-g -n
165 atf_check
-s eq
:0 -o file:expout
-e empty .
/run_id.sh
-g -r
168 atf_check
-s eq
:0 -o file:expout
-e empty .
/run_id.sh
-g -r -n
171 atf_check
-s eq
:0 -o file:expout
-e empty .
/run_id.sh
-g -r 100
172 atf_check
-s eq
:0 -o file:expout
-e empty .
/run_id.sh
-g -r test
175 atf_check
-s eq
:0 -o file:expout
-e empty .
/run_id.sh
-g -r -n 100
176 atf_check
-s eq
:0 -o file:expout
-e empty .
/run_id.sh
-g -r -n test
178 unset LIBFAKE_EGID_ROOT LIBFAKE_EUID_ROOT
180 echo 'id: nonexistent: No such user' >experr
181 atf_check
-s eq
:1 -o empty
-e file:experr .
/run_id.sh
-g nonexistent
183 atf_check
-s eq
:1 -o empty
-e save
:stderr .
/run_id.sh
-g root nonexistent
184 atf_check
-s eq
:0 -o ignore
-e empty
grep ^usage
: stderr
189 atf_set
"descr" "Checks that the -p primary flag works"
198 atf_check
-s eq
:0 -o file:expout
-e empty .
/run_id.sh
-p
199 atf_check
-s eq
:0 -o file:expout
-e empty .
/run_id.sh
-p 100
200 atf_check
-s eq
:0 -o file:expout
-e empty .
/run_id.sh
-p test
206 atf_check
-s eq
:0 -o file:expout
-e empty .
/run_id.sh
-p 0
207 atf_check
-s eq
:0 -o file:expout
-e empty .
/run_id.sh
-p root
209 export LIBFAKE_EGID_ROOT
=1 LIBFAKE_EUID_ROOT
=1
216 atf_check
-s eq
:0 -o file:expout
-e empty .
/run_id.sh
-p
217 unset LIBFAKE_EGID_ROOT LIBFAKE_EUID_ROOT
219 echo 'id: nonexistent: No such user' >experr
220 atf_check
-s eq
:1 -o empty
-e file:experr .
/run_id.sh
-p nonexistent
222 atf_check
-s eq
:1 -o empty
-e save
:stderr .
/run_id.sh
-p root nonexistent
223 atf_check
-s eq
:0 -o ignore
-e empty
grep ^usage
: stderr
228 atf_set
"descr" "Checks that the -u primary flag works"
234 atf_check
-s eq
:0 -o file:expout
-e empty .
/run_id.sh
-u
235 atf_check
-s eq
:0 -o file:expout
-e empty .
/run_id.sh
-u 100
236 atf_check
-s eq
:0 -o file:expout
-e empty .
/run_id.sh
-u test
239 atf_check
-s eq
:0 -o file:expout
-e empty .
/run_id.sh
-u -n
240 atf_check
-s eq
:0 -o file:expout
-e empty .
/run_id.sh
-u -n 100
241 atf_check
-s eq
:0 -o file:expout
-e empty .
/run_id.sh
-u -n test
244 atf_check
-s eq
:0 -o file:expout
-e empty .
/run_id.sh
-u 0
245 atf_check
-s eq
:0 -o file:expout
-e empty .
/run_id.sh
-u root
248 atf_check
-s eq
:0 -o file:expout
-e empty .
/run_id.sh
-u -n 0
249 atf_check
-s eq
:0 -o file:expout
-e empty .
/run_id.sh
-u -n root
252 atf_check
-s eq
:0 -o file:expout
-e empty .
/run_id.sh
-u -r
255 atf_check
-s eq
:0 -o file:expout
-e empty .
/run_id.sh
-u -r -n
258 atf_check
-s eq
:0 -o file:expout
-e empty .
/run_id.sh
-u -r 100
259 atf_check
-s eq
:0 -o file:expout
-e empty .
/run_id.sh
-u -r test
262 atf_check
-s eq
:0 -o file:expout
-e empty .
/run_id.sh
-u -r -n 100
263 atf_check
-s eq
:0 -o file:expout
-e empty .
/run_id.sh
-u -r -n test
265 export LIBFAKE_EGID_ROOT
=1 LIBFAKE_EUID_ROOT
=1
268 atf_check
-s eq
:0 -o file:expout
-e empty .
/run_id.sh
-u
271 atf_check
-s eq
:0 -o file:expout
-e empty .
/run_id.sh
-u -n
274 atf_check
-s eq
:0 -o file:expout
-e empty .
/run_id.sh
-u -r
277 atf_check
-s eq
:0 -o file:expout
-e empty .
/run_id.sh
-u -r -n
280 atf_check
-s eq
:0 -o file:expout
-e empty .
/run_id.sh
-u -r 100
281 atf_check
-s eq
:0 -o file:expout
-e empty .
/run_id.sh
-u -r test
284 atf_check
-s eq
:0 -o file:expout
-e empty .
/run_id.sh
-u -r -n 100
285 atf_check
-s eq
:0 -o file:expout
-e empty .
/run_id.sh
-u -r -n test
287 unset LIBFAKE_EGID_ROOT LIBFAKE_EUID_ROOT
289 echo 'id: nonexistent: No such user' >experr
290 atf_check
-s eq
:1 -o empty
-e file:experr .
/run_id.sh
-u nonexistent
292 atf_check
-s eq
:1 -o empty
-e save
:stderr \
293 .
/run_id.sh
-u root nonexistent
294 atf_check
-s eq
:0 -o ignore
-e empty
grep ^usage
: stderr
297 atf_init_test_cases
()
299 atf_add_test_case default
300 atf_add_test_case primaries
301 atf_add_test_case Gflag
302 atf_add_test_case gflag
303 atf_add_test_case pflag
304 atf_add_test_case uflag