2009-10-31 08:47:47 +08:00
|
|
|
#!/bin/sh
|
|
|
|
|
|
|
|
test_description='test smart fetching over http via http-backend'
|
|
|
|
. ./test-lib.sh
|
|
|
|
|
|
|
|
if test -n "$NO_CURL"; then
|
2010-06-25 01:44:48 +08:00
|
|
|
skip_all='skipping test, git built without http support'
|
2009-10-31 08:47:47 +08:00
|
|
|
test_done
|
|
|
|
fi
|
|
|
|
|
|
|
|
. "$TEST_DIRECTORY"/lib-httpd.sh
|
|
|
|
start_httpd
|
|
|
|
|
|
|
|
test_expect_success 'setup repository' '
|
2013-01-16 10:05:07 +08:00
|
|
|
git config push.default matching &&
|
2009-10-31 08:47:47 +08:00
|
|
|
echo content >file &&
|
|
|
|
git add file &&
|
|
|
|
git commit -m one
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'create http-accessible bare repository' '
|
|
|
|
mkdir "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" &&
|
|
|
|
(cd "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" &&
|
|
|
|
git --bare init
|
|
|
|
) &&
|
|
|
|
git remote add public "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" &&
|
|
|
|
git push public master:master
|
|
|
|
'
|
|
|
|
|
2012-08-27 21:25:36 +08:00
|
|
|
setup_askpass_helper
|
|
|
|
|
2009-10-31 08:47:47 +08:00
|
|
|
cat >exp <<EOF
|
|
|
|
> GET /smart/repo.git/info/refs?service=git-upload-pack HTTP/1.1
|
|
|
|
> Accept: */*
|
2012-09-20 07:12:02 +08:00
|
|
|
> Accept-Encoding: gzip
|
2009-10-31 08:47:47 +08:00
|
|
|
> Pragma: no-cache
|
|
|
|
< HTTP/1.1 200 OK
|
|
|
|
< Pragma: no-cache
|
|
|
|
< Cache-Control: no-cache, max-age=0, must-revalidate
|
|
|
|
< Content-Type: application/x-git-upload-pack-advertisement
|
|
|
|
> POST /smart/repo.git/git-upload-pack HTTP/1.1
|
2012-09-20 07:12:02 +08:00
|
|
|
> Accept-Encoding: gzip
|
2009-10-31 08:47:47 +08:00
|
|
|
> Content-Type: application/x-git-upload-pack-request
|
2010-01-13 01:54:04 +08:00
|
|
|
> Accept: application/x-git-upload-pack-result
|
2009-10-31 08:47:47 +08:00
|
|
|
> Content-Length: xxx
|
|
|
|
< HTTP/1.1 200 OK
|
|
|
|
< Pragma: no-cache
|
|
|
|
< Cache-Control: no-cache, max-age=0, must-revalidate
|
|
|
|
< Content-Type: application/x-git-upload-pack-result
|
|
|
|
EOF
|
|
|
|
test_expect_success 'clone http repository' '
|
|
|
|
GIT_CURL_VERBOSE=1 git clone --quiet $HTTPD_URL/smart/repo.git clone 2>err &&
|
|
|
|
test_cmp file clone/file &&
|
|
|
|
tr '\''\015'\'' Q <err |
|
|
|
|
sed -e "
|
|
|
|
s/Q\$//
|
|
|
|
/^[*] /d
|
2009-11-10 02:10:36 +08:00
|
|
|
/^$/d
|
|
|
|
/^< $/d
|
2009-10-31 08:47:47 +08:00
|
|
|
|
|
|
|
/^[^><]/{
|
|
|
|
s/^/> /
|
|
|
|
}
|
|
|
|
|
|
|
|
/^> User-Agent: /d
|
|
|
|
/^> Host: /d
|
2009-11-10 02:10:37 +08:00
|
|
|
/^> POST /,$ {
|
|
|
|
/^> Accept: [*]\\/[*]/d
|
|
|
|
}
|
2009-10-31 08:47:47 +08:00
|
|
|
s/^> Content-Length: .*/> Content-Length: xxx/
|
2009-11-10 02:10:36 +08:00
|
|
|
/^> 00..want /d
|
|
|
|
/^> 00.*done/d
|
2009-10-31 08:47:47 +08:00
|
|
|
|
|
|
|
/^< Server: /d
|
|
|
|
/^< Expires: /d
|
|
|
|
/^< Date: /d
|
|
|
|
/^< Content-Length: /d
|
|
|
|
/^< Transfer-Encoding: /d
|
|
|
|
" >act &&
|
|
|
|
test_cmp exp act
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'fetch changes via http' '
|
|
|
|
echo content >>file &&
|
|
|
|
git commit -a -m two &&
|
|
|
|
git push public
|
|
|
|
(cd clone && git pull) &&
|
|
|
|
test_cmp file clone/file
|
|
|
|
'
|
|
|
|
|
|
|
|
cat >exp <<EOF
|
|
|
|
GET /smart/repo.git/info/refs?service=git-upload-pack HTTP/1.1 200
|
|
|
|
POST /smart/repo.git/git-upload-pack HTTP/1.1 200
|
|
|
|
GET /smart/repo.git/info/refs?service=git-upload-pack HTTP/1.1 200
|
|
|
|
POST /smart/repo.git/git-upload-pack HTTP/1.1 200
|
|
|
|
EOF
|
|
|
|
test_expect_success 'used upload-pack service' '
|
|
|
|
sed -e "
|
|
|
|
s/^.* \"//
|
|
|
|
s/\"//
|
|
|
|
s/ [1-9][0-9]*\$//
|
|
|
|
s/^GET /GET /
|
|
|
|
" >act <"$HTTPD_ROOT_PATH"/access.log &&
|
|
|
|
test_cmp exp act
|
|
|
|
'
|
|
|
|
|
2010-09-25 12:20:35 +08:00
|
|
|
test_expect_success 'follow redirects (301)' '
|
|
|
|
git clone $HTTPD_URL/smart-redir-perm/repo.git --quiet repo-p
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'follow redirects (302)' '
|
|
|
|
git clone $HTTPD_URL/smart-redir-temp/repo.git --quiet repo-t
|
|
|
|
'
|
|
|
|
|
remote-curl: rewrite base url from info/refs redirects
For efficiency and security reasons, an earlier commit in
this series taught http_get_* to re-write the base url based
on redirections we saw while making a specific request.
This commit wires that option into the info/refs request,
meaning that a redirect from
http://example.com/foo.git/info/refs
to
https://example.com/bar.git/info/refs
will behave as if "https://example.com/bar.git" had been
provided to git in the first place.
The tests bear some explanation. We introduce two new
hierearchies into the httpd test config:
1. Requests to /smart-redir-limited will work only for the
initial info/refs request, but not any subsequent
requests. As a result, we can confirm whether the
client is re-rooting its requests after the initial
contact, since otherwise it will fail (it will ask for
"repo.git/git-upload-pack", which is not redirected).
2. Requests to smart-redir-auth will redirect, and require
auth after the redirection. Since we are using the
redirected base for further requests, we also update
the credential struct, in order not to mislead the user
(or credential helpers) about which credential is
needed. We can therefore check the GIT_ASKPASS prompts
to make sure we are prompting for the new location.
Because we have neither multiple servers nor https
support in our test setup, we can only redirect between
paths, meaning we need to turn on
credential.useHttpPath to see the difference.
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
2013-09-28 16:35:35 +08:00
|
|
|
test_expect_success 'redirects re-root further requests' '
|
|
|
|
git clone $HTTPD_URL/smart-redir-limited/repo.git repo-redir-limited
|
|
|
|
'
|
|
|
|
|
2012-08-27 21:25:36 +08:00
|
|
|
test_expect_success 'clone from password-protected repository' '
|
|
|
|
echo two >expect &&
|
2014-01-02 15:38:35 +08:00
|
|
|
set_askpass user@host pass@host &&
|
2012-08-27 21:25:36 +08:00
|
|
|
git clone --bare "$HTTPD_URL/auth/smart/repo.git" smart-auth &&
|
|
|
|
expect_askpass both user@host &&
|
|
|
|
git --git-dir=smart-auth log -1 --format=%s >actual &&
|
|
|
|
test_cmp expect actual
|
|
|
|
'
|
|
|
|
|
2012-08-27 21:25:53 +08:00
|
|
|
test_expect_success 'clone from auth-only-for-push repository' '
|
|
|
|
echo two >expect &&
|
|
|
|
set_askpass wrong &&
|
|
|
|
git clone --bare "$HTTPD_URL/auth-push/smart/repo.git" smart-noauth &&
|
|
|
|
expect_askpass none &&
|
|
|
|
git --git-dir=smart-noauth log -1 --format=%s >actual &&
|
|
|
|
test_cmp expect actual
|
|
|
|
'
|
|
|
|
|
remote-curl: retry failed requests for auth even with gzip
Commit b81401c taught the post_rpc function to retry the
http request after prompting for credentials. However, it
did not handle two cases:
1. If we have a large request, we do not retry. That's OK,
since we would have sent a probe (with retry) already.
2. If we are gzipping the request, we do not retry. That
was considered OK, because the intended use was for
push (e.g., listing refs is OK, but actually pushing
objects is not), and we never gzip on push.
This patch teaches post_rpc to retry even a gzipped request.
This has two advantages:
1. It is possible to configure a "half-auth" state for
fetching, where the set of refs and their sha1s are
advertised, but one cannot actually fetch objects.
This is not a recommended configuration, as it leaks
some information about what is in the repository (e.g.,
an attacker can try brute-forcing possible content in
your repository and checking whether it matches your
branch sha1). However, it can be slightly more
convenient, since a no-op fetch will not require a
password at all.
2. It future-proofs us should we decide to ever gzip more
requests.
Signed-off-by: Jeff King <peff@peff.net>
2012-10-31 19:29:16 +08:00
|
|
|
test_expect_success 'clone from auth-only-for-objects repository' '
|
|
|
|
echo two >expect &&
|
2014-01-02 15:38:35 +08:00
|
|
|
set_askpass user@host pass@host &&
|
remote-curl: retry failed requests for auth even with gzip
Commit b81401c taught the post_rpc function to retry the
http request after prompting for credentials. However, it
did not handle two cases:
1. If we have a large request, we do not retry. That's OK,
since we would have sent a probe (with retry) already.
2. If we are gzipping the request, we do not retry. That
was considered OK, because the intended use was for
push (e.g., listing refs is OK, but actually pushing
objects is not), and we never gzip on push.
This patch teaches post_rpc to retry even a gzipped request.
This has two advantages:
1. It is possible to configure a "half-auth" state for
fetching, where the set of refs and their sha1s are
advertised, but one cannot actually fetch objects.
This is not a recommended configuration, as it leaks
some information about what is in the repository (e.g.,
an attacker can try brute-forcing possible content in
your repository and checking whether it matches your
branch sha1). However, it can be slightly more
convenient, since a no-op fetch will not require a
password at all.
2. It future-proofs us should we decide to ever gzip more
requests.
Signed-off-by: Jeff King <peff@peff.net>
2012-10-31 19:29:16 +08:00
|
|
|
git clone --bare "$HTTPD_URL/auth-fetch/smart/repo.git" half-auth &&
|
|
|
|
expect_askpass both user@host &&
|
|
|
|
git --git-dir=half-auth log -1 --format=%s >actual &&
|
|
|
|
test_cmp expect actual
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'no-op half-auth fetch does not require a password' '
|
|
|
|
set_askpass wrong &&
|
|
|
|
git --git-dir=half-auth fetch &&
|
|
|
|
expect_askpass none
|
|
|
|
'
|
|
|
|
|
remote-curl: rewrite base url from info/refs redirects
For efficiency and security reasons, an earlier commit in
this series taught http_get_* to re-write the base url based
on redirections we saw while making a specific request.
This commit wires that option into the info/refs request,
meaning that a redirect from
http://example.com/foo.git/info/refs
to
https://example.com/bar.git/info/refs
will behave as if "https://example.com/bar.git" had been
provided to git in the first place.
The tests bear some explanation. We introduce two new
hierearchies into the httpd test config:
1. Requests to /smart-redir-limited will work only for the
initial info/refs request, but not any subsequent
requests. As a result, we can confirm whether the
client is re-rooting its requests after the initial
contact, since otherwise it will fail (it will ask for
"repo.git/git-upload-pack", which is not redirected).
2. Requests to smart-redir-auth will redirect, and require
auth after the redirection. Since we are using the
redirected base for further requests, we also update
the credential struct, in order not to mislead the user
(or credential helpers) about which credential is
needed. We can therefore check the GIT_ASKPASS prompts
to make sure we are prompting for the new location.
Because we have neither multiple servers nor https
support in our test setup, we can only redirect between
paths, meaning we need to turn on
credential.useHttpPath to see the difference.
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
2013-09-28 16:35:35 +08:00
|
|
|
test_expect_success 'redirects send auth to new location' '
|
2014-01-02 15:38:35 +08:00
|
|
|
set_askpass user@host pass@host &&
|
remote-curl: rewrite base url from info/refs redirects
For efficiency and security reasons, an earlier commit in
this series taught http_get_* to re-write the base url based
on redirections we saw while making a specific request.
This commit wires that option into the info/refs request,
meaning that a redirect from
http://example.com/foo.git/info/refs
to
https://example.com/bar.git/info/refs
will behave as if "https://example.com/bar.git" had been
provided to git in the first place.
The tests bear some explanation. We introduce two new
hierearchies into the httpd test config:
1. Requests to /smart-redir-limited will work only for the
initial info/refs request, but not any subsequent
requests. As a result, we can confirm whether the
client is re-rooting its requests after the initial
contact, since otherwise it will fail (it will ask for
"repo.git/git-upload-pack", which is not redirected).
2. Requests to smart-redir-auth will redirect, and require
auth after the redirection. Since we are using the
redirected base for further requests, we also update
the credential struct, in order not to mislead the user
(or credential helpers) about which credential is
needed. We can therefore check the GIT_ASKPASS prompts
to make sure we are prompting for the new location.
Because we have neither multiple servers nor https
support in our test setup, we can only redirect between
paths, meaning we need to turn on
credential.useHttpPath to see the difference.
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
2013-09-28 16:35:35 +08:00
|
|
|
git -c credential.useHttpPath=true \
|
|
|
|
clone $HTTPD_URL/smart-redir-auth/repo.git repo-redir-auth &&
|
|
|
|
expect_askpass both user@host auth/smart/repo.git
|
|
|
|
'
|
|
|
|
|
2012-09-21 05:30:58 +08:00
|
|
|
test_expect_success 'disable dumb http on server' '
|
|
|
|
git --git-dir="$HTTPD_DOCUMENT_ROOT_PATH/repo.git" \
|
|
|
|
config http.getanyfile false
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'GIT_SMART_HTTP can disable smart http' '
|
|
|
|
(GIT_SMART_HTTP=0 &&
|
|
|
|
export GIT_SMART_HTTP &&
|
|
|
|
cd clone &&
|
|
|
|
test_must_fail git fetch)
|
|
|
|
'
|
|
|
|
|
2013-02-01 05:02:07 +08:00
|
|
|
test_expect_success 'invalid Content-Type rejected' '
|
|
|
|
test_must_fail git clone $HTTPD_URL/broken_smart/repo.git 2>actual
|
2013-02-05 08:21:42 +08:00
|
|
|
grep "not valid:" actual
|
2013-02-01 05:02:07 +08:00
|
|
|
'
|
|
|
|
|
2013-04-10 08:55:08 +08:00
|
|
|
test_expect_success 'create namespaced refs' '
|
|
|
|
test_commit namespaced &&
|
|
|
|
git push public HEAD:refs/namespaces/ns/refs/heads/master &&
|
|
|
|
git --git-dir="$HTTPD_DOCUMENT_ROOT_PATH/repo.git" \
|
|
|
|
symbolic-ref refs/namespaces/ns/HEAD refs/namespaces/ns/refs/heads/master
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'smart clone respects namespace' '
|
|
|
|
git clone "$HTTPD_URL/smart_namespace/repo.git" ns-smart &&
|
|
|
|
echo namespaced >expect &&
|
|
|
|
git --git-dir=ns-smart/.git log -1 --format=%s >actual &&
|
|
|
|
test_cmp expect actual
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'dumb clone via http-backend respects namespace' '
|
|
|
|
git --git-dir="$HTTPD_DOCUMENT_ROOT_PATH/repo.git" \
|
|
|
|
config http.getanyfile true &&
|
|
|
|
GIT_SMART_HTTP=0 git clone \
|
|
|
|
"$HTTPD_URL/smart_namespace/repo.git" ns-dumb &&
|
|
|
|
echo namespaced >expect &&
|
|
|
|
git --git-dir=ns-dumb/.git log -1 --format=%s >actual &&
|
|
|
|
test_cmp expect actual
|
|
|
|
'
|
|
|
|
|
2013-07-24 06:40:17 +08:00
|
|
|
cat >cookies.txt <<EOF
|
|
|
|
127.0.0.1 FALSE /smart_cookies/ FALSE 0 othername othervalue
|
|
|
|
EOF
|
|
|
|
cat >expect_cookies.txt <<EOF
|
|
|
|
|
|
|
|
127.0.0.1 FALSE /smart_cookies/ FALSE 0 othername othervalue
|
|
|
|
127.0.0.1 FALSE /smart_cookies/repo.git/info/ FALSE 0 name value
|
|
|
|
EOF
|
|
|
|
test_expect_success 'cookies stored in http.cookiefile when http.savecookies set' '
|
|
|
|
git config http.cookiefile cookies.txt &&
|
|
|
|
git config http.savecookies true &&
|
|
|
|
git ls-remote $HTTPD_URL/smart_cookies/repo.git master &&
|
2013-08-05 23:59:24 +08:00
|
|
|
tail -3 cookies.txt > cookies_tail.txt
|
|
|
|
test_cmp expect_cookies.txt cookies_tail.txt
|
2013-07-24 06:40:17 +08:00
|
|
|
'
|
|
|
|
|
2012-04-02 23:17:03 +08:00
|
|
|
test_expect_success EXPENSIVE 'create 50,000 tags in the repo' '
|
|
|
|
(
|
|
|
|
cd "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" &&
|
2012-08-04 06:21:04 +08:00
|
|
|
for i in `test_seq 50000`
|
2012-04-02 23:17:03 +08:00
|
|
|
do
|
|
|
|
echo "commit refs/heads/too-many-refs"
|
|
|
|
echo "mark :$i"
|
|
|
|
echo "committer git <git@example.com> $i +0000"
|
|
|
|
echo "data 0"
|
|
|
|
echo "M 644 inline bla.txt"
|
|
|
|
echo "data 4"
|
|
|
|
echo "bla"
|
|
|
|
# make every commit dangling by always
|
|
|
|
# rewinding the branch after each commit
|
|
|
|
echo "reset refs/heads/too-many-refs"
|
|
|
|
echo "from :1"
|
|
|
|
done | git fast-import --export-marks=marks &&
|
|
|
|
|
|
|
|
# now assign tags to all the dangling commits we created above
|
2013-10-29 09:23:03 +08:00
|
|
|
tag=$(perl -e "print \"bla\" x 30") &&
|
2013-05-13 06:50:59 +08:00
|
|
|
sed -e "s|^:\([^ ]*\) \(.*\)$|\2 refs/tags/$tag-\1|" <marks >>packed-refs
|
2012-04-02 23:17:03 +08:00
|
|
|
)
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success EXPENSIVE 'clone the 50,000 tag repo to check OS command line overflow' '
|
2014-06-06 05:36:21 +08:00
|
|
|
git clone $HTTPD_URL/smart/repo.git too-many-refs &&
|
2013-05-13 06:50:59 +08:00
|
|
|
(
|
|
|
|
cd too-many-refs &&
|
|
|
|
test $(git for-each-ref refs/tags | wc -l) = 50000
|
|
|
|
)
|
2012-04-02 23:17:03 +08:00
|
|
|
'
|
|
|
|
|
2009-10-31 08:47:47 +08:00
|
|
|
stop_httpd
|
|
|
|
test_done
|