1 # $NetBSD: t_create.sh,v 1.8 2011/03/05 07:41:11 pooka Exp $
3 # Copyright (c) 2005, 2006, 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.
29 # Verifies that the create operation works.
34 atf_set
"descr" "Verifies that files can be created"
35 atf_set
"require.user" "root"
40 atf_check
-s eq
:1 -o empty
-e empty
test -f a
41 atf_check
-s eq
:0 -o empty
-e empty
touch a
42 atf_check
-s eq
:0 -o empty
-e empty
test -f a
49 atf_set
"descr" "Verifies that a new file gets the correct" \
51 atf_set
"require.config" "unprivileged-user"
52 atf_set
"require.user" "root"
55 user
=$
(atf_config_get unprivileged-user
)
56 # Allow the unprivileged user to access the work directory.
62 atf_check
-s eq
:1 -o empty
-e empty
test -f a
63 atf_check
-s eq
:0 -o empty
-e empty
touch a
64 atf_check
-s eq
:0 -o empty
-e empty
test -f a
66 eval $
(stat
-s . |
sed -e 's|st_|dst_|g')
68 test ${st_flags} -eq 0 || atf_fail
"Incorrect flags"
69 test ${st_size} -eq 0 || atf_fail
"Incorrect size"
70 test ${st_uid} -eq $
(id
-u) || atf_fail
"Incorrect uid"
71 test ${st_gid} -eq ${dst_gid} || atf_fail
"Incorrect gid"
72 test ${st_mode} = 0100644 || atf_fail
"Incorrect mode"
74 atf_check
-s eq
:0 -o empty
-e empty mkdir b c
76 atf_check
-s eq
:0 -o empty
-e empty chown
${user}:0 b
78 [ ${st_uid} -eq $
(id
-u ${user}) ] || atf_fail
"Incorrect owner"
79 [ ${st_gid} -eq 0 ] || atf_fail
"Incorrect group"
81 atf_check
-s eq
:0 -o empty
-e empty chown
${user}:100 c
83 [ ${st_uid} -eq $
(id
-u ${user}) ] || atf_fail
"Incorrect owner"
84 [ ${st_gid} -eq 100 ] || atf_fail
"Incorrect group"
86 atf_check
-s eq
:0 -o empty
-e empty su
-m ${user} -c 'touch b/a'
88 [ ${st_uid} -eq $
(id
-u ${user}) ] || atf_fail
"Incorrect owner"
89 [ ${st_gid} -eq 0 ] || atf_fail
"Incorrect group"
91 atf_check
-s eq
:0 -o empty
-e empty su
-m ${user} -c 'touch c/a'
93 [ ${st_uid} -eq $
(id
-u ${user}) ] || atf_fail
"Incorrect owner"
94 [ ${st_gid} -eq 100 ] || atf_fail
"Incorrect group"
101 atf_set
"descr" "Verifies that creating a file raises the correct" \
103 atf_set
"require.user" "root"
108 atf_check
-s eq
:0 -o empty
-e empty mkdir dir
109 echo 'touch dir/a' | kqueue_monitor
1 dir
110 kqueue_check dir NOTE_WRITE
115 atf_init_test_cases
() {
116 . $
(atf_get_srcdir
)/..
/h_funcs.subr
117 . $
(atf_get_srcdir
)/h_funcs.subr
119 atf_add_test_case create
120 atf_add_test_case attrs
121 atf_add_test_case kqueue