Add e2e for ssh:// URLs

This commit is contained in:
Tim Hockin 2024-04-04 09:18:08 -07:00
parent e412c5f9ee
commit f521da5548
2 changed files with 42 additions and 2 deletions

View File

@ -572,7 +572,9 @@ func main() {
if *flUsername == "" {
// username and user@host URLs are validated as mutually exclusive
if u, err := url.Parse(*flRepo); err == nil { // it may not even parse as a URL, that's OK
if u.User != nil && u.Scheme != "ssh" {
// Note that `ssh://user@host/path` URLs need to retain the user
// field. Out of caution, we only handle HTTP(S) URLs here.
if u.User != nil && (u.Scheme == "http" || u.Scheme == "https") {
if user := u.User.Username(); user != "" {
*flUsername = user
}

View File

@ -1892,7 +1892,7 @@ function e2e::auth_http_password_file() {
}
##############################################
# Test SSH
# Test SSH (user@host:path syntax)
##############################################
function e2e::auth_ssh() {
# Run a git-over-SSH server. Use key #3 to exercise the multi-key logic.
@ -1929,6 +1929,44 @@ function e2e::auth_ssh() {
assert_file_eq "$ROOT/link/file" "$FUNCNAME"
}
##############################################
# Test SSH (ssh://user@host/path syntax)
##############################################
function e2e::auth_ssh_url() {
# Run a git-over-SSH server. Use key #3 to exercise the multi-key logic.
CTR=$(docker_run \
-v "$DOT_SSH/server/3":/dot_ssh:ro \
-v "$REPO":/git/repo:ro \
e2e/test/sshd)
IP=$(docker_ip "$CTR")
# Try to sync with key #1.
assert_fail \
GIT_SYNC \
--one-time \
--repo="ssh://test@$IP/git/repo" \
--root="$ROOT" \
--link="link" \
--ssh-known-hosts=false \
--ssh-key-file="/ssh/secret.2"
assert_file_absent "$ROOT/link/file"
# Try to sync with multiple keys
GIT_SYNC \
--one-time \
--repo="ssh://test@$IP/git/repo" \
--root="$ROOT" \
--link="link" \
--ssh-known-hosts=false \
--ssh-key-file="/ssh/secret.1" \
--ssh-key-file="/ssh/secret.2" \
--ssh-key-file="/ssh/secret.3"
assert_link_exists "$ROOT/link"
assert_file_exists "$ROOT/link/file"
assert_file_eq "$ROOT/link/file" "$FUNCNAME"
}
##############################################
# Test askpass-url with bad password
##############################################