1272343Sngie# $NetBSD: t_id.sh,v 1.1 2012/03/17 16:33:14 jruoho Exp $ 2272343Sngie# 3272343Sngie# Copyright (c) 2007, 2008 The NetBSD Foundation, Inc. 4272343Sngie# All rights reserved. 5272343Sngie# 6272343Sngie# Redistribution and use in source and binary forms, with or without 7272343Sngie# modification, are permitted provided that the following conditions 8272343Sngie# are met: 9272343Sngie# 1. Redistributions of source code must retain the above copyright 10272343Sngie# notice, this list of conditions and the following disclaimer. 11272343Sngie# 2. Redistributions in binary form must reproduce the above copyright 12272343Sngie# notice, this list of conditions and the following disclaimer in the 13272343Sngie# documentation and/or other materials provided with the distribution. 14272343Sngie# 15272343Sngie# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 16272343Sngie# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 17272343Sngie# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 18272343Sngie# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 19272343Sngie# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 20272343Sngie# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 21272343Sngie# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 22272343Sngie# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 23272343Sngie# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 24272343Sngie# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 25272343Sngie# POSSIBILITY OF SUCH DAMAGE. 26272343Sngie# 27272343Sngie 28272343Sngiecreate_run_id() { 29272343Sngie cat >run_id.sh <<EOF 30272343Sngie#! /bin/sh 31272343Sngie[ -f ./id ] || ln -s $(atf_get_srcdir)/h_id ./id 32272343Sngie./id "\${@}" 33272343SngieEOF 34272343Sngie chmod +x run_id.sh 35272343Sngie} 36272343Sngie 37272343Sngieatf_test_case default 38272343Sngiedefault_head() { 39272343Sngie atf_set "descr" "Checks that the output without options is correct" 40272343Sngie} 41272343Sngiedefault_body() { 42272343Sngie create_run_id 43272343Sngie 44272343Sngie echo "uid=100(test) gid=100(users) groups=100(users),0(wheel)" >expout 45272343Sngie atf_check -s eq:0 -o file:expout -e empty ./run_id.sh 46272343Sngie atf_check -s eq:0 -o file:expout -e empty ./run_id.sh 100 47272343Sngie atf_check -s eq:0 -o file:expout -e empty ./run_id.sh test 48272343Sngie 49272343Sngie echo "uid=0(root) gid=0(wheel) groups=0(wheel)" >expout 50272343Sngie atf_check -s eq:0 -o file:expout -e empty ./run_id.sh 0 51272343Sngie atf_check -s eq:0 -o file:expout -e empty ./run_id.sh root 52272343Sngie 53272343Sngie export LIBFAKE_EGID_ROOT=1 LIBFAKE_EUID_ROOT=1 54272343Sngie echo "uid=100(test) gid=100(users) euid=0(root) egid=0(wheel) groups=100(users),0(wheel)" >expout 55272343Sngie atf_check -s eq:0 -o file:expout -e empty ./run_id.sh 56272343Sngie unset LIBFAKE_EGID_ROOT LIBFAKE_EUID_ROOT 57272343Sngie 58272343Sngie echo 'id: nonexistent: No such user' >experr 59272343Sngie atf_check -s eq:1 -o empty -e file:experr ./run_id.sh nonexistent 60272343Sngie 61272343Sngie atf_check -s eq:1 -o empty -e save:stderr ./run_id.sh root nonexistent 62272343Sngie atf_check -s eq:0 -o ignore -e empty grep ^usage: stderr 63272343Sngie} 64272343Sngie 65272343Sngieatf_test_case primaries 66272343Sngieprimaries_head() { 67272343Sngie atf_set "descr" "Checks that giving multiple primaries" \ 68272343Sngie "simultaneously provides an error" 69272343Sngie} 70272343Sngieprimaries_body() { 71272343Sngie create_run_id 72272343Sngie 73272343Sngie for p1 in -G -g -p -u; do 74272343Sngie for p2 in -G -g -p -u; do 75272343Sngie if [ ${p1} != ${p2} ]; then 76272343Sngie atf_check -s eq:1 -o empty -e save:stderr \ 77272343Sngie ./run_id.sh ${p1} ${p2} 78272343Sngie atf_check -s eq:0 -o ignore -e empty \ 79272343Sngie grep ^usage: stderr 80272343Sngie fi 81272343Sngie done 82272343Sngie done 83272343Sngie} 84272343Sngie 85272343Sngieatf_test_case Gflag 86272343SngieGflag_head() { 87272343Sngie atf_set "descr" "Checks that the -G primary flag works" 88272343Sngie} 89272343SngieGflag_body() { 90272343Sngie create_run_id 91272343Sngie 92272343Sngie echo "100 0" >expout 93272343Sngie atf_check -s eq:0 -o file:expout -e empty ./run_id.sh -G 94272343Sngie atf_check -s eq:0 -o file:expout -e empty ./run_id.sh -G 100 95272343Sngie atf_check -s eq:0 -o file:expout -e empty ./run_id.sh -G test 96272343Sngie 97272343Sngie echo "users wheel" >expout 98272343Sngie atf_check -s eq:0 -o file:expout -e empty ./run_id.sh -G -n 99272343Sngie atf_check -s eq:0 -o file:expout -e empty ./run_id.sh -G -n 100 100272343Sngie atf_check -s eq:0 -o file:expout -e empty ./run_id.sh -G -n test 101272343Sngie 102272343Sngie echo "0" >expout 103272343Sngie atf_check -s eq:0 -o file:expout -e empty ./run_id.sh -G 0 104272343Sngie atf_check -s eq:0 -o file:expout -e empty ./run_id.sh -G root 105272343Sngie 106272343Sngie echo "wheel" >expout 107272343Sngie atf_check -s eq:0 -o file:expout -e empty ./run_id.sh -G -n 0 108272343Sngie atf_check -s eq:0 -o file:expout -e empty ./run_id.sh -G -n root 109272343Sngie 110272343Sngie echo 'id: nonexistent: No such user' >experr 111272343Sngie atf_check -s eq:1 -o empty -e file:experr ./run_id.sh -G nonexistent 112272343Sngie 113272343Sngie atf_check -s eq:1 -o empty -e save:stderr ./run_id.sh -G root nonexistent 114272343Sngie atf_check -s eq:0 -o ignore -e empty grep ^usage: stderr 115272343Sngie} 116272343Sngie 117272343Sngieatf_test_case gflag 118272343Sngiegflag_head() { 119272343Sngie atf_set "descr" "Checks that the -g primary flag works" 120272343Sngie} 121272343Sngiegflag_body() { 122272343Sngie create_run_id 123272343Sngie 124272343Sngie echo "100" >expout 125272343Sngie atf_check -s eq:0 -o file:expout -e empty ./run_id.sh -g 126272343Sngie atf_check -s eq:0 -o file:expout -e empty ./run_id.sh -g 100 127272343Sngie atf_check -s eq:0 -o file:expout -e empty ./run_id.sh -g test 128272343Sngie 129272343Sngie echo "users" >expout 130272343Sngie atf_check -s eq:0 -o file:expout -e empty ./run_id.sh -g -n 131272343Sngie atf_check -s eq:0 -o file:expout -e empty ./run_id.sh -g -n 100 132272343Sngie atf_check -s eq:0 -o file:expout -e empty ./run_id.sh -g -n test 133272343Sngie 134272343Sngie echo "0" >expout 135272343Sngie atf_check -s eq:0 -o file:expout -e empty ./run_id.sh -g 0 136272343Sngie atf_check -s eq:0 -o file:expout -e empty ./run_id.sh -g root 137272343Sngie 138272343Sngie echo "wheel" >expout 139272343Sngie atf_check -s eq:0 -o file:expout -e empty ./run_id.sh -g -n 0 140272343Sngie atf_check -s eq:0 -o file:expout -e empty ./run_id.sh -g -n root 141272343Sngie 142272343Sngie echo "100" >expout 143272343Sngie atf_check -s eq:0 -o file:expout -e empty ./run_id.sh -g -r 144272343Sngie 145272343Sngie echo "users" >expout 146272343Sngie atf_check -s eq:0 -o file:expout -e empty ./run_id.sh -g -r -n 147272343Sngie 148272343Sngie echo "100" >expout 149272343Sngie atf_check -s eq:0 -o file:expout -e empty ./run_id.sh -g -r 100 150272343Sngie atf_check -s eq:0 -o file:expout -e empty ./run_id.sh -g -r test 151272343Sngie 152272343Sngie echo "users" >expout 153272343Sngie atf_check -s eq:0 -o file:expout -e empty ./run_id.sh -g -r -n 100 154272343Sngie atf_check -s eq:0 -o file:expout -e empty ./run_id.sh -g -r -n test 155272343Sngie 156272343Sngie export LIBFAKE_EGID_ROOT=1 LIBFAKE_EUID_ROOT=1 157272343Sngie 158272343Sngie echo "0" >expout 159272343Sngie atf_check -s eq:0 -o file:expout -e empty ./run_id.sh -g 160272343Sngie 161272343Sngie echo "wheel" >expout 162272343Sngie atf_check -s eq:0 -o file:expout -e empty ./run_id.sh -g -n 163272343Sngie 164272343Sngie echo "100" >expout 165272343Sngie atf_check -s eq:0 -o file:expout -e empty ./run_id.sh -g -r 166272343Sngie 167272343Sngie echo "users" >expout 168272343Sngie atf_check -s eq:0 -o file:expout -e empty ./run_id.sh -g -r -n 169272343Sngie 170272343Sngie echo "100" >expout 171272343Sngie atf_check -s eq:0 -o file:expout -e empty ./run_id.sh -g -r 100 172272343Sngie atf_check -s eq:0 -o file:expout -e empty ./run_id.sh -g -r test 173272343Sngie 174272343Sngie echo "users" >expout 175272343Sngie atf_check -s eq:0 -o file:expout -e empty ./run_id.sh -g -r -n 100 176272343Sngie atf_check -s eq:0 -o file:expout -e empty ./run_id.sh -g -r -n test 177272343Sngie 178272343Sngie unset LIBFAKE_EGID_ROOT LIBFAKE_EUID_ROOT 179272343Sngie 180272343Sngie echo 'id: nonexistent: No such user' >experr 181272343Sngie atf_check -s eq:1 -o empty -e file:experr ./run_id.sh -g nonexistent 182272343Sngie 183272343Sngie atf_check -s eq:1 -o empty -e save:stderr ./run_id.sh -g root nonexistent 184272343Sngie atf_check -s eq:0 -o ignore -e empty grep ^usage: stderr 185272343Sngie} 186272343Sngie 187272343Sngieatf_test_case pflag 188272343Sngiepflag_head() { 189272343Sngie atf_set "descr" "Checks that the -p primary flag works" 190272343Sngie} 191272343Sngiepflag_body() { 192272343Sngie create_run_id 193272343Sngie 194272343Sngie cat >expout <<EOF 195272343Sngieuid test 196272343Sngiegroups users wheel 197272343SngieEOF 198272343Sngie atf_check -s eq:0 -o file:expout -e empty ./run_id.sh -p 199272343Sngie atf_check -s eq:0 -o file:expout -e empty ./run_id.sh -p 100 200272343Sngie atf_check -s eq:0 -o file:expout -e empty ./run_id.sh -p test 201272343Sngie 202272343Sngie cat >expout <<EOF 203272343Sngieuid root 204272343Sngiegroups wheel 205272343SngieEOF 206272343Sngie atf_check -s eq:0 -o file:expout -e empty ./run_id.sh -p 0 207272343Sngie atf_check -s eq:0 -o file:expout -e empty ./run_id.sh -p root 208272343Sngie 209272343Sngie export LIBFAKE_EGID_ROOT=1 LIBFAKE_EUID_ROOT=1 210272343Sngie cat >expout <<EOF 211272343Sngieuid test 212272343Sngieeuid root 213272343Sngiergid users 214272343Sngiegroups users wheel 215272343SngieEOF 216272343Sngie atf_check -s eq:0 -o file:expout -e empty ./run_id.sh -p 217272343Sngie unset LIBFAKE_EGID_ROOT LIBFAKE_EUID_ROOT 218272343Sngie 219272343Sngie echo 'id: nonexistent: No such user' >experr 220272343Sngie atf_check -s eq:1 -o empty -e file:experr ./run_id.sh -p nonexistent 221272343Sngie 222272343Sngie atf_check -s eq:1 -o empty -e save:stderr ./run_id.sh -p root nonexistent 223272343Sngie atf_check -s eq:0 -o ignore -e empty grep ^usage: stderr 224272343Sngie} 225272343Sngie 226272343Sngieatf_test_case uflag 227272343Sngieuflag_head() { 228272343Sngie atf_set "descr" "Checks that the -u primary flag works" 229272343Sngie} 230272343Sngieuflag_body() { 231272343Sngie create_run_id 232272343Sngie 233272343Sngie echo "100" >expout 234272343Sngie atf_check -s eq:0 -o file:expout -e empty ./run_id.sh -u 235272343Sngie atf_check -s eq:0 -o file:expout -e empty ./run_id.sh -u 100 236272343Sngie atf_check -s eq:0 -o file:expout -e empty ./run_id.sh -u test 237272343Sngie 238272343Sngie echo "test" >expout 239272343Sngie atf_check -s eq:0 -o file:expout -e empty ./run_id.sh -u -n 240272343Sngie atf_check -s eq:0 -o file:expout -e empty ./run_id.sh -u -n 100 241272343Sngie atf_check -s eq:0 -o file:expout -e empty ./run_id.sh -u -n test 242272343Sngie 243272343Sngie echo "0" >expout 244272343Sngie atf_check -s eq:0 -o file:expout -e empty ./run_id.sh -u 0 245272343Sngie atf_check -s eq:0 -o file:expout -e empty ./run_id.sh -u root 246272343Sngie 247272343Sngie echo "root" >expout 248272343Sngie atf_check -s eq:0 -o file:expout -e empty ./run_id.sh -u -n 0 249272343Sngie atf_check -s eq:0 -o file:expout -e empty ./run_id.sh -u -n root 250272343Sngie 251272343Sngie echo "100" >expout 252272343Sngie atf_check -s eq:0 -o file:expout -e empty ./run_id.sh -u -r 253272343Sngie 254272343Sngie echo "test" >expout 255272343Sngie atf_check -s eq:0 -o file:expout -e empty ./run_id.sh -u -r -n 256272343Sngie 257272343Sngie echo "100" >expout 258272343Sngie atf_check -s eq:0 -o file:expout -e empty ./run_id.sh -u -r 100 259272343Sngie atf_check -s eq:0 -o file:expout -e empty ./run_id.sh -u -r test 260272343Sngie 261272343Sngie echo "test" >expout 262272343Sngie atf_check -s eq:0 -o file:expout -e empty ./run_id.sh -u -r -n 100 263272343Sngie atf_check -s eq:0 -o file:expout -e empty ./run_id.sh -u -r -n test 264272343Sngie 265272343Sngie export LIBFAKE_EGID_ROOT=1 LIBFAKE_EUID_ROOT=1 266272343Sngie 267272343Sngie echo "0" >expout 268272343Sngie atf_check -s eq:0 -o file:expout -e empty ./run_id.sh -u 269272343Sngie 270272343Sngie echo "root" >expout 271272343Sngie atf_check -s eq:0 -o file:expout -e empty ./run_id.sh -u -n 272272343Sngie 273272343Sngie echo "100" >expout 274272343Sngie atf_check -s eq:0 -o file:expout -e empty ./run_id.sh -u -r 275272343Sngie 276272343Sngie echo "test" >expout 277272343Sngie atf_check -s eq:0 -o file:expout -e empty ./run_id.sh -u -r -n 278272343Sngie 279272343Sngie echo "100" >expout 280272343Sngie atf_check -s eq:0 -o file:expout -e empty ./run_id.sh -u -r 100 281272343Sngie atf_check -s eq:0 -o file:expout -e empty ./run_id.sh -u -r test 282272343Sngie 283272343Sngie echo "test" >expout 284272343Sngie atf_check -s eq:0 -o file:expout -e empty ./run_id.sh -u -r -n 100 285272343Sngie atf_check -s eq:0 -o file:expout -e empty ./run_id.sh -u -r -n test 286272343Sngie 287272343Sngie unset LIBFAKE_EGID_ROOT LIBFAKE_EUID_ROOT 288272343Sngie 289272343Sngie echo 'id: nonexistent: No such user' >experr 290272343Sngie atf_check -s eq:1 -o empty -e file:experr ./run_id.sh -u nonexistent 291272343Sngie 292272343Sngie atf_check -s eq:1 -o empty -e save:stderr \ 293272343Sngie ./run_id.sh -u root nonexistent 294272343Sngie atf_check -s eq:0 -o ignore -e empty grep ^usage: stderr 295272343Sngie} 296272343Sngie 297272343Sngieatf_init_test_cases() 298272343Sngie{ 299272343Sngie atf_add_test_case default 300272343Sngie atf_add_test_case primaries 301272343Sngie atf_add_test_case Gflag 302272343Sngie atf_add_test_case gflag 303272343Sngie atf_add_test_case pflag 304272343Sngie atf_add_test_case uflag 305272343Sngie} 306