t_psshfs.sh revision 1.1 1 1.1 pooka # $NetBSD: t_psshfs.sh,v 1.1 2010/07/06 14:06:22 pooka 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.1 pooka /usr/sbin/sshd -e -D -f ./sshd_config >sshd.log 2>&1 &
84 1.1 pooka echo $! >sshd.pid
85 1.1 pooka echo "SSH server started (pid $(cat sshd.pid))"
86 1.1 pooka
87 1.1 pooka echo "Setting up SSH client configuration"
88 1.1 pooka atf_check -s eq:0 -o empty -e empty \
89 1.1 pooka ssh-keygen -f ssh_user_key -t rsa -b 1024 -N "" -q
90 1.1 pooka atf_check -s eq:0 -o empty -e empty \
91 1.1 pooka cp ssh_user_key.pub authorized_keys
92 1.1 pooka echo "[localhost]:10000,[127.0.0.1]:10000,[::1]:10000" \
93 1.1 pooka "$(cat $(atf_get_srcdir)/ssh_host_key.pub)" >known_hosts || \
94 1.1 pooka atf_fail "Failed to create known_hosts"
95 1.1 pooka atf_check -s eq:0 -o empty -e empty chmod 600 authorized_keys
96 1.1 pooka sed -e "s,@SRCDIR@,$(atf_get_srcdir),g" -e "s,@WORKDIR@,$(pwd),g" \
97 1.1 pooka $(atf_get_srcdir)/ssh_config.in >ssh_config || \
98 1.1 pooka atf_fail "Failed to create ssh_config"
99 1.1 pooka }
100 1.1 pooka
101 1.1 pooka #
102 1.1 pooka # Stops the SSH server spawned by start_ssh and prints diagnosis data.
103 1.1 pooka #
104 1.1 pooka stop_ssh() {
105 1.1 pooka if [ -f sshd.pid ]; then
106 1.1 pooka echo "Stopping SSH server (pid $(cat sshd.pid))"
107 1.1 pooka kill $(cat sshd.pid)
108 1.1 pooka fi
109 1.1 pooka if [ -f sshd.log ]; then
110 1.1 pooka echo "Server output was:"
111 1.1 pooka sed -e 's,^, ,' sshd.log
112 1.1 pooka fi
113 1.1 pooka }
114 1.1 pooka
115 1.1 pooka #
116 1.1 pooka # Mounts the given source directory on the target directory using psshfs.
117 1.1 pooka # Both directories are supposed to live on the current directory.
118 1.1 pooka #
119 1.1 pooka mount_psshfs() {
120 1.1 pooka atf_check -s eq:0 -o empty -e empty \
121 1.1 pooka mount -t psshfs -o -F=$(pwd)/ssh_config localhost:$(pwd)/${1} ${2}
122 1.1 pooka }
123 1.1 pooka
124 1.1 pooka # -------------------------------------------------------------------------
125 1.1 pooka # The test cases.
126 1.1 pooka # -------------------------------------------------------------------------
127 1.1 pooka
128 1.1 pooka atf_test_case inode_nos cleanup
129 1.1 pooka inode_nos_head() {
130 1.1 pooka atf_set "descr" "Checks that different files get different inode" \
131 1.1 pooka "numbers"
132 1.1 pooka atf_set "use.fs" "true"
133 1.1 pooka }
134 1.1 pooka inode_nos_body() {
135 1.1 pooka require_puffs
136 1.1 pooka
137 1.1 pooka start_ssh
138 1.1 pooka
139 1.1 pooka mkdir root
140 1.1 pooka mkdir root/dir
141 1.1 pooka touch root/dir/file1
142 1.1 pooka touch root/dir/file2
143 1.1 pooka touch root/file3
144 1.1 pooka touch root/file4
145 1.1 pooka
146 1.1 pooka cat >ne_inodes.sh <<EOF
147 1.1 pooka #! $(atf-config -t atf_shell)
148 1.1 pooka #
149 1.1 pooka # Compares the inodes of the two given files and returns true if they are
150 1.1 pooka # different; false otherwise.
151 1.1 pooka #
152 1.1 pooka test \$(stat -f %i \${1}) -ne \$(stat -f %i \${2})
153 1.1 pooka EOF
154 1.1 pooka chmod +x ne_inodes.sh
155 1.1 pooka
156 1.1 pooka mkdir mnt
157 1.1 pooka mount_psshfs root mnt
158 1.1 pooka atf_check -s eq:0 -o empty -e empty \
159 1.1 pooka ./ne_inodes.sh root/dir root/dir/file1
160 1.1 pooka atf_check -s eq:0 -o empty -e empty \
161 1.1 pooka ./ne_inodes.sh root/dir root/dir/file2
162 1.1 pooka atf_check -s eq:0 -o empty -e empty \
163 1.1 pooka ./ne_inodes.sh root/dir/file1 root/dir/file2
164 1.1 pooka atf_check -s eq:0 -o empty -e empty \
165 1.1 pooka ./ne_inodes.sh root/file3 root/file4
166 1.1 pooka }
167 1.1 pooka inode_nos_cleanup() {
168 1.1 pooka umount mnt
169 1.1 pooka stop_ssh
170 1.1 pooka }
171 1.1 pooka
172 1.1 pooka atf_test_case pwd cleanup
173 1.1 pooka pwd_head() {
174 1.1 pooka atf_set "descr" "Checks that pwd works correctly"
175 1.1 pooka atf_set "use.fs" "true"
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.1 pooka # -------------------------------------------------------------------------
199 1.1 pooka # Initialization.
200 1.1 pooka # -------------------------------------------------------------------------
201 1.1 pooka
202 1.1 pooka atf_init_test_cases() {
203 1.1 pooka atf_add_test_case inode_nos
204 1.1 pooka atf_add_test_case pwd
205 1.1 pooka }
206