unicorn.git  about / heads / tags
Rack HTTP server for Unix and fast clients
blob 9dc1cd2980c45f82806b22d745ae874ad3bbc264 1989 bytes (raw)
$ git show no-kgio-wip:t/t0002-parser-error.sh	# shows this blob on the CLI

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
 
#!/bin/sh
. ./test-lib.sh
t_plan 11 "parser error test"

t_begin "setup and startup" && {
	unicorn_setup
	unicorn -D env.ru -c $unicorn_config
	unicorn_wait_start
}

t_begin "send a bad request" && {
	(
		printf 'GET / HTTP/1/1\r\nHost: example.com\r\n\r\n'
		cat $fifo > $tmp &
		wait
		echo ok > $ok
	) | socat - TCP:$listen > $fifo
	test xok = x$(cat $ok)
}

dbgcat tmp

t_begin "response should be a 400" && {
	grep -F 'HTTP/1.1 400 Bad Request' $tmp
}

t_begin "send a huge Request URI (REQUEST_PATH > (12 * 1024))" && {
	rm -f $tmp
	cat $fifo > $tmp &
	(
		set -e
		trap 'echo ok > $ok' EXIT
		printf 'GET /'
		for i in $(awk </dev/null 'BEGIN{for(i=0;i<1024;i++) print i}')
		do
			printf '0123456789ab'
		done
		printf ' HTTP/1.1\r\nHost: example.com\r\n\r\n'
	) | socat - TCP:$listen > $fifo || :
	test xok = x$(cat $ok)
	wait
}

t_begin "response should be a 414 (REQUEST_PATH)" && {
	grep -F 'HTTP/1.1 414 ' $tmp
}

t_begin "send a huge Request URI (QUERY_STRING > (10 * 1024))" && {
	rm -f $tmp
	cat $fifo > $tmp &
	(
		set -e
		trap 'echo ok > $ok' EXIT
		printf 'GET /hello-world?a'
		for i in $(awk </dev/null 'BEGIN{for(i=0;i<1024;i++) print i}')
		do
			printf '0123456789'
		done
		printf ' HTTP/1.1\r\nHost: example.com\r\n\r\n'
	) | socat - TCP:$listen > $fifo || :
	test xok = x$(cat $ok)
	wait
}

t_begin "response should be a 414 (QUERY_STRING)" && {
	grep -F 'HTTP/1.1 414 ' $tmp
}

t_begin "send a huge Request URI (FRAGMENT > 1024)" && {
	rm -f $tmp
	cat $fifo > $tmp &
	(
		set -e
		trap 'echo ok > $ok' EXIT
		printf 'GET /hello-world#a'
		for i in $(awk </dev/null 'BEGIN{for(i=0;i<64;i++) print i}')
		do
			printf '0123456789abcdef'
		done
		printf ' HTTP/1.1\r\nHost: example.com\r\n\r\n'
	) | socat - TCP:$listen > $fifo || :
	test xok = x$(cat $ok)
	wait
}

t_begin "response should be a 414 (FRAGMENT)" && {
	grep -F 'HTTP/1.1 414 ' $tmp
}

t_begin "server stderr should be clean" && check_stderr

t_begin "term signal sent" && kill $unicorn_pid

t_done

git clone https://yhbt.net/unicorn.git