t_whoami.sh revision 272343
1134911Ssam# $NetBSD: t_whoami.sh,v 1.1 2012/03/17 16:33:14 jruoho Exp $
2134911Ssam#
3134911Ssam# Copyright (c) 2007, 2008 The NetBSD Foundation, Inc.
4134911Ssam# All rights reserved.
5134911Ssam#
6134911Ssam# Redistribution and use in source and binary forms, with or without
7134911Ssam# modification, are permitted provided that the following conditions
8134911Ssam# are met:
9134911Ssam# 1. Redistributions of source code must retain the above copyright
10134911Ssam#    notice, this list of conditions and the following disclaimer.
11134911Ssam# 2. Redistributions in binary form must reproduce the above copyright
12134911Ssam#    notice, this list of conditions and the following disclaimer in the
13134911Ssam#    documentation and/or other materials provided with the distribution.
14134911Ssam#
15134911Ssam# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
16134911Ssam# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
17134911Ssam# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
18134911Ssam# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
19134911Ssam# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20134911Ssam# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21134911Ssam# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22134911Ssam# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23134911Ssam# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24134911Ssam# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25134911Ssam# POSSIBILITY OF SUCH DAMAGE.
26134911Ssam#
27134911Ssam
28134911Ssamcreate_run_whoami() {
29134911Ssam	cat >run_whoami.sh <<EOF
30134911Ssam#! /bin/sh
31134911Ssam[ -f ./whoami ] || ln -s $(atf_get_srcdir)/h_id ./whoami
32134911Ssam./whoami "\${@}"
33134911SsamEOF
34134911Ssam	chmod +x run_whoami.sh
35134911Ssam}
36134911Ssam
37134911Ssamatf_test_case correct
38134911Ssamcorrect_head() {
39134911Ssam	atf_set "descr" "Checks that correct queries work"
40134911Ssam}
41134911Ssamcorrect_body() {
42134911Ssam	create_run_whoami
43167755Ssam
44134911Ssam	echo "Checking with EUID=100"
45134911Ssam	echo "test" >expout
46134911Ssam	atf_check -s eq:0 -o file:expout -e empty ./run_whoami.sh
47134911Ssam
48134911Ssam	echo "Checking with EUID=0"
49134911Ssam	export LIBFAKE_EUID_ROOT=1
50134911Ssam	echo "root" >expout
51134911Ssam	atf_check -s eq:0 -o file:expout -e empty ./run_whoami.sh
52134911Ssam}
53134911Ssam
54134911Ssamatf_test_case syntax
55134911Ssamsyntax_head() {
56134911Ssam	atf_set "descr" "Checks the command's syntax"
57134911Ssam}
58134911Ssamsyntax_body() {
59134911Ssam	create_run_whoami
60134911Ssam
61134911Ssam	# Give a user to the command.
62134911Ssam	echo 'usage: whoami' >experr
63134911Ssam	atf_check -s eq:1 -o empty -e file:experr ./run_whoami.sh root
64134911Ssam
65134911Ssam	# Give an invalid flag but which is allowed by id (with which
66134911Ssam	# whoami shares code) when using the -un options.
67134911Ssam	echo 'usage: whoami' >experr
68134911Ssam	atf_check -s eq:1 -o empty -e file:experr ./run_whoami.sh -r
69134911Ssam}
70134911Ssam
71134911Ssamatf_init_test_cases()
72134911Ssam{
73134911Ssam	atf_add_test_case correct
74134911Ssam	atf_add_test_case syntax
75134911Ssam}
76134911Ssam