use strpbrk(3) to search for characters from a given set
[git/debian.git] / t / t5562-http-backend-content-length.sh
blobf0f425b2cf5746fb3f7205909cbc93eb25a84874
1 #!/bin/sh
3 test_description='test git-http-backend respects CONTENT_LENGTH'
4 . ./test-lib.sh
6 test_lazy_prereq GZIP 'gzip --version'
8 verify_http_result() {
9 # some fatal errors still produce status 200
10 # so check if there is the error message
11 if grep 'fatal:' act.err.$test_count
12 then
13 return 1
16 if ! grep "Status" act.out.$test_count >act
17 then
18 printf "Status: 200 OK\r\n" >act
20 printf "Status: $1\r\n" >exp &&
21 test_cmp exp act
24 test_http_env() {
25 handler_type="$1"
26 request_body="$2"
27 shift
28 env \
29 CONTENT_TYPE="application/x-git-$handler_type-pack-request" \
30 QUERY_STRING="/repo.git/git-$handler_type-pack" \
31 PATH_TRANSLATED="$PWD/.git/git-$handler_type-pack" \
32 GIT_HTTP_EXPORT_ALL=TRUE \
33 REQUEST_METHOD=POST \
34 "$PERL_PATH" \
35 "$TEST_DIRECTORY"/t5562/invoke-with-content-length.pl \
36 "$request_body" git http-backend >act.out.$test_count 2>act.err.$test_count
39 ssize_b100dots() {
40 # hardcoded ((size_t) SSIZE_MAX) + 1
41 case "$(build_option sizeof-size_t)" in
42 8) echo 9223372036854775808;;
43 4) echo 2147483648;;
44 *) die "Unexpected ssize_t size: $(build_option sizeof-size_t)";;
45 esac
48 test_expect_success 'setup' '
49 HTTP_CONTENT_ENCODING="identity" &&
50 export HTTP_CONTENT_ENCODING &&
51 git config http.receivepack true &&
52 test_commit c0 &&
53 test_commit c1 &&
54 hash_head=$(git rev-parse HEAD) &&
55 hash_prev=$(git rev-parse HEAD~1) &&
56 printf "want %s" "$hash_head" | packetize >fetch_body &&
57 printf 0000 >>fetch_body &&
58 printf "have %s" "$hash_prev" | packetize >>fetch_body &&
59 printf done | packetize >>fetch_body &&
60 test_copy_bytes 10 <fetch_body >fetch_body.trunc &&
61 hash_next=$(git commit-tree -p HEAD -m next HEAD^{tree}) &&
62 printf "%s %s refs/heads/newbranch\\0report-status\\n" "$_z40" "$hash_next" | packetize >push_body &&
63 printf 0000 >>push_body &&
64 echo "$hash_next" | git pack-objects --stdout >>push_body &&
65 test_copy_bytes 10 <push_body >push_body.trunc &&
66 : >empty_body
69 test_expect_success GZIP 'setup, compression related' '
70 gzip -c fetch_body >fetch_body.gz &&
71 test_copy_bytes 10 <fetch_body.gz >fetch_body.gz.trunc &&
72 gzip -c push_body >push_body.gz &&
73 test_copy_bytes 10 <push_body.gz >push_body.gz.trunc
76 test_expect_success 'fetch plain' '
77 test_http_env upload fetch_body &&
78 verify_http_result "200 OK"
81 test_expect_success 'fetch plain truncated' '
82 test_http_env upload fetch_body.trunc &&
83 ! verify_http_result "200 OK"
86 test_expect_success 'fetch plain empty' '
87 test_http_env upload empty_body &&
88 ! verify_http_result "200 OK"
91 test_expect_success GZIP 'fetch gzipped' '
92 test_env HTTP_CONTENT_ENCODING="gzip" test_http_env upload fetch_body.gz &&
93 verify_http_result "200 OK"
96 test_expect_success GZIP 'fetch gzipped truncated' '
97 test_env HTTP_CONTENT_ENCODING="gzip" test_http_env upload fetch_body.gz.trunc &&
98 ! verify_http_result "200 OK"
101 test_expect_success GZIP 'fetch gzipped empty' '
102 test_env HTTP_CONTENT_ENCODING="gzip" test_http_env upload empty_body &&
103 ! verify_http_result "200 OK"
106 test_expect_success GZIP 'push plain' '
107 test_when_finished "git branch -D newbranch" &&
108 test_http_env receive push_body &&
109 verify_http_result "200 OK" &&
110 git rev-parse newbranch >act.head &&
111 echo "$hash_next" >exp.head &&
112 test_cmp act.head exp.head
115 test_expect_success 'push plain truncated' '
116 test_http_env receive push_body.trunc &&
117 ! verify_http_result "200 OK"
120 test_expect_success 'push plain empty' '
121 test_http_env receive empty_body &&
122 ! verify_http_result "200 OK"
125 test_expect_success GZIP 'push gzipped' '
126 test_when_finished "git branch -D newbranch" &&
127 test_env HTTP_CONTENT_ENCODING="gzip" test_http_env receive push_body.gz &&
128 verify_http_result "200 OK" &&
129 git rev-parse newbranch >act.head &&
130 echo "$hash_next" >exp.head &&
131 test_cmp act.head exp.head
134 test_expect_success GZIP 'push gzipped truncated' '
135 test_env HTTP_CONTENT_ENCODING="gzip" test_http_env receive push_body.gz.trunc &&
136 ! verify_http_result "200 OK"
139 test_expect_success GZIP 'push gzipped empty' '
140 test_env HTTP_CONTENT_ENCODING="gzip" test_http_env receive empty_body &&
141 ! verify_http_result "200 OK"
144 test_expect_success 'CONTENT_LENGTH overflow ssite_t' '
145 NOT_FIT_IN_SSIZE=$(ssize_b100dots) &&
146 env \
147 CONTENT_TYPE=application/x-git-upload-pack-request \
148 QUERY_STRING=/repo.git/git-upload-pack \
149 PATH_TRANSLATED="$PWD"/.git/git-upload-pack \
150 GIT_HTTP_EXPORT_ALL=TRUE \
151 REQUEST_METHOD=POST \
152 CONTENT_LENGTH="$NOT_FIT_IN_SSIZE" \
153 git http-backend </dev/null >/dev/null 2>err &&
154 grep "fatal:.*CONTENT_LENGTH" err
157 test_expect_success 'empty CONTENT_LENGTH' '
158 env \
159 QUERY_STRING="service=git-receive-pack" \
160 PATH_TRANSLATED="$PWD"/.git/info/refs \
161 GIT_HTTP_EXPORT_ALL=TRUE \
162 REQUEST_METHOD=GET \
163 CONTENT_LENGTH="" \
164 git http-backend <empty_body >act.out.$test_count 2>act.err.$test_count &&
165 verify_http_result "200 OK"
168 test_done