PageRenderTime 79ms CodeModel.GetById 72ms app.highlight 4ms RepoModel.GetById 1ms app.codeStats 1ms

/js/lib/Socket.IO-node/support/expresso/deps/jscoverage/tests/server-bad-requests.sh

http://github.com/onedayitwillmake/RealtimeMultiplayerNodeJs
Shell | 104 lines | 59 code | 19 blank | 26 comment | 2 complexity | bcb71ab565eb1603a8bb5aafcda6fdcb MD5 | raw file
  1#!/bin/sh
  2#    server-bad-requests.sh - test jscoverage-server with bad requests
  3#    Copyright (C) 2008 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
 19set -e
 20
 21shutdown() {
 22  wget -q -O- --post-data= "http://127.0.0.1:${server_port}/jscoverage-shutdown" > /dev/null
 23  wait $server_pid
 24}
 25
 26cleanup() {
 27  shutdown
 28  rm -fr EXPECTED ACTUAL OUT ERR
 29}
 30
 31bad_request() {
 32  /bin/echo -ne "$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
 38trap 'cleanup' 0 1 2 3 15
 39
 40export PATH=.:..:$PATH
 41
 42if [ -z "$VALGRIND" ]
 43then
 44  delay=0.2
 45else
 46  delay=2
 47fi
 48
 49if which netcat > /dev/null 2> /dev/null
 50then
 51  NETCAT=netcat
 52elif which nc > /dev/null 2> /dev/null
 53then
 54  NETCAT=nc
 55else
 56  NETCAT='perl netcat.pl';
 57fi
 58
 59rm -fr EXPECTED ACTUAL OUT ERR
 60$VALGRIND jscoverage-server --port 8000 > /dev/null 2> /dev/null &
 61server_pid=$!
 62server_port=8000
 63
 64sleep $delay
 65
 66# send NUL in Request-Line
 67bad_request 'GET \0000 HTTP/1.1\r\n\r\n'
 68
 69# send empty Request-Line
 70bad_request '\r\n\r\n'
 71
 72# send bad Request-Line
 73bad_request ' \r\n\r\n'
 74bad_request 'GET\r\n\r\n'
 75bad_request 'GET \r\n\r\n'
 76bad_request 'GET  \r\n\r\n'
 77bad_request 'GET /\r\n\r\n'
 78bad_request 'GET / \r\n\r\n'
 79
 80# bad Host header
 81bad_request 'GET / HTTP/1.1\r\nConnection: close\r\nHost: foo:bar\r\n\r\n'
 82
 83# NUL in header
 84bad_request 'GET / HTTP/1.1\r\nConnection: close\r\nFoo: \0000\r\n\r\n'
 85
 86# missing header
 87bad_request 'GET / HTTP/1.1\r\nConnection: close\r\n: bar\r\n\r\n'
 88
 89# missing header value
 90bad_request 'GET / HTTP/1.1\r\nConnection: close\r\nFoo:\r\n\r\n'
 91
 92# bad Transfer-Encoding
 93bad_request 'GET / HTTP/1.1\r\nConnection: close\r\nTransfer-Encoding: foo;\r\n\r\n'
 94bad_request 'GET / HTTP/1.1\r\nConnection: close\r\nTransfer-Encoding: foo; bar\r\n\r\n'
 95bad_request 'GET / HTTP/1.1\r\nConnection: close\r\nTransfer-Encoding: foo; bar = "\r\n\r\n'
 96bad_request 'GET / HTTP/1.1\r\nConnection: close\r\nTransfer-Encoding: foo; bar = "\r\n\r\n'
 97bad_request 'GET / HTTP/1.1\r\nConnection: close\r\nTransfer-Encoding: foo; bar = "\\\0200"\r\n\r\n'
 98bad_request 'GET / HTTP/1.1\r\nConnection: close\r\nTransfer-Encoding: foo; bar = "\0177"\r\n\r\n'
 99bad_request 'GET / HTTP/1.1\r\nConnection: close\r\nTransfer-Encoding: foo; bar = ;\r\n\r\n'
100
101# bad Content-Length
102bad_request 'GET / HTTP/1.1\r\nConnection: close\r\nContent-Length: 4294967296\r\n\r\n'
103bad_request 'GET / HTTP/1.1\r\nConnection: close\r\nContent-Length: 4294967300\r\n\r\n'
104bad_request 'GET / HTTP/1.1\r\nConnection: close\r\nContent-Length: foo\r\n\r\n'