git-lfs/t/t-ssh.sh

64 lines
1.5 KiB
Bash
Raw Normal View History

#!/usr/bin/env bash
. "$(dirname "$0")/testlib.sh"
begin_test "ssh with proxy command in lfs.url (default variant)"
(
set -e
reponame="batch-ssh-proxy-default"
setup_remote_repo "$reponame"
clone_repo "$reponame" "$reponame"
sshurl="${GITSERVER/http:\/\//ssh://-oProxyCommand=ssh-proxy-test/}/$reponame"
git config lfs.url "$sshurl"
contents="test"
oid="$(calc_oid "$contents")"
git lfs track "*.dat"
printf "%s" "$contents" > test.dat
git add .gitattributes test.dat
git commit -m "initial commit"
unset GIT_SSH_VARIANT
t/cmd: expand functionality of lfs-ssh-echo Currently, the only thing that lfs-ssh-echo does is provide the output for git-lfs-authenticate. However, in the future, we'll want to support git-lfs-transfer, and for our testing functionality, we'll want to pretend to have an SSH transport for cloning and pushing. In order to do so, let's refactor out some code. Let's plan to spawn a shell with the argument if we get a Git command or a git-lfs-transfer command, and let's make things work properly on both Unix (where we'll want sh) and Windows (where sh is not always available but we can rely on bash). Let's also gracefully handle the fact that we may not always have the same number of arguments. Git will think we're a simple transport helper and so we won't receive a port in the tests that use mock SSH URLs, so let's accommodate the lack of port argument and the lack of -- arguments passed by Git. Since the error handling has changed somewhat, update the SSH test to make it look for the new error message and extract the command line from the trace output, since we no longer print it as part of the error message in this case. Additionally, include some examples of the new syntax forms we're expecting here, so it's easier for future developers to reason about this code. While we're at it, let's do some long-overdue cleanups. First, fix a long-standing bug in this code. The check for the length of authLine was against the quantity 13, which was probably a typo for 3, which used to be the number of arguments in the final argument string. However, because we just printed an error and didn't exit, we never noticed this problem. Let's fix this here by adding a suitable os.Exit call. Note that the check is now against the quanity 2 because when invoking git-receive-pack or git-upload-pack, we receive only the program name and repo, but no operation. Additionally, remove an extra debugging statement and an unused variable from the tests.
2021-05-14 17:47:40 +00:00
GIT_TRACE=1 git push origin main 2>&1 | tee push.log
if [ "0" -eq "${PIPESTATUS[0]}" ]; then
echo >&2 "fatal: push succeeded"
exit 1
fi
t/cmd: expand functionality of lfs-ssh-echo Currently, the only thing that lfs-ssh-echo does is provide the output for git-lfs-authenticate. However, in the future, we'll want to support git-lfs-transfer, and for our testing functionality, we'll want to pretend to have an SSH transport for cloning and pushing. In order to do so, let's refactor out some code. Let's plan to spawn a shell with the argument if we get a Git command or a git-lfs-transfer command, and let's make things work properly on both Unix (where we'll want sh) and Windows (where sh is not always available but we can rely on bash). Let's also gracefully handle the fact that we may not always have the same number of arguments. Git will think we're a simple transport helper and so we won't receive a port in the tests that use mock SSH URLs, so let's accommodate the lack of port argument and the lack of -- arguments passed by Git. Since the error handling has changed somewhat, update the SSH test to make it look for the new error message and extract the command line from the trace output, since we no longer print it as part of the error message in this case. Additionally, include some examples of the new syntax forms we're expecting here, so it's easier for future developers to reason about this code. While we're at it, let's do some long-overdue cleanups. First, fix a long-standing bug in this code. The check for the length of authLine was against the quantity 13, which was probably a typo for 3, which used to be the number of arguments in the final argument string. However, because we just printed an error and didn't exit, we never noticed this problem. Let's fix this here by adding a suitable os.Exit call. Note that the check is now against the quanity 2 because when invoking git-receive-pack or git-upload-pack, we receive only the program name and repo, but no operation. Additionally, remove an extra debugging statement and an unused variable from the tests.
2021-05-14 17:47:40 +00:00
grep 'expected.*git@127.0.0.1' push.log
grep "lfs-ssh-echo -- -oProxyCommand" push.log
)
end_test
begin_test "ssh with proxy command in lfs.url (custom variant)"
(
set -e
reponame="batch-ssh-proxy-simple"
setup_remote_repo "$reponame"
clone_repo "$reponame" "$reponame"
sshurl="${GITSERVER/http:\/\//ssh://-oProxyCommand=ssh-proxy-test/}/$reponame"
git config lfs.url "$sshurl"
contents="test"
oid="$(calc_oid "$contents")"
git lfs track "*.dat"
printf "%s" "$contents" > test.dat
git add .gitattributes test.dat
git commit -m "initial commit"
export GIT_SSH_VARIANT=simple
GIT_TRACE=1 git push origin main 2>&1 | tee push.log
if [ "0" -eq "${PIPESTATUS[0]}" ]; then
echo >&2 "fatal: push succeeded"
exit 1
fi
grep 'expected.*git@127.0.0.1' push.log
grep "lfs-ssh-echo oProxyCommand" push.log
)
end_test