3 test_description='test git-http-backend respects CONTENT_LENGTH'
6 test_lazy_prereq GZIP 'gzip --version'
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
16 if ! grep "Status" act.out.$test_count >act
18 printf "Status: 200 OK\r\n" >act
20 printf "Status: $1\r\n" >exp &&
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 \
35 "$TEST_DIRECTORY"/t5562/invoke-with-content-length.pl \
36 "$request_body" git http-backend >act.out.$test_count 2>act.err.$test_count
40 # hardcoded ((size_t) SSIZE_MAX) + 1
41 case "$(build_option sizeof-size_t)" in
42 8) echo 9223372036854775808;;
44 *) die "Unexpected ssize_t size: $(build_option sizeof-size_t)";;
48 test_expect_success 'setup' '
50 HTTP_CONTENT_ENCODING="identity" &&
51 export HTTP_CONTENT_ENCODING &&
52 git config http.receivepack true &&
55 hash_head=$(git rev-parse HEAD) &&
56 hash_prev=$(git rev-parse HEAD~1) &&
58 packetize "want $hash_head" &&
60 packetize "have $hash_prev" &&
63 test_copy_bytes 10 <fetch_body >fetch_body.trunc &&
64 hash_next=$(git commit-tree -p HEAD -m next HEAD^{tree}) &&
66 printf "%s %s refs/heads/newbranch\\0report-status object-format=%s\\n" \
67 "$ZERO_OID" "$hash_next" "$(test_oid algo)" | packetize &&
69 echo "$hash_next" | git pack-objects --stdout
71 test_copy_bytes 10 <push_body >push_body.trunc &&
75 test_expect_success GZIP 'setup, compression related' '
76 gzip -c fetch_body >fetch_body.gz &&
77 test_copy_bytes 10 <fetch_body.gz >fetch_body.gz.trunc &&
78 gzip -c push_body >push_body.gz &&
79 test_copy_bytes 10 <push_body.gz >push_body.gz.trunc
82 test_expect_success 'fetch plain' '
83 test_http_env upload fetch_body &&
84 verify_http_result "200 OK"
87 test_expect_success 'fetch plain truncated' '
88 test_http_env upload fetch_body.trunc &&
89 ! verify_http_result "200 OK"
92 test_expect_success 'fetch plain empty' '
93 test_http_env upload empty_body &&
94 ! verify_http_result "200 OK"
97 test_expect_success GZIP 'fetch gzipped' '
98 test_env HTTP_CONTENT_ENCODING="gzip" test_http_env upload fetch_body.gz &&
99 verify_http_result "200 OK"
102 test_expect_success GZIP 'fetch gzipped truncated' '
103 test_env HTTP_CONTENT_ENCODING="gzip" test_http_env upload fetch_body.gz.trunc &&
104 ! verify_http_result "200 OK"
107 test_expect_success GZIP 'fetch gzipped empty' '
108 test_env HTTP_CONTENT_ENCODING="gzip" test_http_env upload empty_body &&
109 ! verify_http_result "200 OK"
112 test_expect_success GZIP 'push plain' '
113 test_when_finished "git branch -D newbranch" &&
114 test_http_env receive push_body &&
115 verify_http_result "200 OK" &&
116 git rev-parse newbranch >act.head &&
117 echo "$hash_next" >exp.head &&
118 test_cmp act.head exp.head
121 test_expect_success 'push plain truncated' '
122 test_http_env receive push_body.trunc &&
123 ! verify_http_result "200 OK"
126 test_expect_success 'push plain empty' '
127 test_http_env receive empty_body &&
128 ! verify_http_result "200 OK"
131 test_expect_success GZIP 'push gzipped' '
132 test_when_finished "git branch -D newbranch" &&
133 test_env HTTP_CONTENT_ENCODING="gzip" test_http_env receive push_body.gz &&
134 verify_http_result "200 OK" &&
135 git rev-parse newbranch >act.head &&
136 echo "$hash_next" >exp.head &&
137 test_cmp act.head exp.head
140 test_expect_success GZIP 'push gzipped truncated' '
141 test_env HTTP_CONTENT_ENCODING="gzip" test_http_env receive push_body.gz.trunc &&
142 ! verify_http_result "200 OK"
145 test_expect_success GZIP 'push gzipped empty' '
146 test_env HTTP_CONTENT_ENCODING="gzip" test_http_env receive empty_body &&
147 ! verify_http_result "200 OK"
150 test_expect_success 'CONTENT_LENGTH overflow ssite_t' '
151 NOT_FIT_IN_SSIZE=$(ssize_b100dots) &&
153 CONTENT_TYPE=application/x-git-upload-pack-request \
154 QUERY_STRING=/repo.git/git-upload-pack \
155 PATH_TRANSLATED="$PWD"/.git/git-upload-pack \
156 GIT_HTTP_EXPORT_ALL=TRUE \
157 REQUEST_METHOD=POST \
158 CONTENT_LENGTH="$NOT_FIT_IN_SSIZE" \
159 git http-backend </dev/null >/dev/null 2>err &&
160 grep "fatal:.*CONTENT_LENGTH" err
163 test_expect_success 'empty CONTENT_LENGTH' '
165 QUERY_STRING="service=git-receive-pack" \
166 PATH_TRANSLATED="$PWD"/.git/info/refs \
167 GIT_HTTP_EXPORT_ALL=TRUE \
170 git http-backend <empty_body >act.out.$test_count 2>act.err.$test_count &&
171 verify_http_result "200 OK"