Skip to content

Commit

Permalink
Add e2e for ssh:// URLs
Browse files Browse the repository at this point in the history
  • Loading branch information
thockin committed Apr 4, 2024
1 parent e412c5f commit f521da5
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 2 deletions.
4 changes: 3 additions & 1 deletion main.go
Expand Up @@ -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
}
Expand Down
40 changes: 39 additions & 1 deletion test_e2e.sh
Expand Up @@ -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.
Expand Down Expand Up @@ -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
##############################################
Expand Down

0 comments on commit f521da5

Please sign in to comment.