]> git.ipfire.org Git - thirdparty/git.git/blame - t/t5562-http-backend-content-length.sh
Merge branch 'bc/sha-256-part-2'
[thirdparty/git.git] / t / t5562-http-backend-content-length.sh
CommitLineData
6c213e86
MK
1#!/bin/sh
2
3test_description='test git-http-backend respects CONTENT_LENGTH'
4. ./test-lib.sh
5
6test_lazy_prereq GZIP 'gzip --version'
7
8verify_http_result() {
9 # some fatal errors still produce status 200
10 # so check if there is the error message
0539071b 11 if grep 'fatal:' act.err.$test_count
6c213e86
MK
12 then
13 return 1
14 fi
15
0539071b 16 if ! grep "Status" act.out.$test_count >act
6c213e86
MK
17 then
18 printf "Status: 200 OK\r\n" >act
19 fi
20 printf "Status: $1\r\n" >exp &&
21 test_cmp exp act
22}
23
24test_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 \
8c8fad9e 34 "$PERL_PATH" \
6c213e86 35 "$TEST_DIRECTORY"/t5562/invoke-with-content-length.pl \
0539071b 36 "$request_body" git http-backend >act.out.$test_count 2>act.err.$test_count
6c213e86
MK
37}
38
39ssize_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
46}
47
48test_expect_success 'setup' '
9dc78c20 49 test_oid_init &&
eebfe409
RJ
50 HTTP_CONTENT_ENCODING="identity" &&
51 export HTTP_CONTENT_ENCODING &&
6c213e86
MK
52 git config http.receivepack true &&
53 test_commit c0 &&
54 test_commit c1 &&
55 hash_head=$(git rev-parse HEAD) &&
56 hash_prev=$(git rev-parse HEAD~1) &&
88124ab2
JK
57 {
58 packetize "want $hash_head" &&
59 printf 0000 &&
60 packetize "have $hash_prev" &&
61 packetize "done"
62 } >fetch_body &&
6c213e86
MK
63 test_copy_bytes 10 <fetch_body >fetch_body.trunc &&
64 hash_next=$(git commit-tree -p HEAD -m next HEAD^{tree}) &&
88124ab2 65 {
9dc78c20 66 printf "%s %s refs/heads/newbranch\\0report-status object-format=%s\\n" \
67 "$ZERO_OID" "$hash_next" "$(test_oid algo)" | packetize &&
88124ab2
JK
68 printf 0000 &&
69 echo "$hash_next" | git pack-objects --stdout
70 } >push_body &&
6c213e86
MK
71 test_copy_bytes 10 <push_body >push_body.trunc &&
72 : >empty_body
73'
74
75test_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
80'
81
82test_expect_success 'fetch plain' '
83 test_http_env upload fetch_body &&
84 verify_http_result "200 OK"
85'
86
87test_expect_success 'fetch plain truncated' '
88 test_http_env upload fetch_body.trunc &&
89 ! verify_http_result "200 OK"
90'
91
92test_expect_success 'fetch plain empty' '
93 test_http_env upload empty_body &&
94 ! verify_http_result "200 OK"
95'
96
97test_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"
100'
101
102test_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"
105'
106
107test_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"
110'
111
112test_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
119'
120
121test_expect_success 'push plain truncated' '
122 test_http_env receive push_body.trunc &&
123 ! verify_http_result "200 OK"
124'
125
126test_expect_success 'push plain empty' '
127 test_http_env receive empty_body &&
128 ! verify_http_result "200 OK"
129'
130
131test_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
138'
139
140test_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"
143'
144
145test_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"
148'
149
150test_expect_success 'CONTENT_LENGTH overflow ssite_t' '
151 NOT_FIT_IN_SSIZE=$(ssize_b100dots) &&
d9919482 152 env \
6c213e86
MK
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" \
70941750 159 git http-backend </dev/null >/dev/null 2>err &&
6c213e86
MK
160 grep "fatal:.*CONTENT_LENGTH" err
161'
162
574c513e
MK
163test_expect_success 'empty CONTENT_LENGTH' '
164 env \
806b1687
MK
165 QUERY_STRING="service=git-receive-pack" \
166 PATH_TRANSLATED="$PWD"/.git/info/refs \
574c513e
MK
167 GIT_HTTP_EXPORT_ALL=TRUE \
168 REQUEST_METHOD=GET \
169 CONTENT_LENGTH="" \
0539071b 170 git http-backend <empty_body >act.out.$test_count 2>act.err.$test_count &&
574c513e
MK
171 verify_http_result "200 OK"
172'
173
6c213e86 174test_done