port t0002-parser-error.sh to Perl 5
[unicorn.git] / t / t0100-rack-input-tests.sh
blobee7a43715a96b4d69575408a71b84f018e9b4062
1 #!/bin/sh
2 . ./test-lib.sh
3 test -r random_blob || die "random_blob required, run with 'make $0'"
5 t_plan 10 "rack.input read tests"
7 t_begin "setup and startup" && {
8 rtmpfiles curl_out curl_err
9 unicorn_setup
10 unicorn -E none -D rack-input-tests.ru -c $unicorn_config
11 blob_sha1=$(rsha1 < random_blob)
12 blob_size=$(count_bytes < random_blob)
13 t_info "blob_sha1=$blob_sha1"
14 unicorn_wait_start
17 t_begin "corked identity request" && {
18 rm -f $tmp
20 cat $fifo > $tmp &
21 printf 'PUT / HTTP/1.0\r\n'
22 printf 'Content-Length: %d\r\n\r\n' $blob_size
23 cat random_blob
24 wait
25 echo ok > $ok
26 ) | ( sleep 1 && socat - TCP4:$listen > $fifo )
27 test 1 -eq $(grep $blob_sha1 $tmp |count_lines)
28 test x"$(cat $ok)" = xok
31 t_begin "corked chunked request" && {
32 rm -f $tmp
34 cat $fifo > $tmp &
35 content-md5-put < random_blob
36 wait
37 echo ok > $ok
38 ) | ( sleep 1 && socat - TCP4:$listen > $fifo )
39 test 1 -eq $(grep $blob_sha1 $tmp |count_lines)
40 test x"$(cat $ok)" = xok
43 t_begin "corked identity request (input#size first)" && {
44 rm -f $tmp
46 cat $fifo > $tmp &
47 printf 'PUT /size_first HTTP/1.0\r\n'
48 printf 'Content-Length: %d\r\n\r\n' $blob_size
49 cat random_blob
50 wait
51 echo ok > $ok
52 ) | ( sleep 1 && socat - TCP4:$listen > $fifo )
53 test 1 -eq $(grep $blob_sha1 $tmp |count_lines)
54 test x"$(cat $ok)" = xok
57 t_begin "corked identity request (input#rewind first)" && {
58 rm -f $tmp
60 cat $fifo > $tmp &
61 printf 'PUT /rewind_first HTTP/1.0\r\n'
62 printf 'Content-Length: %d\r\n\r\n' $blob_size
63 cat random_blob
64 wait
65 echo ok > $ok
66 ) | ( sleep 1 && socat - TCP4:$listen > $fifo )
67 test 1 -eq $(grep $blob_sha1 $tmp |count_lines)
68 test x"$(cat $ok)" = xok
71 t_begin "corked chunked request (input#size first)" && {
72 rm -f $tmp
74 cat $fifo > $tmp &
75 printf 'PUT /size_first HTTP/1.1\r\n'
76 printf 'Host: example.com\r\n'
77 printf 'Transfer-Encoding: chunked\r\n'
78 printf 'Trailer: Content-MD5\r\n'
79 printf '\r\n'
80 content-md5-put --no-headers < random_blob
81 wait
82 echo ok > $ok
83 ) | ( sleep 1 && socat - TCP4:$listen > $fifo )
84 test 1 -eq $(grep $blob_sha1 $tmp |count_lines)
85 test 1 -eq $(grep $blob_sha1 $tmp |count_lines)
86 test x"$(cat $ok)" = xok
89 t_begin "corked chunked request (input#rewind first)" && {
90 rm -f $tmp
92 cat $fifo > $tmp &
93 printf 'PUT /rewind_first HTTP/1.1\r\n'
94 printf 'Host: example.com\r\n'
95 printf 'Transfer-Encoding: chunked\r\n'
96 printf 'Trailer: Content-MD5\r\n'
97 printf '\r\n'
98 content-md5-put --no-headers < random_blob
99 wait
100 echo ok > $ok
101 ) | ( sleep 1 && socat - TCP4:$listen > $fifo )
102 test 1 -eq $(grep $blob_sha1 $tmp |count_lines)
103 test x"$(cat $ok)" = xok
106 t_begin "regular request" && {
107 curl -sSf -T random_blob http://$listen/ > $curl_out 2> $curl_err
108 test x$blob_sha1 = x$(cat $curl_out)
109 test ! -s $curl_err
112 t_begin "chunked request" && {
113 curl -sSf -T- < random_blob http://$listen/ > $curl_out 2> $curl_err
114 test x$blob_sha1 = x$(cat $curl_out)
115 test ! -s $curl_err
118 dbgcat r_err
120 t_begin "shutdown" && {
121 kill $unicorn_pid
124 t_done