git/t/t5802-connect-helper.sh

102 строки
2.4 KiB
Bash
Исходник Обычный вид История

#!/bin/sh
test_description='ext::cmd remote "connect" helper'
. ./test-lib.sh
test_expect_success setup '
transport: add protocol policy config option Previously the `GIT_ALLOW_PROTOCOL` environment variable was used to specify a whitelist of protocols to be used in clone/fetch/push commands. This patch introduces new configuration options for more fine-grained control for allowing/disallowing protocols. This also has the added benefit of allowing easier construction of a protocol whitelist on systems where setting an environment variable is non-trivial. Now users can specify a policy to be used for each type of protocol via the 'protocol.<name>.allow' config option. A default policy for all unconfigured protocols can be set with the 'protocol.allow' config option. If no user configured default is made git will allow known-safe protocols (http, https, git, ssh, file), disallow known-dangerous protocols (ext), and have a default policy of `user` for all other protocols. The supported policies are `always`, `never`, and `user`. The `user` policy can be used to configure a protocol to be usable when explicitly used by a user, while disallowing it for commands which run clone/fetch/push commands without direct user intervention (e.g. recursive initialization of submodules). Commands which can potentially clone/fetch/push from untrusted repositories without user intervention can export `GIT_PROTOCOL_FROM_USER` with a value of '0' to prevent protocols configured to the `user` policy from being used. Fix remote-ext tests to use the new config to allow the ext protocol to be tested. Based on a patch by Jeff King <peff@peff.net> Signed-off-by: Brandon Williams <bmwill@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2016-12-15 01:39:52 +03:00
git config --global protocol.ext.allow user &&
test_tick &&
git commit --allow-empty -m initial &&
test_tick &&
git commit --allow-empty -m second &&
test_tick &&
git commit --allow-empty -m third &&
test_tick &&
git tag -a -m "tip three" three &&
test_tick &&
git commit --allow-empty -m fourth
'
test_expect_success clone '
cmd=$(echo "echo >&2 ext::sh invoked && %S .." | sed -e "s/ /% /g") &&
git clone "ext::sh -c %S% ." dst &&
git for-each-ref refs/heads/ refs/tags/ >expect &&
(
cd dst &&
git config remote.origin.url "ext::sh -c $cmd" &&
git for-each-ref refs/heads/ refs/tags/
) >actual &&
test_cmp expect actual
'
test_expect_success 'update following tag' '
test_tick &&
git commit --allow-empty -m fifth &&
test_tick &&
git tag -a -m "tip five" five &&
git for-each-ref refs/heads/ refs/tags/ >expect &&
(
cd dst &&
git pull &&
git for-each-ref refs/heads/ refs/tags/ >../actual
) &&
test_cmp expect actual
'
test_expect_success 'update backfilled tag' '
test_tick &&
git commit --allow-empty -m sixth &&
test_tick &&
git tag -a -m "tip two" two three^1 &&
git for-each-ref refs/heads/ refs/tags/ >expect &&
(
cd dst &&
git pull &&
git for-each-ref refs/heads/ refs/tags/ >../actual
) &&
test_cmp expect actual
'
test_expect_success 'update backfilled tag without primary transfer' '
test_tick &&
git tag -a -m "tip one " one two^1 &&
git for-each-ref refs/heads/ refs/tags/ >expect &&
(
cd dst &&
git pull &&
git for-each-ref refs/heads/ refs/tags/ >../actual
) &&
test_cmp expect actual
'
test_expect_success 'set up fake git-daemon' '
mkdir remote &&
git init --bare remote/one.git &&
mkdir remote/host &&
git init --bare remote/host/two.git &&
write_script fake-daemon <<-\EOF &&
git daemon --inetd \
--informative-errors \
--export-all \
--base-path="$TRASH_DIRECTORY/remote" \
--interpolated-path="$TRASH_DIRECTORY/remote/%H%D" \
"$TRASH_DIRECTORY/remote"
EOF
export TRASH_DIRECTORY &&
PATH=$TRASH_DIRECTORY:$PATH
'
test_expect_success 'ext command can connect to git daemon (no vhost)' '
rm -rf dst &&
git clone "ext::fake-daemon %G/one.git" dst
'
test_expect_success 'ext command can connect to git daemon (vhost)' '
rm -rf dst &&
git clone "ext::fake-daemon %G/two.git %Vhost" dst
'
test_done