Skip to content

Commit b2893ea

Browse files
committed
Merge branch 'jk/http-test-fixes'
Various fix-ups on HTTP tests. * jk/http-test-fixes: t5559: make SSL/TLS the default t5559: fix test failures with LIB_HTTPD_SSL t/lib-httpd: enable HTTP/2 "h2" protocol, not just h2c t/lib-httpd: respect $HTTPD_PROTO in expect_askpass() t5551: drop curl trace lines without headers t5551: handle v2 protocol in cookie test t5551: simplify expected cookie file t5551: handle v2 protocol in upload-pack service test t5551: handle v2 protocol when checking curl trace t5551: stop forcing clone to run with v0 protocol t5551: handle HTTP/2 when checking curl trace t5551: lower-case headers in expected curl trace t5551: drop redundant grep for Accept-Language t5541: simplify and move "no empty path components" test t5541: stop marking "used receive-pack service" test as v0 only t5541: run "used receive-pack service" test earlier
2 parents a0f05f6 + 8f2146d commit b2893ea

File tree

5 files changed

+122
-114
lines changed

5 files changed

+122
-114
lines changed

t/lib-httpd.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -290,11 +290,11 @@ expect_askpass() {
290290
none)
291291
;;
292292
pass)
293-
echo "askpass: Password for 'http://$2@$dest': "
293+
echo "askpass: Password for '$HTTPD_PROTO://$2@$dest': "
294294
;;
295295
both)
296-
echo "askpass: Username for 'http://$dest': "
297-
echo "askpass: Password for 'http://$2@$dest': "
296+
echo "askpass: Username for '$HTTPD_PROTO://$dest': "
297+
echo "askpass: Password for '$HTTPD_PROTO://$2@$dest': "
298298
;;
299299
*)
300300
false

t/lib-httpd/apache.conf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ ErrorLog error.log
3131

3232
<IfDefine HTTP2>
3333
LoadModule http2_module modules/mod_http2.so
34-
Protocols h2c
34+
Protocols h2 h2c
3535
</IfDefine>
3636

3737
<IfModule !mod_auth_basic.c>

t/t5541-http-push-smart.sh

Lines changed: 13 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -36,28 +36,6 @@ test_expect_success 'setup remote repository' '
3636

3737
setup_askpass_helper
3838

39-
cat >exp <<EOF
40-
GET /smart/test_repo.git/info/refs?service=git-upload-pack HTTP/1.1 200
41-
POST /smart/test_repo.git/git-upload-pack HTTP/1.1 200
42-
EOF
43-
test_expect_success 'no empty path components' '
44-
# Clear the log, so that it does not affect the "used receive-pack
45-
# service" test which reads the log too.
46-
test_when_finished ">\"\$HTTPD_ROOT_PATH\"/access.log" &&
47-
48-
# In the URL, add a trailing slash, and see if git appends yet another
49-
# slash.
50-
cd "$ROOT_PATH" &&
51-
git clone $HTTPD_URL/smart/test_repo.git/ test_repo_clone &&
52-
53-
# NEEDSWORK: If the overspecification of the expected result is reduced, we
54-
# might be able to run this test in all protocol versions.
55-
if test "$GIT_TEST_PROTOCOL_VERSION" = 0
56-
then
57-
check_access_log exp
58-
fi
59-
'
60-
6139
test_expect_success 'clone remote repository' '
6240
rm -rf test_repo_clone &&
6341
git clone $HTTPD_URL/smart/test_repo.git test_repo_clone &&
@@ -67,6 +45,10 @@ test_expect_success 'clone remote repository' '
6745
'
6846

6947
test_expect_success 'push to remote repository (standard)' '
48+
# Clear the log, so that the "used receive-pack service" test below
49+
# sees just what we did here.
50+
>"$HTTPD_ROOT_PATH"/access.log &&
51+
7052
cd "$ROOT_PATH"/test_repo_clone &&
7153
: >path2 &&
7254
git add path2 &&
@@ -80,6 +62,15 @@ test_expect_success 'push to remote repository (standard)' '
8062
test $HEAD = $(git rev-parse --verify HEAD))
8163
'
8264

65+
test_expect_success 'used receive-pack service' '
66+
cat >exp <<-\EOF &&
67+
GET /smart/test_repo.git/info/refs?service=git-receive-pack HTTP/1.1 200
68+
POST /smart/test_repo.git/git-receive-pack HTTP/1.1 200
69+
EOF
70+
71+
check_access_log exp
72+
'
73+
8374
test_expect_success 'push to remote repository (standard) with sending Accept-Language' '
8475
cat >exp <<-\EOF &&
8576
=> Send header: Accept-Language: ko-KR, *;q=0.9
@@ -141,28 +132,6 @@ test_expect_success 'rejected update prints status' '
141132
'
142133
rm -f "$HTTPD_DOCUMENT_ROOT_PATH/test_repo.git/hooks/update"
143134

144-
cat >exp <<EOF
145-
GET /smart/test_repo.git/info/refs?service=git-upload-pack HTTP/1.1 200
146-
POST /smart/test_repo.git/git-upload-pack HTTP/1.1 200
147-
GET /smart/test_repo.git/info/refs?service=git-receive-pack HTTP/1.1 200
148-
POST /smart/test_repo.git/git-receive-pack HTTP/1.1 200
149-
GET /smart/test_repo.git/info/refs?service=git-receive-pack HTTP/1.1 200
150-
GET /smart/test_repo.git/info/refs?service=git-receive-pack HTTP/1.1 200
151-
POST /smart/test_repo.git/git-receive-pack HTTP/1.1 200
152-
GET /smart/test_repo.git/info/refs?service=git-receive-pack HTTP/1.1 200
153-
POST /smart/test_repo.git/git-receive-pack HTTP/1.1 200
154-
GET /smart/test_repo.git/info/refs?service=git-receive-pack HTTP/1.1 200
155-
POST /smart/test_repo.git/git-receive-pack HTTP/1.1 200
156-
EOF
157-
test_expect_success 'used receive-pack service' '
158-
# NEEDSWORK: If the overspecification of the expected result is reduced, we
159-
# might be able to run this test in all protocol versions.
160-
if test "$GIT_TEST_PROTOCOL_VERSION" = 0
161-
then
162-
check_access_log exp
163-
fi
164-
'
165-
166135
test_http_push_nonff "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo.git \
167136
"$ROOT_PATH"/test_repo_clone main success
168137

t/t5551-http-fetch-smart.sh

Lines changed: 104 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/bin/sh
22

3-
: ${HTTP_PROTO:=HTTP}
3+
: ${HTTP_PROTO:=HTTP/1.1}
44
test_description="test smart fetching over http via http-backend ($HTTP_PROTO)"
55
GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
66
export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
@@ -33,35 +33,71 @@ test_expect_success 'create http-accessible bare repository' '
3333
setup_askpass_helper
3434

3535
test_expect_success 'clone http repository' '
36-
cat >exp <<-\EOF &&
37-
> GET /smart/repo.git/info/refs?service=git-upload-pack HTTP/1.1
38-
> Accept: */*
39-
> Accept-Encoding: ENCODINGS
40-
> Accept-Language: ko-KR, *;q=0.9
41-
> Pragma: no-cache
42-
< HTTP/1.1 200 OK
43-
< Pragma: no-cache
44-
< Cache-Control: no-cache, max-age=0, must-revalidate
45-
< Content-Type: application/x-git-upload-pack-advertisement
46-
> POST /smart/repo.git/git-upload-pack HTTP/1.1
47-
> Accept-Encoding: ENCODINGS
48-
> Content-Type: application/x-git-upload-pack-request
49-
> Accept: application/x-git-upload-pack-result
50-
> Accept-Language: ko-KR, *;q=0.9
51-
> Content-Length: xxx
52-
< HTTP/1.1 200 OK
53-
< Pragma: no-cache
54-
< Cache-Control: no-cache, max-age=0, must-revalidate
55-
< Content-Type: application/x-git-upload-pack-result
36+
if test_have_prereq HTTP2 && test "$HTTPD_PROTO" = "https"
37+
then
38+
# ALPN lets us immediately use HTTP/2; likewise, POSTs with
39+
# bodies can use it because they do not need to upgrade
40+
INITIAL_PROTO=HTTP/2
41+
else
42+
# either we are not using HTTP/2, or the initial
43+
# request is sent via HTTP/1.1 and asks for upgrade
44+
INITIAL_PROTO=HTTP/1.1
45+
fi &&
46+
47+
cat >exp.raw <<-EOF &&
48+
> GET /smart/repo.git/info/refs?service=git-upload-pack $INITIAL_PROTO
49+
> accept: */*
50+
> accept-encoding: ENCODINGS
51+
> accept-language: ko-KR, *;q=0.9
52+
> pragma: no-cache
53+
{V2} > git-protocol: version=2
54+
< $HTTP_PROTO 200 OK
55+
< pragma: no-cache
56+
< cache-control: no-cache, max-age=0, must-revalidate
57+
< content-type: application/x-git-upload-pack-advertisement
58+
> POST /smart/repo.git/git-upload-pack $INITIAL_PROTO
59+
> accept-encoding: ENCODINGS
60+
> content-type: application/x-git-upload-pack-request
61+
> accept: application/x-git-upload-pack-result
62+
> accept-language: ko-KR, *;q=0.9
63+
{V2} > git-protocol: version=2
64+
> content-length: xxx
65+
< $INITIAL_PROTO 200 OK
66+
< pragma: no-cache
67+
< cache-control: no-cache, max-age=0, must-revalidate
68+
< content-type: application/x-git-upload-pack-result
69+
{V2} > POST /smart/repo.git/git-upload-pack $INITIAL_PROTO
70+
{V2} > accept-encoding: ENCODINGS
71+
{V2} > content-type: application/x-git-upload-pack-request
72+
{V2} > accept: application/x-git-upload-pack-result
73+
{V2} > accept-language: ko-KR, *;q=0.9
74+
{V2} > git-protocol: version=2
75+
{V2} > content-length: xxx
76+
{V2} < $INITIAL_PROTO 200 OK
77+
{V2} < pragma: no-cache
78+
{V2} < cache-control: no-cache, max-age=0, must-revalidate
79+
{V2} < content-type: application/x-git-upload-pack-result
5680
EOF
5781
58-
GIT_TRACE_CURL=true GIT_TEST_PROTOCOL_VERSION=0 LANGUAGE="ko_KR.UTF-8" \
82+
if test "$GIT_TEST_PROTOCOL_VERSION" = 0
83+
then
84+
sed "/^{V2}/d" <exp.raw >exp
85+
else
86+
sed "s/^{V2} //" <exp.raw >exp
87+
fi &&
88+
89+
GIT_TRACE_CURL=true LANGUAGE="ko_KR.UTF-8" \
5990
git clone --quiet $HTTPD_URL/smart/repo.git clone 2>err &&
6091
test_cmp file clone/file &&
6192
tr '\''\015'\'' Q <err |
93+
perl -pe '\''
94+
s/(Send|Recv) header: ([A-Za-z0-9-]+):/
95+
"$1 header: " . lc($2) . ":"
96+
/e;
97+
'\'' |
6298
sed -e "
6399
s/Q\$//
64-
/^[*] /d
100+
/^[^<=]/d
65101
/^== Info:/d
66102
/^=> Send header, /d
67103
/^=> Send header:$/d
@@ -71,43 +107,44 @@ test_expect_success 'clone http repository' '
71107
s/= Recv header://
72108
/^<= Recv data/d
73109
/^=> Send data/d
110+
/^<= Recv SSL data/d
111+
/^=> Send SSL data/d
74112
/^$/d
75113
/^< $/d
76114
77115
/^[^><]/{
78116
s/^/> /
79117
}
80118
81-
/^> User-Agent: /d
82-
/^> Host: /d
119+
/^< HTTP/ {
120+
s/200$/200 OK/
121+
}
122+
/^< HTTP\\/1.1 101/d
123+
/^[><] connection: /d
124+
/^[><] upgrade: /d
125+
/^> http2-settings: /d
126+
127+
/^> user-agent: /d
128+
/^> host: /d
83129
/^> POST /,$ {
84130
/^> Accept: [*]\\/[*]/d
85131
}
86-
s/^> Content-Length: .*/> Content-Length: xxx/
132+
s/^> content-length: .*/> content-length: xxx/
87133
/^> 00..want /d
88134
/^> 00.*done/d
89135
90-
/^< Server: /d
91-
/^< Expires: /d
92-
/^< Date: /d
93-
/^< Content-Length: /d
94-
/^< Transfer-Encoding: /d
136+
/^< server: /d
137+
/^< expires: /d
138+
/^< date: /d
139+
/^< content-length: /d
140+
/^< transfer-encoding: /d
95141
" >actual &&
96142
97-
# NEEDSWORK: If the overspecification of the expected result is reduced, we
98-
# might be able to run this test in all protocol versions.
99-
if test "$GIT_TEST_PROTOCOL_VERSION" = 0
100-
then
101-
sed -e "s/^> Accept-Encoding: .*/> Accept-Encoding: ENCODINGS/" \
102-
actual >actual.smudged &&
103-
test_cmp exp actual.smudged &&
104-
105-
grep "Accept-Encoding:.*gzip" actual >actual.gzip &&
106-
test_line_count = 2 actual.gzip &&
143+
sed -e "s/^> accept-encoding: .*/> accept-encoding: ENCODINGS/" \
144+
actual >actual.smudged &&
145+
test_cmp exp actual.smudged &&
107146
108-
grep "Accept-Language: ko-KR, *" actual >actual.language &&
109-
test_line_count = 2 actual.language
110-
fi
147+
grep "accept-encoding:.*gzip" actual >actual.gzip
111148
'
112149

113150
test_expect_success 'fetch changes via http' '
@@ -119,19 +156,9 @@ test_expect_success 'fetch changes via http' '
119156
'
120157

121158
test_expect_success 'used upload-pack service' '
122-
cat >exp <<-\EOF &&
123-
GET /smart/repo.git/info/refs?service=git-upload-pack HTTP/1.1 200
124-
POST /smart/repo.git/git-upload-pack HTTP/1.1 200
125-
GET /smart/repo.git/info/refs?service=git-upload-pack HTTP/1.1 200
126-
POST /smart/repo.git/git-upload-pack HTTP/1.1 200
127-
EOF
128-
129-
# NEEDSWORK: If the overspecification of the expected result is reduced, we
130-
# might be able to run this test in all protocol versions.
131-
if test "$GIT_TEST_PROTOCOL_VERSION" = 0
132-
then
133-
check_access_log exp
134-
fi
159+
strip_access_log >log &&
160+
grep "GET /smart/repo.git/info/refs?service=git-upload-pack HTTP/[0-9.]* 200" log &&
161+
grep "POST /smart/repo.git/git-upload-pack HTTP/[0-9.]* 200" log
135162
'
136163

137164
test_expect_success 'follow redirects (301)' '
@@ -280,21 +307,23 @@ test_expect_success 'cookies stored in http.cookiefile when http.savecookies set
280307
127.0.0.1 FALSE /smart_cookies/ FALSE 0 othername othervalue
281308
EOF
282309
sort >expect_cookies.txt <<-\EOF &&
283-
284310
127.0.0.1 FALSE /smart_cookies/ FALSE 0 othername othervalue
311+
127.0.0.1 FALSE /smart_cookies/repo.git/ FALSE 0 name value
285312
127.0.0.1 FALSE /smart_cookies/repo.git/info/ FALSE 0 name value
286313
EOF
287314
git config http.cookiefile cookies.txt &&
288315
git config http.savecookies true &&
289-
git ls-remote $HTTPD_URL/smart_cookies/repo.git main &&
290316
291-
# NEEDSWORK: If the overspecification of the expected result is reduced, we
292-
# might be able to run this test in all protocol versions.
293-
if test "$GIT_TEST_PROTOCOL_VERSION" = 0
294-
then
295-
tail -3 cookies.txt | sort >cookies_tail.txt &&
296-
test_cmp expect_cookies.txt cookies_tail.txt
297-
fi
317+
test_when_finished "
318+
git --git-dir=\"\$HTTPD_DOCUMENT_ROOT_PATH/repo.git\" \
319+
tag -d cookie-tag
320+
" &&
321+
git --git-dir="$HTTPD_DOCUMENT_ROOT_PATH/repo.git" \
322+
tag -m "foo" cookie-tag &&
323+
git fetch $HTTPD_URL/smart_cookies/repo.git cookie-tag &&
324+
325+
grep "^[^#]" cookies.txt | sort >cookies_stripped.txt &&
326+
test_cmp expect_cookies.txt cookies_stripped.txt
298327
'
299328

300329
test_expect_success 'transfer.hiderefs works over smart-http' '
@@ -666,4 +695,13 @@ test_expect_success 'push warns or fails when using username:password' '
666695
test_line_count -ge 1 warnings
667696
'
668697

698+
test_expect_success 'no empty path components' '
699+
# In the URL, add a trailing slash, and see if git appends yet another
700+
# slash.
701+
git clone $HTTPD_URL/smart/repo.git/ clone-with-slash &&
702+
703+
strip_access_log >log &&
704+
! grep "//" log
705+
'
706+
669707
test_done

t/t5559-http-fetch-smart-http2.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#!/bin/sh
22

33
HTTP_PROTO=HTTP/2
4+
LIB_HTTPD_SSL=1
45
. ./t5551-http-fetch-smart.sh

0 commit comments

Comments
 (0)