3 # Simple shell script which tests whether rws is basically working.
4 # - by Richard W.M. Jones <rich@annexia.org>
6 # This library is free software; you can redistribute it and/or
7 # modify it under the terms of the GNU Library General Public
8 # License as published by the Free Software Foundation; either
9 # version 2 of the License, or (at your option) any later version.
11 # This library is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 # Library General Public License for more details.
16 # You should have received a copy of the GNU Library General Public
17 # License along with this library; if not, write to the Free
18 # Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 # $Id: test_rws.sh,v 1.4 2003/02/05 23:02:51 rich Exp $
22 # A random, hopefully free, port.
25 # We need either 'wget' or 'nc'.
26 wget --help >/dev/null 2>&1
34 echo "Please install either 'wget' or 'nc'."
35 echo "This test did not run."
40 echo "Using $mode to fetch URLs."
46 # Create the configuration directory.
47 mkdir -p $tmp/etc/rws/hosts
49 cat > $tmp/etc/rws/rws.conf <<EOF
50 mime types file: $tmp/etc/mime.types
51 error log: $tmp/log/error_log
52 access log: $tmp/log/access_log
53 icon for application/*: /icons/binary.gif 20x22 "Application"
54 icon for application/x-tar: /icons/tar.gif 20x22 "Unix tape archive file"
55 icon for application/x-gzip: /icons/compressed.gif 20x22 "Compressed file"
56 icon for application/zip: /icons/compressed.gif 20x22 "Compressed file"
57 icon for audio/*: /icons/sound1.gif 20x22 "Audio file"
58 icon for image/*: /icons/image2.gif 20x22 "Image"
59 icon for message/*: /icons/quill.gif 20x22 "Mail message"
60 icon for text/*: /icons/text.gif 20x22 "Text file"
61 icon for video/*: /icons/movie.gif 20x22 "Video file"
62 no type icon: /icons/generic.gif 20x22 "File"
63 unknown icon: /icons/unknown.gif 20x22 "Unknown file type"
64 directory icon: /icons/dir.gif 20x22 "Directory"
65 link icon: /icons/link.gif 20x22 "Symbolic link"
66 special icon: /icons/sphere2.gif 20x22 "Special file"
69 cat > $tmp/etc/rws/hosts/default <<EOF
84 (cd $tmp/etc/rws/hosts; ln -s default localhost:$port)
86 cat > $tmp/etc/mime.types <<EOF
92 # Create the content directory.
96 cat > $tmp/html/index.html <<EOF
99 This is the test page.
105 cp *.o $tmp/html/files
107 # Create the so-bin directory.
109 cp examples/show_params.so $tmp/so-bin
110 chmod 0755 $tmp/so-bin/show_params.so
112 # Create the CGI directory
114 cat > $tmp/cgi-bin/test.sh <<EOF
116 echo "HTTP/1.0 200 OK"
117 echo "Content-Type: text/plain"
119 echo "This is the test CGI script"
122 chmod 0755 $tmp/cgi-bin/test.sh
124 # Try to start up the server.
125 ./rwsd -p $port -f -a 127.0.0.1 -C $tmp/etc/rws &
129 if kill -0 $rws_pid; then :;
131 echo "Server did not start up. Check any preceeding messages."
135 echo "Started rwsd instance."
137 # Fetch function: fetch (server, port, serverpath, file)
145 echo "Fetching http://$server:$port$serverpath ..."
147 if [ $mode = "nc" ]; then
148 nc $server $port > $file <<EOF
149 GET $serverpath HTTP/1.0
150 User-Agent: test_rws.sh
153 if [ $? -ne 0 ]; then exit 1; fi
155 wget -q -O $file http://$server:$port$serverpath
156 if [ $? -ne 0 ]; then kill $rws_pid; exit 1; fi
160 # Fetch the test file.
161 fetch localhost $port /index.html $tmp/downloaded
162 if grep -q MAGIC-1234 $tmp/downloaded; then :;
164 echo "Download of a simple file failed!"
165 echo "Look at $tmp/downloaded for clues."
171 # Fetch the directory listing.
172 fetch localhost $port /files/ $tmp/downloaded
173 if grep -q main.o $tmp/downloaded; then :;
175 echo "Download of a directory listing failed!"
176 echo "Look at $tmp/downloaded for clues."
182 # Test shared object scripts.
183 echo "Testing shared object scripts."
184 fetch localhost $port '/so-bin/show_params.so?key=value' $tmp/downloaded
185 if grep -q 'This is the show_params shared object script' $tmp/downloaded
188 echo "Execution of a shared object script failed!"
189 echo "Look at $tmp/downloaded for clues."
196 echo "Testing CGI scripts."
197 fetch localhost $port /cgi-bin/test.sh $tmp/downloaded
198 if grep -q MAGIC-4321 $tmp/downloaded; then :;
200 echo "Execution of a CGI script failed!"
201 echo "Look at $tmp/downloaded for clues."
207 echo "Test completed OK."
212 # Remove the temporary directory.