return 414 for URI length violations
[unicorn.git] / t / t0002-parser-error.sh
blobf0df69df617156cb6d924a32063e8845f7134411
1 #!/bin/sh
2 . ./test-lib.sh
3 t_plan 11 "parser error test"
5 t_begin "setup and startup" && {
6 unicorn_setup
7 unicorn -D env.ru -c $unicorn_config
8 unicorn_wait_start
11 t_begin "send a bad request" && {
13 printf 'GET / HTTP/1/1\r\nHost: example.com\r\n\r\n'
14 cat $fifo > $tmp &
15 wait
16 echo ok > $ok
17 ) | socat - TCP:$listen > $fifo
18 test xok = x$(cat $ok)
21 dbgcat tmp
23 t_begin "response should be a 400" && {
24 grep -F 'HTTP/1.1 400 Bad Request' $tmp
27 t_begin "send a huge Request URI (REQUEST_PATH > (12 * 1024))" && {
28 rm -f $tmp
30 cat $fifo > $tmp &
31 set -e
32 trap 'wait && echo ok > $ok' EXIT
33 printf 'GET /'
34 for i in $(awk </dev/null 'BEGIN{for(i=0;i<1024;i++) print i}')
36 printf '0123456789ab'
37 done
38 printf ' HTTP/1.1\r\nHost: example.com\r\n\r\n'
39 ) | socat - TCP:$listen > $fifo || :
40 test xok = x$(cat $ok)
43 t_begin "response should be a 414" && {
44 grep -F 'HTTP/1.1 414 Request-URI Too Long' $tmp
47 t_begin "send a huge Request URI (QUERY_STRING > (10 * 1024))" && {
48 rm -f $tmp
50 cat $fifo > $tmp &
51 set -e
52 trap 'wait && echo ok > $ok' EXIT
53 printf 'GET /hello-world?a'
54 for i in $(awk </dev/null 'BEGIN{for(i=0;i<1024;i++) print i}')
56 printf '0123456789'
57 done
58 printf ' HTTP/1.1\r\nHost: example.com\r\n\r\n'
59 ) | socat - TCP:$listen > $fifo || :
60 test xok = x$(cat $ok)
63 t_begin "response should be a 414" && {
64 grep -F 'HTTP/1.1 414 Request-URI Too Long' $tmp
67 t_begin "send a huge Request URI (FRAGMENT > 1024)" && {
68 rm -f $tmp
70 cat $fifo > $tmp &
71 set -e
72 trap 'wait && echo ok > $ok' EXIT
73 printf 'GET /hello-world#a'
74 for i in $(awk </dev/null 'BEGIN{for(i=0;i<64;i++) print i}')
76 printf '0123456789abcdef'
77 done
78 printf ' HTTP/1.1\r\nHost: example.com\r\n\r\n'
79 ) | socat - TCP:$listen > $fifo || :
80 test xok = x$(cat $ok)
83 t_begin "response should be a 414" && {
84 grep -F 'HTTP/1.1 414 Request-URI Too Long' $tmp
87 t_begin "server stderr should be clean" && check_stderr
89 t_begin "term signal sent" && kill $unicorn_pid
91 t_done