1*11be35a1SLionel Sambuc# $NetBSD: t_id.sh,v 1.1 2012/03/17 16:33:14 jruoho Exp $ 2*11be35a1SLionel Sambuc# 3*11be35a1SLionel Sambuc# Copyright (c) 2007, 2008 The NetBSD Foundation, Inc. 4*11be35a1SLionel Sambuc# All rights reserved. 5*11be35a1SLionel Sambuc# 6*11be35a1SLionel Sambuc# Redistribution and use in source and binary forms, with or without 7*11be35a1SLionel Sambuc# modification, are permitted provided that the following conditions 8*11be35a1SLionel Sambuc# are met: 9*11be35a1SLionel Sambuc# 1. Redistributions of source code must retain the above copyright 10*11be35a1SLionel Sambuc# notice, this list of conditions and the following disclaimer. 11*11be35a1SLionel Sambuc# 2. Redistributions in binary form must reproduce the above copyright 12*11be35a1SLionel Sambuc# notice, this list of conditions and the following disclaimer in the 13*11be35a1SLionel Sambuc# documentation and/or other materials provided with the distribution. 14*11be35a1SLionel Sambuc# 15*11be35a1SLionel Sambuc# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 16*11be35a1SLionel Sambuc# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 17*11be35a1SLionel Sambuc# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 18*11be35a1SLionel Sambuc# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 19*11be35a1SLionel Sambuc# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 20*11be35a1SLionel Sambuc# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 21*11be35a1SLionel Sambuc# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 22*11be35a1SLionel Sambuc# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 23*11be35a1SLionel Sambuc# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 24*11be35a1SLionel Sambuc# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 25*11be35a1SLionel Sambuc# POSSIBILITY OF SUCH DAMAGE. 26*11be35a1SLionel Sambuc# 27*11be35a1SLionel Sambuc 28*11be35a1SLionel Sambuccreate_run_id() { 29*11be35a1SLionel Sambuc cat >run_id.sh <<EOF 30*11be35a1SLionel Sambuc#! /bin/sh 31*11be35a1SLionel Sambuc[ -f ./id ] || ln -s $(atf_get_srcdir)/h_id ./id 32*11be35a1SLionel Sambuc./id "\${@}" 33*11be35a1SLionel SambucEOF 34*11be35a1SLionel Sambuc chmod +x run_id.sh 35*11be35a1SLionel Sambuc} 36*11be35a1SLionel Sambuc 37*11be35a1SLionel Sambucatf_test_case default 38*11be35a1SLionel Sambucdefault_head() { 39*11be35a1SLionel Sambuc atf_set "descr" "Checks that the output without options is correct" 40*11be35a1SLionel Sambuc} 41*11be35a1SLionel Sambucdefault_body() { 42*11be35a1SLionel Sambuc create_run_id 43*11be35a1SLionel Sambuc 44*11be35a1SLionel Sambuc echo "uid=100(test) gid=100(users) groups=100(users),0(wheel)" >expout 45*11be35a1SLionel Sambuc atf_check -s eq:0 -o file:expout -e empty ./run_id.sh 46*11be35a1SLionel Sambuc atf_check -s eq:0 -o file:expout -e empty ./run_id.sh 100 47*11be35a1SLionel Sambuc atf_check -s eq:0 -o file:expout -e empty ./run_id.sh test 48*11be35a1SLionel Sambuc 49*11be35a1SLionel Sambuc echo "uid=0(root) gid=0(wheel) groups=0(wheel)" >expout 50*11be35a1SLionel Sambuc atf_check -s eq:0 -o file:expout -e empty ./run_id.sh 0 51*11be35a1SLionel Sambuc atf_check -s eq:0 -o file:expout -e empty ./run_id.sh root 52*11be35a1SLionel Sambuc 53*11be35a1SLionel Sambuc export LIBFAKE_EGID_ROOT=1 LIBFAKE_EUID_ROOT=1 54*11be35a1SLionel Sambuc echo "uid=100(test) gid=100(users) euid=0(root) egid=0(wheel) groups=100(users),0(wheel)" >expout 55*11be35a1SLionel Sambuc atf_check -s eq:0 -o file:expout -e empty ./run_id.sh 56*11be35a1SLionel Sambuc unset LIBFAKE_EGID_ROOT LIBFAKE_EUID_ROOT 57*11be35a1SLionel Sambuc 58*11be35a1SLionel Sambuc echo 'id: nonexistent: No such user' >experr 59*11be35a1SLionel Sambuc atf_check -s eq:1 -o empty -e file:experr ./run_id.sh nonexistent 60*11be35a1SLionel Sambuc 61*11be35a1SLionel Sambuc atf_check -s eq:1 -o empty -e save:stderr ./run_id.sh root nonexistent 62*11be35a1SLionel Sambuc atf_check -s eq:0 -o ignore -e empty grep ^usage: stderr 63*11be35a1SLionel Sambuc} 64*11be35a1SLionel Sambuc 65*11be35a1SLionel Sambucatf_test_case primaries 66*11be35a1SLionel Sambucprimaries_head() { 67*11be35a1SLionel Sambuc atf_set "descr" "Checks that giving multiple primaries" \ 68*11be35a1SLionel Sambuc "simultaneously provides an error" 69*11be35a1SLionel Sambuc} 70*11be35a1SLionel Sambucprimaries_body() { 71*11be35a1SLionel Sambuc create_run_id 72*11be35a1SLionel Sambuc 73*11be35a1SLionel Sambuc for p1 in -G -g -p -u; do 74*11be35a1SLionel Sambuc for p2 in -G -g -p -u; do 75*11be35a1SLionel Sambuc if [ ${p1} != ${p2} ]; then 76*11be35a1SLionel Sambuc atf_check -s eq:1 -o empty -e save:stderr \ 77*11be35a1SLionel Sambuc ./run_id.sh ${p1} ${p2} 78*11be35a1SLionel Sambuc atf_check -s eq:0 -o ignore -e empty \ 79*11be35a1SLionel Sambuc grep ^usage: stderr 80*11be35a1SLionel Sambuc fi 81*11be35a1SLionel Sambuc done 82*11be35a1SLionel Sambuc done 83*11be35a1SLionel Sambuc} 84*11be35a1SLionel Sambuc 85*11be35a1SLionel Sambucatf_test_case Gflag 86*11be35a1SLionel SambucGflag_head() { 87*11be35a1SLionel Sambuc atf_set "descr" "Checks that the -G primary flag works" 88*11be35a1SLionel Sambuc} 89*11be35a1SLionel SambucGflag_body() { 90*11be35a1SLionel Sambuc create_run_id 91*11be35a1SLionel Sambuc 92*11be35a1SLionel Sambuc echo "100 0" >expout 93*11be35a1SLionel Sambuc atf_check -s eq:0 -o file:expout -e empty ./run_id.sh -G 94*11be35a1SLionel Sambuc atf_check -s eq:0 -o file:expout -e empty ./run_id.sh -G 100 95*11be35a1SLionel Sambuc atf_check -s eq:0 -o file:expout -e empty ./run_id.sh -G test 96*11be35a1SLionel Sambuc 97*11be35a1SLionel Sambuc echo "users wheel" >expout 98*11be35a1SLionel Sambuc atf_check -s eq:0 -o file:expout -e empty ./run_id.sh -G -n 99*11be35a1SLionel Sambuc atf_check -s eq:0 -o file:expout -e empty ./run_id.sh -G -n 100 100*11be35a1SLionel Sambuc atf_check -s eq:0 -o file:expout -e empty ./run_id.sh -G -n test 101*11be35a1SLionel Sambuc 102*11be35a1SLionel Sambuc echo "0" >expout 103*11be35a1SLionel Sambuc atf_check -s eq:0 -o file:expout -e empty ./run_id.sh -G 0 104*11be35a1SLionel Sambuc atf_check -s eq:0 -o file:expout -e empty ./run_id.sh -G root 105*11be35a1SLionel Sambuc 106*11be35a1SLionel Sambuc echo "wheel" >expout 107*11be35a1SLionel Sambuc atf_check -s eq:0 -o file:expout -e empty ./run_id.sh -G -n 0 108*11be35a1SLionel Sambuc atf_check -s eq:0 -o file:expout -e empty ./run_id.sh -G -n root 109*11be35a1SLionel Sambuc 110*11be35a1SLionel Sambuc echo 'id: nonexistent: No such user' >experr 111*11be35a1SLionel Sambuc atf_check -s eq:1 -o empty -e file:experr ./run_id.sh -G nonexistent 112*11be35a1SLionel Sambuc 113*11be35a1SLionel Sambuc atf_check -s eq:1 -o empty -e save:stderr ./run_id.sh -G root nonexistent 114*11be35a1SLionel Sambuc atf_check -s eq:0 -o ignore -e empty grep ^usage: stderr 115*11be35a1SLionel Sambuc} 116*11be35a1SLionel Sambuc 117*11be35a1SLionel Sambucatf_test_case gflag 118*11be35a1SLionel Sambucgflag_head() { 119*11be35a1SLionel Sambuc atf_set "descr" "Checks that the -g primary flag works" 120*11be35a1SLionel Sambuc} 121*11be35a1SLionel Sambucgflag_body() { 122*11be35a1SLionel Sambuc create_run_id 123*11be35a1SLionel Sambuc 124*11be35a1SLionel Sambuc echo "100" >expout 125*11be35a1SLionel Sambuc atf_check -s eq:0 -o file:expout -e empty ./run_id.sh -g 126*11be35a1SLionel Sambuc atf_check -s eq:0 -o file:expout -e empty ./run_id.sh -g 100 127*11be35a1SLionel Sambuc atf_check -s eq:0 -o file:expout -e empty ./run_id.sh -g test 128*11be35a1SLionel Sambuc 129*11be35a1SLionel Sambuc echo "users" >expout 130*11be35a1SLionel Sambuc atf_check -s eq:0 -o file:expout -e empty ./run_id.sh -g -n 131*11be35a1SLionel Sambuc atf_check -s eq:0 -o file:expout -e empty ./run_id.sh -g -n 100 132*11be35a1SLionel Sambuc atf_check -s eq:0 -o file:expout -e empty ./run_id.sh -g -n test 133*11be35a1SLionel Sambuc 134*11be35a1SLionel Sambuc echo "0" >expout 135*11be35a1SLionel Sambuc atf_check -s eq:0 -o file:expout -e empty ./run_id.sh -g 0 136*11be35a1SLionel Sambuc atf_check -s eq:0 -o file:expout -e empty ./run_id.sh -g root 137*11be35a1SLionel Sambuc 138*11be35a1SLionel Sambuc echo "wheel" >expout 139*11be35a1SLionel Sambuc atf_check -s eq:0 -o file:expout -e empty ./run_id.sh -g -n 0 140*11be35a1SLionel Sambuc atf_check -s eq:0 -o file:expout -e empty ./run_id.sh -g -n root 141*11be35a1SLionel Sambuc 142*11be35a1SLionel Sambuc echo "100" >expout 143*11be35a1SLionel Sambuc atf_check -s eq:0 -o file:expout -e empty ./run_id.sh -g -r 144*11be35a1SLionel Sambuc 145*11be35a1SLionel Sambuc echo "users" >expout 146*11be35a1SLionel Sambuc atf_check -s eq:0 -o file:expout -e empty ./run_id.sh -g -r -n 147*11be35a1SLionel Sambuc 148*11be35a1SLionel Sambuc echo "100" >expout 149*11be35a1SLionel Sambuc atf_check -s eq:0 -o file:expout -e empty ./run_id.sh -g -r 100 150*11be35a1SLionel Sambuc atf_check -s eq:0 -o file:expout -e empty ./run_id.sh -g -r test 151*11be35a1SLionel Sambuc 152*11be35a1SLionel Sambuc echo "users" >expout 153*11be35a1SLionel Sambuc atf_check -s eq:0 -o file:expout -e empty ./run_id.sh -g -r -n 100 154*11be35a1SLionel Sambuc atf_check -s eq:0 -o file:expout -e empty ./run_id.sh -g -r -n test 155*11be35a1SLionel Sambuc 156*11be35a1SLionel Sambuc export LIBFAKE_EGID_ROOT=1 LIBFAKE_EUID_ROOT=1 157*11be35a1SLionel Sambuc 158*11be35a1SLionel Sambuc echo "0" >expout 159*11be35a1SLionel Sambuc atf_check -s eq:0 -o file:expout -e empty ./run_id.sh -g 160*11be35a1SLionel Sambuc 161*11be35a1SLionel Sambuc echo "wheel" >expout 162*11be35a1SLionel Sambuc atf_check -s eq:0 -o file:expout -e empty ./run_id.sh -g -n 163*11be35a1SLionel Sambuc 164*11be35a1SLionel Sambuc echo "100" >expout 165*11be35a1SLionel Sambuc atf_check -s eq:0 -o file:expout -e empty ./run_id.sh -g -r 166*11be35a1SLionel Sambuc 167*11be35a1SLionel Sambuc echo "users" >expout 168*11be35a1SLionel Sambuc atf_check -s eq:0 -o file:expout -e empty ./run_id.sh -g -r -n 169*11be35a1SLionel Sambuc 170*11be35a1SLionel Sambuc echo "100" >expout 171*11be35a1SLionel Sambuc atf_check -s eq:0 -o file:expout -e empty ./run_id.sh -g -r 100 172*11be35a1SLionel Sambuc atf_check -s eq:0 -o file:expout -e empty ./run_id.sh -g -r test 173*11be35a1SLionel Sambuc 174*11be35a1SLionel Sambuc echo "users" >expout 175*11be35a1SLionel Sambuc atf_check -s eq:0 -o file:expout -e empty ./run_id.sh -g -r -n 100 176*11be35a1SLionel Sambuc atf_check -s eq:0 -o file:expout -e empty ./run_id.sh -g -r -n test 177*11be35a1SLionel Sambuc 178*11be35a1SLionel Sambuc unset LIBFAKE_EGID_ROOT LIBFAKE_EUID_ROOT 179*11be35a1SLionel Sambuc 180*11be35a1SLionel Sambuc echo 'id: nonexistent: No such user' >experr 181*11be35a1SLionel Sambuc atf_check -s eq:1 -o empty -e file:experr ./run_id.sh -g nonexistent 182*11be35a1SLionel Sambuc 183*11be35a1SLionel Sambuc atf_check -s eq:1 -o empty -e save:stderr ./run_id.sh -g root nonexistent 184*11be35a1SLionel Sambuc atf_check -s eq:0 -o ignore -e empty grep ^usage: stderr 185*11be35a1SLionel Sambuc} 186*11be35a1SLionel Sambuc 187*11be35a1SLionel Sambucatf_test_case pflag 188*11be35a1SLionel Sambucpflag_head() { 189*11be35a1SLionel Sambuc atf_set "descr" "Checks that the -p primary flag works" 190*11be35a1SLionel Sambuc} 191*11be35a1SLionel Sambucpflag_body() { 192*11be35a1SLionel Sambuc create_run_id 193*11be35a1SLionel Sambuc 194*11be35a1SLionel Sambuc cat >expout <<EOF 195*11be35a1SLionel Sambucuid test 196*11be35a1SLionel Sambucgroups users wheel 197*11be35a1SLionel SambucEOF 198*11be35a1SLionel Sambuc atf_check -s eq:0 -o file:expout -e empty ./run_id.sh -p 199*11be35a1SLionel Sambuc atf_check -s eq:0 -o file:expout -e empty ./run_id.sh -p 100 200*11be35a1SLionel Sambuc atf_check -s eq:0 -o file:expout -e empty ./run_id.sh -p test 201*11be35a1SLionel Sambuc 202*11be35a1SLionel Sambuc cat >expout <<EOF 203*11be35a1SLionel Sambucuid root 204*11be35a1SLionel Sambucgroups wheel 205*11be35a1SLionel SambucEOF 206*11be35a1SLionel Sambuc atf_check -s eq:0 -o file:expout -e empty ./run_id.sh -p 0 207*11be35a1SLionel Sambuc atf_check -s eq:0 -o file:expout -e empty ./run_id.sh -p root 208*11be35a1SLionel Sambuc 209*11be35a1SLionel Sambuc export LIBFAKE_EGID_ROOT=1 LIBFAKE_EUID_ROOT=1 210*11be35a1SLionel Sambuc cat >expout <<EOF 211*11be35a1SLionel Sambucuid test 212*11be35a1SLionel Sambuceuid root 213*11be35a1SLionel Sambucrgid users 214*11be35a1SLionel Sambucgroups users wheel 215*11be35a1SLionel SambucEOF 216*11be35a1SLionel Sambuc atf_check -s eq:0 -o file:expout -e empty ./run_id.sh -p 217*11be35a1SLionel Sambuc unset LIBFAKE_EGID_ROOT LIBFAKE_EUID_ROOT 218*11be35a1SLionel Sambuc 219*11be35a1SLionel Sambuc echo 'id: nonexistent: No such user' >experr 220*11be35a1SLionel Sambuc atf_check -s eq:1 -o empty -e file:experr ./run_id.sh -p nonexistent 221*11be35a1SLionel Sambuc 222*11be35a1SLionel Sambuc atf_check -s eq:1 -o empty -e save:stderr ./run_id.sh -p root nonexistent 223*11be35a1SLionel Sambuc atf_check -s eq:0 -o ignore -e empty grep ^usage: stderr 224*11be35a1SLionel Sambuc} 225*11be35a1SLionel Sambuc 226*11be35a1SLionel Sambucatf_test_case uflag 227*11be35a1SLionel Sambucuflag_head() { 228*11be35a1SLionel Sambuc atf_set "descr" "Checks that the -u primary flag works" 229*11be35a1SLionel Sambuc} 230*11be35a1SLionel Sambucuflag_body() { 231*11be35a1SLionel Sambuc create_run_id 232*11be35a1SLionel Sambuc 233*11be35a1SLionel Sambuc echo "100" >expout 234*11be35a1SLionel Sambuc atf_check -s eq:0 -o file:expout -e empty ./run_id.sh -u 235*11be35a1SLionel Sambuc atf_check -s eq:0 -o file:expout -e empty ./run_id.sh -u 100 236*11be35a1SLionel Sambuc atf_check -s eq:0 -o file:expout -e empty ./run_id.sh -u test 237*11be35a1SLionel Sambuc 238*11be35a1SLionel Sambuc echo "test" >expout 239*11be35a1SLionel Sambuc atf_check -s eq:0 -o file:expout -e empty ./run_id.sh -u -n 240*11be35a1SLionel Sambuc atf_check -s eq:0 -o file:expout -e empty ./run_id.sh -u -n 100 241*11be35a1SLionel Sambuc atf_check -s eq:0 -o file:expout -e empty ./run_id.sh -u -n test 242*11be35a1SLionel Sambuc 243*11be35a1SLionel Sambuc echo "0" >expout 244*11be35a1SLionel Sambuc atf_check -s eq:0 -o file:expout -e empty ./run_id.sh -u 0 245*11be35a1SLionel Sambuc atf_check -s eq:0 -o file:expout -e empty ./run_id.sh -u root 246*11be35a1SLionel Sambuc 247*11be35a1SLionel Sambuc echo "root" >expout 248*11be35a1SLionel Sambuc atf_check -s eq:0 -o file:expout -e empty ./run_id.sh -u -n 0 249*11be35a1SLionel Sambuc atf_check -s eq:0 -o file:expout -e empty ./run_id.sh -u -n root 250*11be35a1SLionel Sambuc 251*11be35a1SLionel Sambuc echo "100" >expout 252*11be35a1SLionel Sambuc atf_check -s eq:0 -o file:expout -e empty ./run_id.sh -u -r 253*11be35a1SLionel Sambuc 254*11be35a1SLionel Sambuc echo "test" >expout 255*11be35a1SLionel Sambuc atf_check -s eq:0 -o file:expout -e empty ./run_id.sh -u -r -n 256*11be35a1SLionel Sambuc 257*11be35a1SLionel Sambuc echo "100" >expout 258*11be35a1SLionel Sambuc atf_check -s eq:0 -o file:expout -e empty ./run_id.sh -u -r 100 259*11be35a1SLionel Sambuc atf_check -s eq:0 -o file:expout -e empty ./run_id.sh -u -r test 260*11be35a1SLionel Sambuc 261*11be35a1SLionel Sambuc echo "test" >expout 262*11be35a1SLionel Sambuc atf_check -s eq:0 -o file:expout -e empty ./run_id.sh -u -r -n 100 263*11be35a1SLionel Sambuc atf_check -s eq:0 -o file:expout -e empty ./run_id.sh -u -r -n test 264*11be35a1SLionel Sambuc 265*11be35a1SLionel Sambuc export LIBFAKE_EGID_ROOT=1 LIBFAKE_EUID_ROOT=1 266*11be35a1SLionel Sambuc 267*11be35a1SLionel Sambuc echo "0" >expout 268*11be35a1SLionel Sambuc atf_check -s eq:0 -o file:expout -e empty ./run_id.sh -u 269*11be35a1SLionel Sambuc 270*11be35a1SLionel Sambuc echo "root" >expout 271*11be35a1SLionel Sambuc atf_check -s eq:0 -o file:expout -e empty ./run_id.sh -u -n 272*11be35a1SLionel Sambuc 273*11be35a1SLionel Sambuc echo "100" >expout 274*11be35a1SLionel Sambuc atf_check -s eq:0 -o file:expout -e empty ./run_id.sh -u -r 275*11be35a1SLionel Sambuc 276*11be35a1SLionel Sambuc echo "test" >expout 277*11be35a1SLionel Sambuc atf_check -s eq:0 -o file:expout -e empty ./run_id.sh -u -r -n 278*11be35a1SLionel Sambuc 279*11be35a1SLionel Sambuc echo "100" >expout 280*11be35a1SLionel Sambuc atf_check -s eq:0 -o file:expout -e empty ./run_id.sh -u -r 100 281*11be35a1SLionel Sambuc atf_check -s eq:0 -o file:expout -e empty ./run_id.sh -u -r test 282*11be35a1SLionel Sambuc 283*11be35a1SLionel Sambuc echo "test" >expout 284*11be35a1SLionel Sambuc atf_check -s eq:0 -o file:expout -e empty ./run_id.sh -u -r -n 100 285*11be35a1SLionel Sambuc atf_check -s eq:0 -o file:expout -e empty ./run_id.sh -u -r -n test 286*11be35a1SLionel Sambuc 287*11be35a1SLionel Sambuc unset LIBFAKE_EGID_ROOT LIBFAKE_EUID_ROOT 288*11be35a1SLionel Sambuc 289*11be35a1SLionel Sambuc echo 'id: nonexistent: No such user' >experr 290*11be35a1SLionel Sambuc atf_check -s eq:1 -o empty -e file:experr ./run_id.sh -u nonexistent 291*11be35a1SLionel Sambuc 292*11be35a1SLionel Sambuc atf_check -s eq:1 -o empty -e save:stderr \ 293*11be35a1SLionel Sambuc ./run_id.sh -u root nonexistent 294*11be35a1SLionel Sambuc atf_check -s eq:0 -o ignore -e empty grep ^usage: stderr 295*11be35a1SLionel Sambuc} 296*11be35a1SLionel Sambuc 297*11be35a1SLionel Sambucatf_init_test_cases() 298*11be35a1SLionel Sambuc{ 299*11be35a1SLionel Sambuc atf_add_test_case default 300*11be35a1SLionel Sambuc atf_add_test_case primaries 301*11be35a1SLionel Sambuc atf_add_test_case Gflag 302*11be35a1SLionel Sambuc atf_add_test_case gflag 303*11be35a1SLionel Sambuc atf_add_test_case pflag 304*11be35a1SLionel Sambuc atf_add_test_case uflag 305*11be35a1SLionel Sambuc} 306