t_psshfs.sh revision 1.3.2.1 1 1.3.2.1 bouyer # $NetBSD: t_psshfs.sh,v 1.3.2.1 2011/02/17 12:00:53 bouyer Exp $
2 1.1 pooka #
3 1.1 pooka # Copyright (c) 2007, 2008 The NetBSD Foundation, Inc.
4 1.1 pooka # All rights reserved.
5 1.1 pooka #
6 1.1 pooka # Redistribution and use in source and binary forms, with or without
7 1.1 pooka # modification, are permitted provided that the following conditions
8 1.1 pooka # are met:
9 1.1 pooka # 1. Redistributions of source code must retain the above copyright
10 1.1 pooka # notice, this list of conditions and the following disclaimer.
11 1.1 pooka # 2. Redistributions in binary form must reproduce the above copyright
12 1.1 pooka # notice, this list of conditions and the following disclaimer in the
13 1.1 pooka # documentation and/or other materials provided with the distribution.
14 1.1 pooka #
15 1.1 pooka # THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
16 1.1 pooka # ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
17 1.1 pooka # TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
18 1.1 pooka # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
19 1.1 pooka # BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20 1.1 pooka # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21 1.1 pooka # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22 1.1 pooka # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23 1.1 pooka # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24 1.1 pooka # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25 1.1 pooka # POSSIBILITY OF SUCH DAMAGE.
26 1.1 pooka #
27 1.1 pooka
28 1.1 pooka # -------------------------------------------------------------------------
29 1.1 pooka # Auxiliary functions.
30 1.1 pooka # -------------------------------------------------------------------------
31 1.1 pooka
32 1.1 pooka #
33 1.1 pooka # Skips the calling test case if puffs is not supported in the kernel
34 1.1 pooka # or if the calling user does not have the necessary permissions to mount
35 1.1 pooka # file systems.
36 1.1 pooka #
37 1.1 pooka require_puffs() {
38 1.1 pooka case "$($(atf_get_srcdir)/h_have_puffs)" in
39 1.1 pooka eacces)
40 1.1 pooka atf_skip "Cannot open /dev/puffs for read/write access"
41 1.1 pooka ;;
42 1.1 pooka enxio)
43 1.1 pooka atf_skip "puffs support not built into the kernel"
44 1.1 pooka ;;
45 1.1 pooka failed)
46 1.1 pooka atf_skip "Unknown error trying to access /dev/puffs"
47 1.1 pooka ;;
48 1.1 pooka yes)
49 1.1 pooka ;;
50 1.1 pooka *)
51 1.1 pooka atf_fail "Unknown value returned by h_have_puffs"
52 1.1 pooka ;;
53 1.1 pooka esac
54 1.1 pooka
55 1.1 pooka if [ $(id -u) -ne 0 -a $(sysctl -n vfs.generic.usermount) -eq 0 ]
56 1.1 pooka then
57 1.1 pooka atf_skip "Regular users cannot mount file systems" \
58 1.1 pooka "(vfs.generic.usermount is set to 0)"
59 1.1 pooka fi
60 1.1 pooka }
61 1.1 pooka
62 1.1 pooka #
63 1.1 pooka # Starts a SSH server and sets up the client to access it.
64 1.1 pooka # Authentication is allowed and done using an RSA key exclusively, which
65 1.1 pooka # is generated on the fly as part of the test case.
66 1.1 pooka # XXX: Ideally, all the tests in this test program should be able to share
67 1.1 pooka # the generated key, because creating it can be a very slow process on some
68 1.1 pooka # machines.
69 1.1 pooka #
70 1.1 pooka start_ssh() {
71 1.1 pooka echo "Setting up SSH server configuration"
72 1.1 pooka sed -e "s,@SRCDIR@,$(atf_get_srcdir),g" -e "s,@WORKDIR@,$(pwd),g" \
73 1.1 pooka $(atf_get_srcdir)/sshd_config.in >sshd_config || \
74 1.1 pooka atf_fail "Failed to create sshd_config"
75 1.1 pooka atf_check -s eq:0 -o empty -e empty cp /usr/libexec/sftp-server .
76 1.1 pooka atf_check -s eq:0 -o empty -e empty \
77 1.1 pooka cp $(atf_get_srcdir)/ssh_host_key .
78 1.1 pooka atf_check -s eq:0 -o empty -e empty \
79 1.1 pooka cp $(atf_get_srcdir)/ssh_host_key.pub .
80 1.1 pooka atf_check -s eq:0 -o empty -e empty chmod 400 ssh_host_key
81 1.1 pooka atf_check -s eq:0 -o empty -e empty chmod 444 ssh_host_key.pub
82 1.1 pooka
83 1.3.2.1 bouyer /usr/sbin/sshd -e -f ./sshd_config >sshd.log 2>&1 &
84 1.3.2.1 bouyer while [ ! -f sshd.pid ]; do
85 1.3.2.1 bouyer sleep 0.01
86 1.3.2.1 bouyer done
87 1.1 pooka echo "SSH server started (pid $(cat sshd.pid))"
88 1.1 pooka
89 1.1 pooka echo "Setting up SSH client configuration"
90 1.1 pooka atf_check -s eq:0 -o empty -e empty \
91 1.1 pooka ssh-keygen -f ssh_user_key -t rsa -b 1024 -N "" -q
92 1.1 pooka atf_check -s eq:0 -o empty -e empty \
93 1.1 pooka cp ssh_user_key.pub authorized_keys
94 1.1 pooka echo "[localhost]:10000,[127.0.0.1]:10000,[::1]:10000" \
95 1.1 pooka "$(cat $(atf_get_srcdir)/ssh_host_key.pub)" >known_hosts || \
96 1.1 pooka atf_fail "Failed to create known_hosts"
97 1.1 pooka atf_check -s eq:0 -o empty -e empty chmod 600 authorized_keys
98 1.1 pooka sed -e "s,@SRCDIR@,$(atf_get_srcdir),g" -e "s,@WORKDIR@,$(pwd),g" \
99 1.1 pooka $(atf_get_srcdir)/ssh_config.in >ssh_config || \
100 1.1 pooka atf_fail "Failed to create ssh_config"
101 1.1 pooka }
102 1.1 pooka
103 1.1 pooka #
104 1.1 pooka # Stops the SSH server spawned by start_ssh and prints diagnosis data.
105 1.1 pooka #
106 1.1 pooka stop_ssh() {
107 1.1 pooka if [ -f sshd.pid ]; then
108 1.1 pooka echo "Stopping SSH server (pid $(cat sshd.pid))"
109 1.1 pooka kill $(cat sshd.pid)
110 1.1 pooka fi
111 1.1 pooka if [ -f sshd.log ]; then
112 1.1 pooka echo "Server output was:"
113 1.1 pooka sed -e 's,^, ,' sshd.log
114 1.1 pooka fi
115 1.1 pooka }
116 1.1 pooka
117 1.1 pooka #
118 1.1 pooka # Mounts the given source directory on the target directory using psshfs.
119 1.1 pooka # Both directories are supposed to live on the current directory.
120 1.1 pooka #
121 1.1 pooka mount_psshfs() {
122 1.1 pooka atf_check -s eq:0 -o empty -e empty \
123 1.1 pooka mount -t psshfs -o -F=$(pwd)/ssh_config localhost:$(pwd)/${1} ${2}
124 1.1 pooka }
125 1.1 pooka
126 1.1 pooka # -------------------------------------------------------------------------
127 1.1 pooka # The test cases.
128 1.1 pooka # -------------------------------------------------------------------------
129 1.1 pooka
130 1.1 pooka atf_test_case inode_nos cleanup
131 1.1 pooka inode_nos_head() {
132 1.1 pooka atf_set "descr" "Checks that different files get different inode" \
133 1.1 pooka "numbers"
134 1.1 pooka }
135 1.1 pooka inode_nos_body() {
136 1.1 pooka require_puffs
137 1.1 pooka
138 1.1 pooka start_ssh
139 1.1 pooka
140 1.1 pooka mkdir root
141 1.1 pooka mkdir root/dir
142 1.1 pooka touch root/dir/file1
143 1.1 pooka touch root/dir/file2
144 1.1 pooka touch root/file3
145 1.1 pooka touch root/file4
146 1.1 pooka
147 1.1 pooka cat >ne_inodes.sh <<EOF
148 1.1 pooka #! $(atf-config -t atf_shell)
149 1.1 pooka #
150 1.1 pooka # Compares the inodes of the two given files and returns true if they are
151 1.1 pooka # different; false otherwise.
152 1.1 pooka #
153 1.1 pooka test \$(stat -f %i \${1}) -ne \$(stat -f %i \${2})
154 1.1 pooka EOF
155 1.1 pooka chmod +x ne_inodes.sh
156 1.1 pooka
157 1.1 pooka mkdir mnt
158 1.1 pooka mount_psshfs root mnt
159 1.1 pooka atf_check -s eq:0 -o empty -e empty \
160 1.1 pooka ./ne_inodes.sh root/dir root/dir/file1
161 1.1 pooka atf_check -s eq:0 -o empty -e empty \
162 1.1 pooka ./ne_inodes.sh root/dir root/dir/file2
163 1.1 pooka atf_check -s eq:0 -o empty -e empty \
164 1.1 pooka ./ne_inodes.sh root/dir/file1 root/dir/file2
165 1.1 pooka atf_check -s eq:0 -o empty -e empty \
166 1.1 pooka ./ne_inodes.sh root/file3 root/file4
167 1.1 pooka }
168 1.1 pooka inode_nos_cleanup() {
169 1.1 pooka umount mnt
170 1.1 pooka stop_ssh
171 1.1 pooka }
172 1.1 pooka
173 1.1 pooka atf_test_case pwd cleanup
174 1.1 pooka pwd_head() {
175 1.1 pooka atf_set "descr" "Checks that pwd works correctly"
176 1.1 pooka }
177 1.1 pooka pwd_body() {
178 1.1 pooka require_puffs
179 1.1 pooka
180 1.1 pooka start_ssh
181 1.1 pooka
182 1.1 pooka mkdir root
183 1.1 pooka mkdir root/dir
184 1.1 pooka
185 1.1 pooka mkdir mnt
186 1.1 pooka atf_check -s eq:0 -o save:stdout -e empty \
187 1.1 pooka -x 'echo $(cd mnt && /bin/pwd)/dir'
188 1.1 pooka mv stdout expout
189 1.1 pooka mount_psshfs root mnt
190 1.1 pooka atf_check -s eq:0 -o file:expout -e empty \
191 1.1 pooka -x 'cd mnt/dir && ls .. >/dev/null && /bin/pwd'
192 1.1 pooka }
193 1.1 pooka pwd_cleanup() {
194 1.1 pooka umount mnt
195 1.1 pooka stop_ssh
196 1.1 pooka }
197 1.1 pooka
198 1.3 pooka atf_test_case ls cleanup
199 1.3 pooka ls_head() {
200 1.3 pooka atf_set "descr" "Uses ls, attempts to exercise puffs_cc"
201 1.3 pooka }
202 1.3 pooka ls_body() {
203 1.3 pooka require_puffs
204 1.3 pooka
205 1.3 pooka start_ssh
206 1.3 pooka
207 1.3 pooka mkdir mnt
208 1.3 pooka mkdir root
209 1.3 pooka mkdir root/dir
210 1.3 pooka touch root/dir/file1
211 1.3 pooka touch root/dir/file2
212 1.3 pooka touch root/file3
213 1.3 pooka touch root/file4
214 1.3 pooka
215 1.3 pooka mount_psshfs root mnt
216 1.3 pooka
217 1.3 pooka ls -l mnt &
218 1.3 pooka
219 1.3 pooka IFS=' '
220 1.3 pooka lsout='dir
221 1.3 pooka file3
222 1.3 pooka file4
223 1.3 pooka
224 1.3 pooka mnt/dir:
225 1.3 pooka file1
226 1.3 pooka file2
227 1.3 pooka '
228 1.3 pooka atf_check -s exit:0 -o inline:"$lsout" ls -R mnt
229 1.3 pooka }
230 1.3 pooka ls_cleanup() {
231 1.3 pooka umount mnt
232 1.3 pooka stop_ssh
233 1.3 pooka }
234 1.3 pooka
235 1.1 pooka # -------------------------------------------------------------------------
236 1.1 pooka # Initialization.
237 1.1 pooka # -------------------------------------------------------------------------
238 1.1 pooka
239 1.1 pooka atf_init_test_cases() {
240 1.1 pooka atf_add_test_case inode_nos
241 1.1 pooka atf_add_test_case pwd
242 1.3 pooka atf_add_test_case ls
243 1.1 pooka }
244