1
1
#! /bin/sh
2
2
3
- : ${HTTP_PROTO:= HTTP}
3
+ : ${HTTP_PROTO:= HTTP/ 1.1 }
4
4
test_description=" test smart fetching over http via http-backend ($HTTP_PROTO )"
5
5
GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
6
6
export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
@@ -33,35 +33,71 @@ test_expect_success 'create http-accessible bare repository' '
33
33
setup_askpass_helper
34
34
35
35
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
56
80
EOF
57
81
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" \
59
90
git clone --quiet $HTTPD_URL/smart/repo.git clone 2>err &&
60
91
test_cmp file clone/file &&
61
92
tr ' \' ' \015' \' ' Q <err |
93
+ perl -pe ' \' '
94
+ s/(Send|Recv) header: ([A-Za-z0-9-]+):/
95
+ "$1 header: " . lc($2) . ":"
96
+ /e;
97
+ ' \' ' |
62
98
sed -e "
63
99
s/Q\$//
64
- /^[*] /d
100
+ /^[^<=] /d
65
101
/^== Info:/d
66
102
/^=> Send header, /d
67
103
/^=> Send header:$/d
@@ -71,43 +107,44 @@ test_expect_success 'clone http repository' '
71
107
s/= Recv header://
72
108
/^<= Recv data/d
73
109
/^=> Send data/d
110
+ /^<= Recv SSL data/d
111
+ /^=> Send SSL data/d
74
112
/^$/d
75
113
/^< $/d
76
114
77
115
/^[^><]/{
78
116
s/^/> /
79
117
}
80
118
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
83
129
/^> POST /,$ {
84
130
/^> Accept: [*]\\/[*]/d
85
131
}
86
- s/^> Content-Length : .*/> Content-Length : xxx/
132
+ s/^> content-length : .*/> content-length : xxx/
87
133
/^> 00..want /d
88
134
/^> 00.*done/d
89
135
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
95
141
" >actual &&
96
142
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 &&
107
146
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
111
148
'
112
149
113
150
test_expect_success ' fetch changes via http' '
@@ -119,19 +156,9 @@ test_expect_success 'fetch changes via http' '
119
156
'
120
157
121
158
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
135
162
'
136
163
137
164
test_expect_success ' follow redirects (301)' '
@@ -280,21 +307,23 @@ test_expect_success 'cookies stored in http.cookiefile when http.savecookies set
280
307
127.0.0.1 FALSE /smart_cookies/ FALSE 0 othername othervalue
281
308
EOF
282
309
sort >expect_cookies.txt <<-\EOF &&
283
-
284
310
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
285
312
127.0.0.1 FALSE /smart_cookies/repo.git/info/ FALSE 0 name value
286
313
EOF
287
314
git config http.cookiefile cookies.txt &&
288
315
git config http.savecookies true &&
289
- git ls-remote $HTTPD_URL/smart_cookies/repo.git main &&
290
316
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
298
327
'
299
328
300
329
test_expect_success ' transfer.hiderefs works over smart-http' '
@@ -666,4 +695,13 @@ test_expect_success 'push warns or fails when using username:password' '
666
695
test_line_count -ge 1 warnings
667
696
'
668
697
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
+
669
707
test_done
0 commit comments