Skip to content

Commit f521da5

Browse files
committed
Add e2e for ssh:// URLs
1 parent e412c5f commit f521da5

File tree

2 files changed

+42
-2
lines changed

2 files changed

+42
-2
lines changed

main.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -572,7 +572,9 @@ func main() {
572572
if *flUsername == "" {
573573
// username and user@host URLs are validated as mutually exclusive
574574
if u, err := url.Parse(*flRepo); err == nil { // it may not even parse as a URL, that's OK
575-
if u.User != nil && u.Scheme != "ssh" {
575+
// Note that `ssh://user@host/path` URLs need to retain the user
576+
// field. Out of caution, we only handle HTTP(S) URLs here.
577+
if u.User != nil && (u.Scheme == "http" || u.Scheme == "https") {
576578
if user := u.User.Username(); user != "" {
577579
*flUsername = user
578580
}

test_e2e.sh

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1892,7 +1892,7 @@ function e2e::auth_http_password_file() {
18921892
}
18931893

18941894
##############################################
1895-
# Test SSH
1895+
# Test SSH (user@host:path syntax)
18961896
##############################################
18971897
function e2e::auth_ssh() {
18981898
# Run a git-over-SSH server. Use key #3 to exercise the multi-key logic.
@@ -1929,6 +1929,44 @@ function e2e::auth_ssh() {
19291929
assert_file_eq "$ROOT/link/file" "$FUNCNAME"
19301930
}
19311931

1932+
##############################################
1933+
# Test SSH (ssh://user@host/path syntax)
1934+
##############################################
1935+
function e2e::auth_ssh_url() {
1936+
# Run a git-over-SSH server. Use key #3 to exercise the multi-key logic.
1937+
CTR=$(docker_run \
1938+
-v "$DOT_SSH/server/3":/dot_ssh:ro \
1939+
-v "$REPO":/git/repo:ro \
1940+
e2e/test/sshd)
1941+
IP=$(docker_ip "$CTR")
1942+
1943+
# Try to sync with key #1.
1944+
assert_fail \
1945+
GIT_SYNC \
1946+
--one-time \
1947+
--repo="ssh://test@$IP/git/repo" \
1948+
--root="$ROOT" \
1949+
--link="link" \
1950+
--ssh-known-hosts=false \
1951+
--ssh-key-file="/ssh/secret.2"
1952+
assert_file_absent "$ROOT/link/file"
1953+
1954+
# Try to sync with multiple keys
1955+
GIT_SYNC \
1956+
--one-time \
1957+
--repo="ssh://test@$IP/git/repo" \
1958+
--root="$ROOT" \
1959+
--link="link" \
1960+
--ssh-known-hosts=false \
1961+
--ssh-key-file="/ssh/secret.1" \
1962+
--ssh-key-file="/ssh/secret.2" \
1963+
--ssh-key-file="/ssh/secret.3"
1964+
1965+
assert_link_exists "$ROOT/link"
1966+
assert_file_exists "$ROOT/link/file"
1967+
assert_file_eq "$ROOT/link/file" "$FUNCNAME"
1968+
}
1969+
19321970
##############################################
19331971
# Test askpass-url with bad password
19341972
##############################################

0 commit comments

Comments
 (0)