Skip to content

Commit 7da4e22

Browse files
spearcegitster
authored andcommitted
test smart http fetch and push
The top level directory "/smart/" of the test Apache server is mapped through our git-http-backend CGI, but uses the same underlying repository space as the server's document root. This is the most simple installation possible. Server logs are checked to verify the client has accessed only the smart URLs during the test. During fetch testing the headers are also logged from libcurl to ensure we are making a reasonably sane HTTP request, and getting back reasonably sane response headers from the CGI. When validating the request headers used during smart fetch we munge away the actual Content-Length and replace it with the placeholder "xxx". This avoids unnecessary varability in the test caused by an unrelated change in the requested capabilities in the first want line of the request. However, we still want to look for and verify that Content-Length was used, because smaller payloads should be using Content-Length and not "Transfer-Encoding: chunked". When validating the server response headers we must discard both Content-Length and Transfer-Encoding, as Apache2 can use either format to return our response. During development of this test I observed Apache returning both forms, depending on when the processes got CPU time. If our CGI returned the pack data quickly, Apache just buffered the whole thing and returned a Content-Length. If our CGI took just a bit too long to complete, Apache flushed its buffer and instead used "Transfer-Encoding: chunked". Signed-off-by: Shawn O. Pearce <spearce@spearce.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 024bb12 commit 7da4e22

File tree

5 files changed

+219
-2
lines changed

5 files changed

+219
-2
lines changed

t/lib-httpd/apache.conf

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,26 @@ ErrorLog error.log
1111
<IfModule !mod_alias.c>
1212
LoadModule alias_module modules/mod_alias.so
1313
</IfModule>
14+
<IfModule !mod_cgi.c>
15+
LoadModule cgi_module modules/mod_cgi.so
16+
</IfModule>
17+
<IfModule !mod_env.c>
18+
LoadModule env_module modules/mod_env.so
19+
</IfModule>
1420

1521
Alias /dumb/ www/
1622

23+
<Location /smart/>
24+
SetEnv GIT_EXEC_PATH ${GIT_EXEC_PATH}
25+
</Location>
26+
ScriptAlias /smart/ ${GIT_EXEC_PATH}/git-http-backend/
27+
<Directory ${GIT_EXEC_PATH}>
28+
Options None
29+
</Directory>
30+
<Files ${GIT_EXEC_PATH}/git-http-backend>
31+
Options ExecCGI
32+
</Files>
33+
1734
<IfDefine SSL>
1835
LoadModule ssl_module modules/mod_ssl.so
1936

t/t5540-http-push.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# Copyright (c) 2008 Clemens Buchacher <drizzd@aon.at>
44
#
55

6-
test_description='test http-push
6+
test_description='test WebDAV http-push
77
88
This test runs various sanity checks on http-push.'
99

t/t5541-http-push.sh

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
#!/bin/sh
2+
#
3+
# Copyright (c) 2008 Clemens Buchacher <drizzd@aon.at>
4+
#
5+
6+
test_description='test smart pushing over http via http-backend'
7+
. ./test-lib.sh
8+
9+
if test -n "$NO_CURL"; then
10+
say 'skipping test, git built without http support'
11+
test_done
12+
fi
13+
14+
ROOT_PATH="$PWD"
15+
LIB_HTTPD_PORT=${LIB_HTTPD_PORT-'5541'}
16+
. "$TEST_DIRECTORY"/lib-httpd.sh
17+
start_httpd
18+
19+
test_expect_success 'setup remote repository' '
20+
cd "$ROOT_PATH" &&
21+
mkdir test_repo &&
22+
cd test_repo &&
23+
git init &&
24+
: >path1 &&
25+
git add path1 &&
26+
test_tick &&
27+
git commit -m initial &&
28+
cd - &&
29+
git clone --bare test_repo test_repo.git &&
30+
cd test_repo.git &&
31+
git config http.receivepack true &&
32+
ORIG_HEAD=$(git rev-parse --verify HEAD) &&
33+
cd - &&
34+
mv test_repo.git "$HTTPD_DOCUMENT_ROOT_PATH"
35+
'
36+
37+
test_expect_success 'clone remote repository' '
38+
cd "$ROOT_PATH" &&
39+
git clone $HTTPD_URL/smart/test_repo.git test_repo_clone
40+
'
41+
42+
test_expect_success 'push to remote repository' '
43+
cd "$ROOT_PATH"/test_repo_clone &&
44+
: >path2 &&
45+
git add path2 &&
46+
test_tick &&
47+
git commit -m path2 &&
48+
HEAD=$(git rev-parse --verify HEAD) &&
49+
git push &&
50+
(cd "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo.git &&
51+
test $HEAD = $(git rev-parse --verify HEAD))
52+
'
53+
54+
test_expect_success 'push already up-to-date' '
55+
git push
56+
'
57+
58+
test_expect_success 'create and delete remote branch' '
59+
cd "$ROOT_PATH"/test_repo_clone &&
60+
git checkout -b dev &&
61+
: >path3 &&
62+
git add path3 &&
63+
test_tick &&
64+
git commit -m dev &&
65+
git push origin dev &&
66+
git push origin :dev &&
67+
test_must_fail git show-ref --verify refs/remotes/origin/dev
68+
'
69+
70+
cat >exp <<EOF
71+
GET /smart/test_repo.git/info/refs?service=git-upload-pack HTTP/1.1 200
72+
POST /smart/test_repo.git/git-upload-pack HTTP/1.1 200
73+
GET /smart/test_repo.git/info/refs?service=git-receive-pack HTTP/1.1 200
74+
POST /smart/test_repo.git/git-receive-pack HTTP/1.1 200
75+
GET /smart/test_repo.git/info/refs?service=git-receive-pack HTTP/1.1 200
76+
GET /smart/test_repo.git/info/refs?service=git-receive-pack HTTP/1.1 200
77+
POST /smart/test_repo.git/git-receive-pack HTTP/1.1 200
78+
GET /smart/test_repo.git/info/refs?service=git-receive-pack HTTP/1.1 200
79+
POST /smart/test_repo.git/git-receive-pack HTTP/1.1 200
80+
EOF
81+
test_expect_success 'used receive-pack service' '
82+
sed -e "
83+
s/^.* \"//
84+
s/\"//
85+
s/ [1-9][0-9]*\$//
86+
s/^GET /GET /
87+
" >act <"$HTTPD_ROOT_PATH"/access.log &&
88+
test_cmp exp act
89+
'
90+
91+
stop_httpd
92+
test_done

t/t5550-http-fetch.sh

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

3-
test_description='test fetching over http'
3+
test_description='test dumb fetching over http via static file'
44
. ./test-lib.sh
55

66
if test -n "$NO_CURL"; then
@@ -61,5 +61,11 @@ test_expect_success 'fetch packed objects' '
6161
git clone $HTTPD_URL/dumb/repo_pack.git
6262
'
6363

64+
test_expect_success 'did not use upload-pack service' '
65+
grep '/git-upload-pack' <"$HTTPD_ROOT_PATH"/access.log >act
66+
: >exp
67+
test_cmp exp act
68+
'
69+
6470
stop_httpd
6571
test_done

t/t5551-http-fetch.sh

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
#!/bin/sh
2+
3+
test_description='test smart fetching over http via http-backend'
4+
. ./test-lib.sh
5+
6+
if test -n "$NO_CURL"; then
7+
say 'skipping test, git built without http support'
8+
test_done
9+
fi
10+
11+
LIB_HTTPD_PORT=${LIB_HTTPD_PORT-'5551'}
12+
. "$TEST_DIRECTORY"/lib-httpd.sh
13+
start_httpd
14+
15+
test_expect_success 'setup repository' '
16+
echo content >file &&
17+
git add file &&
18+
git commit -m one
19+
'
20+
21+
test_expect_success 'create http-accessible bare repository' '
22+
mkdir "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" &&
23+
(cd "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" &&
24+
git --bare init
25+
) &&
26+
git remote add public "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" &&
27+
git push public master:master
28+
'
29+
30+
cat >exp <<EOF
31+
> GET /smart/repo.git/info/refs?service=git-upload-pack HTTP/1.1
32+
> Accept: */*
33+
> Pragma: no-cache
34+
35+
< HTTP/1.1 200 OK
36+
< Pragma: no-cache
37+
< Cache-Control: no-cache, max-age=0, must-revalidate
38+
< Content-Type: application/x-git-upload-pack-advertisement
39+
<
40+
> POST /smart/repo.git/git-upload-pack HTTP/1.1
41+
> Accept-Encoding: deflate, gzip
42+
> Content-Type: application/x-git-upload-pack-request
43+
> Accept: application/x-git-upload-pack-response
44+
> Content-Length: xxx
45+
46+
< HTTP/1.1 200 OK
47+
< Pragma: no-cache
48+
< Cache-Control: no-cache, max-age=0, must-revalidate
49+
< Content-Type: application/x-git-upload-pack-result
50+
<
51+
EOF
52+
test_expect_success 'clone http repository' '
53+
GIT_CURL_VERBOSE=1 git clone --quiet $HTTPD_URL/smart/repo.git clone 2>err &&
54+
test_cmp file clone/file &&
55+
tr '\''\015'\'' Q <err |
56+
sed -e "
57+
s/Q\$//
58+
/^[*] /d
59+
60+
/^[^><]/{
61+
s/^/> /
62+
}
63+
64+
/^> User-Agent: /d
65+
/^> Host: /d
66+
s/^> Content-Length: .*/> Content-Length: xxx/
67+
68+
/^< Server: /d
69+
/^< Expires: /d
70+
/^< Date: /d
71+
/^< Content-Length: /d
72+
/^< Transfer-Encoding: /d
73+
" >act &&
74+
test_cmp exp act
75+
'
76+
77+
test_expect_success 'fetch changes via http' '
78+
echo content >>file &&
79+
git commit -a -m two &&
80+
git push public
81+
(cd clone && git pull) &&
82+
test_cmp file clone/file
83+
'
84+
85+
cat >exp <<EOF
86+
GET /smart/repo.git/info/refs?service=git-upload-pack HTTP/1.1 200
87+
POST /smart/repo.git/git-upload-pack HTTP/1.1 200
88+
GET /smart/repo.git/info/refs?service=git-upload-pack HTTP/1.1 200
89+
POST /smart/repo.git/git-upload-pack HTTP/1.1 200
90+
EOF
91+
test_expect_success 'used upload-pack service' '
92+
sed -e "
93+
s/^.* \"//
94+
s/\"//
95+
s/ [1-9][0-9]*\$//
96+
s/^GET /GET /
97+
" >act <"$HTTPD_ROOT_PATH"/access.log &&
98+
test_cmp exp act
99+
'
100+
101+
stop_httpd
102+
test_done

0 commit comments

Comments
 (0)