| 1 | #!/usr/bin/env bash |
| 2 | |
| 3 | . "$(dirname "$0")/testlib.sh" |
| 4 | |
| 5 | begin_test "ssh with proxy command in lfs.url (default variant)" |
| 6 | ( |
| 7 | set -e |
| 8 | |
| 9 | reponame="batch-ssh-proxy-default" |
| 10 | setup_remote_repo "$reponame" |
| 11 | clone_repo "$reponame" "$reponame" |
| 12 | |
| 13 | sshurl="${GITSERVER/http:\/\//ssh://-oProxyCommand=ssh-proxy-test/}/$reponame" |
| 14 | git config lfs.url "$sshurl" |
| 15 | |
| 16 | contents="test" |
| 17 | oid="$(calc_oid "$contents")" |
| 18 | git lfs track "*.dat" |
| 19 | printf "%s" "$contents" > test.dat |
| 20 | git add .gitattributes test.dat |
| 21 | git commit -m "initial commit" |
| 22 | |
| 23 | unset GIT_SSH_VARIANT |
| 24 | GIT_TRACE=1 git push origin main 2>&1 | tee push.log |
| 25 | if [ "0" -eq "${PIPESTATUS[0]}" ]; then |
| 26 | echo >&2 "fatal: push succeeded" |
| 27 | exit 1 |
| 28 | fi |
| 29 | |
| 30 | grep 'expected.*[email protected]' push.log |
| 31 | grep "lfs-ssh-echo -- -oProxyCommand" push.log |
| 32 | ) |
| 33 | end_test |
| 34 | |
| 35 | begin_test "ssh with proxy command in lfs.url (custom variant)" |
| 36 | ( |
| 37 | set -e |
| 38 | |
| 39 | reponame="batch-ssh-proxy-simple" |
| 40 | setup_remote_repo "$reponame" |
| 41 | clone_repo "$reponame" "$reponame" |
| 42 | |
| 43 | sshurl="${GITSERVER/http:\/\//ssh://-oProxyCommand=ssh-proxy-test/}/$reponame" |
| 44 | git config lfs.url "$sshurl" |
| 45 | |
| 46 | contents="test" |
| 47 | oid="$(calc_oid "$contents")" |
| 48 | git lfs track "*.dat" |
| 49 | printf "%s" "$contents" > test.dat |
| 50 | git add .gitattributes test.dat |
| 51 | git commit -m "initial commit" |
| 52 | |
| 53 | export GIT_SSH_VARIANT=simple |
| 54 | GIT_TRACE=1 git push origin main 2>&1 | tee push.log |
| 55 | if [ "0" -eq "${PIPESTATUS[0]}" ]; then |
| 56 | echo >&2 "fatal: push succeeded" |
| 57 | exit 1 |
| 58 | fi |
| 59 | |
| 60 | grep 'expected.*[email protected]' push.log |
| 61 | grep "lfs-ssh-echo oProxyCommand" push.log |
| 62 | ) |
| 63 | end_test |
| 64 | |
| 65 | # ssh_authenticate_unavailable_test performs a test which expects "git push" |
| 66 | # to fail, but only after the Git LFS client correctly defaults to a |
| 67 | # fallback HTTPS URL when the "git-lfs-authenticate" command is reported as |
| 68 | # not found on the SSH remote. |
| 69 | # |
| 70 | # The SSH client used by the tests is triggered by the repository name to |
| 71 | # simulate a specific exit code and optional error message indicating that |
| 72 | # the "git-lfs-authenticate" command is not available. |
| 73 | ssh_authenticate_unavailable_test() { |
| 74 | local reponame="$1" |
| 75 | |
| 76 | set -e |
| 77 | |
| 78 | setup_remote_repo "$reponame" |
| 79 | clone_repo "$reponame" "$reponame" |
| 80 | |
| 81 | # We construct an invalid host name (127.0.0.1.invalid) to guarantee that |
| 82 | # the HTTPS fallback URL, which will default to port 443, cannot contact |
| 83 | # any local or remote services not controlled by our test suite. |
| 84 | gitserver_hostport="${GITSERVER#http://}" |
| 85 | gitserver_host="${gitserver_hostport/%:*/}" |
| 86 | gitserver_port="${gitserver_hostport/#*:/}" |
| 87 | invalid_host="$gitserver_host.invalid" |
| 88 | git config lfs.url "ssh://git@$invalid_host:$gitserver_port/$reponame" |
| 89 | |
| 90 | git lfs track "*.dat" |
| 91 | |
| 92 | contents="test" |
| 93 | printf "%s" "$contents" >test.dat |
| 94 | |
| 95 | git add .gitattributes test.dat |
| 96 | git commit -m "initial commit" |
| 97 | |
| 98 | GIT_TRACE=1 git push origin main 2>&1 | tee push.log |
| 99 | [ 0 -ne "${PIPESTATUS[0]}" ] |
| 100 | |
| 101 | # Requests to both the Locking API and the Batch API should fall back to |
| 102 | # an HTTPS URL, which should in turn fail because the host name is invalid. |
| 103 | [ 2 -eq "$(grep -c "exec: lfs-ssh-echo.*git-lfs-authenticate /$reponame upload" push.log)" ] |
| 104 | [ 2 -eq "$(grep -c -F "ssh: git@$invalid_host does not provide git-lfs-authenticate, falling back to guessed LFS endpoint" push.log)" ] |
| 105 | [ 2 -eq "$(grep -c -F "HTTP: POST https://$invalid_host/$reponame/" push.log)" ] |
| 106 | } |
| 107 | |
| 108 | begin_test "SSH git-lfs-authenticate unavailable (fallback to HTTPS)" |
| 109 | ( |
| 110 | set -e |
| 111 | |
| 112 | # This repository name announces to the SSH test utility that it should |
| 113 | # exit as if the "git-lfs-authenticate" command was not found. |
| 114 | reponame="ssh-unavailable" |
| 115 | ssh_authenticate_unavailable_test "$reponame" |
| 116 | ) |
| 117 | end_test |
| 118 | |
| 119 | begin_test "SSH git-lfs-authenticate unavailable message (fallback to HTTPS)" |
| 120 | ( |
| 121 | set -e |
| 122 | |
| 123 | # This repository name announces to the SSH test utility that it should |
| 124 | # exit with a generic error status code and a message indicating that the |
| 125 | # "git-lfs-authenticate" command was not found, as may occur when using |
| 126 | # third-party tools such as Gerrit Code Review. |
| 127 | reponame="ssh-unavailable-message" |
| 128 | ssh_authenticate_unavailable_test "$reponame" |
| 129 | ) |
| 130 | end_test |