/[jscoverage]/trunk/tests/server-bad-requests.sh
ViewVC logotype

Contents of /trunk/tests/server-bad-requests.sh

Parent Directory Parent Directory | Revision Log Revision Log


Revision 610 - (show annotations)
Fri Sep 24 20:35:36 2010 UTC (9 years, 1 month ago) by siliconforks
File MIME type: application/x-sh
File size: 3721 byte(s)
Remove hard-coded port numbers.

1 #!/bin/sh
2 # server-bad-requests.sh - test jscoverage-server with bad requests
3 # Copyright (C) 2008, 2009, 2010 siliconforks.com
4 #
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 2 of the License, or
8 # (at your option) any later version.
9 #
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License along
16 # with this program; if not, write to the Free Software Foundation, Inc.,
17 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18
19 set -e
20
21 shutdown() {
22 wget -q -O- --post-data= "http://127.0.0.1:${server_port}/jscoverage-shutdown" > /dev/null
23 wait $server_pid
24 }
25
26 cleanup() {
27 shutdown
28 rm -fr EXPECTED ACTUAL OUT ERR
29 }
30
31 bad_request() {
32 /usr/bin/printf "$1" | $NETCAT 127.0.0.1 $server_port > OUT 2> ERR
33 echo 'HTTP/1.1 400 Bad Request' > EXPECTED
34 head -n 1 OUT > ACTUAL
35 diff --strip-trailing-cr EXPECTED ACTUAL
36 }
37
38 bad_nul_request() {
39 perl echo.pl "$1" | $NETCAT 127.0.0.1 $server_port > OUT 2> ERR
40
41 # When jscoverage-server receives a NUL, in the headers, it immediately closes
42 # the connection.
43 #
44 # On Windows, it appears that this sometimes results in the client read
45 # failing with error 10053 (WSAECONNABORTED).
46 #
47 # This does not happen every time, but when it does OUT will be empty.
48 if [ -s OUT ]
49 then
50 echo 'HTTP/1.1 400 Bad Request' > EXPECTED
51 head -n 1 OUT > ACTUAL
52 diff --strip-trailing-cr EXPECTED ACTUAL
53 fi
54 }
55
56 trap 'cleanup' 0 1 2 3 15
57
58 . ./common.sh
59
60 NETCAT='perl netcat.pl';
61
62 rm -fr EXPECTED ACTUAL OUT ERR
63 server_port=`perl unused-port.pl`
64 $VALGRIND jscoverage-server --port $server_port > /dev/null 2> /dev/null &
65 server_pid=$!
66
67 wait_for_server http://127.0.0.1:${server_port}/jscoverage.html
68
69 # send NUL in Request-Line
70 bad_nul_request 'GET \0 HTTP/1.1\r\n\r\n'
71
72 # send empty Request-Line
73 bad_request '\r\n\r\n'
74
75 # send bad Request-Line
76 bad_request ' \r\n\r\n'
77 bad_request 'GET\r\n\r\n'
78 bad_request 'GET \r\n\r\n'
79 bad_request 'GET \r\n\r\n'
80 bad_request 'GET /\r\n\r\n'
81 bad_request 'GET / \r\n\r\n'
82
83 # bad Host header
84 bad_request 'GET / HTTP/1.1\r\nConnection: close\r\nHost: foo:bar\r\n\r\n'
85
86 # NUL in header
87 bad_nul_request 'GET / HTTP/1.1\r\nConnection: close\r\nFoo: \0\r\n\r\n'
88
89 # missing header
90 bad_request 'GET / HTTP/1.1\r\nConnection: close\r\n: bar\r\n\r\n'
91
92 # missing header value
93 # bad_request 'GET / HTTP/1.1\r\nConnection: close\r\nFoo:\r\n\r\n'
94
95 # bad Transfer-Encoding
96 bad_request 'GET / HTTP/1.1\r\nConnection: close\r\nTransfer-Encoding: foo;\r\n\r\n'
97 bad_request 'GET / HTTP/1.1\r\nConnection: close\r\nTransfer-Encoding: foo; bar\r\n\r\n'
98 bad_request 'GET / HTTP/1.1\r\nConnection: close\r\nTransfer-Encoding: foo; bar = "\r\n\r\n'
99 bad_request 'GET / HTTP/1.1\r\nConnection: close\r\nTransfer-Encoding: foo; bar = "\r\n\r\n'
100 bad_request 'GET / HTTP/1.1\r\nConnection: close\r\nTransfer-Encoding: foo; bar = "\\\200"\r\n\r\n'
101 bad_request 'GET / HTTP/1.1\r\nConnection: close\r\nTransfer-Encoding: foo; bar = "\177"\r\n\r\n'
102 bad_request 'GET / HTTP/1.1\r\nConnection: close\r\nTransfer-Encoding: foo; bar = ;\r\n\r\n'
103
104 # bad Content-Length
105 bad_request 'GET / HTTP/1.1\r\nConnection: close\r\nContent-Length: 4294967296\r\n\r\n'
106 bad_request 'GET / HTTP/1.1\r\nConnection: close\r\nContent-Length: 4294967300\r\n\r\n'
107 bad_request 'GET / HTTP/1.1\r\nConnection: close\r\nContent-Length: foo\r\n\r\n'

Properties

Name Value
svn:executable *

  ViewVC Help
Powered by ViewVC 1.1.24