Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add e2e for ssh:// URLs #869

Merged
merged 1 commit into from
Apr 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
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") {
Copy link
Contributor

@yyvess yyvess Apr 4, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not keep test on schema ssh here ?
Note that for url with the format [email protected]:kubernetes/git-sync method url.Parse return an err then it's good
err = parse "[email protected]:kubernetes/git-sync": first path segment in URL cannot contain colon

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know what OTHER schemes might have the problem that ssh://... has, but I do know that this logic was only intended for HTTP and HTTPS. I'd rather fall back on not changing the URL than changing it wrong (as I did with SSH)

if user := u.User.Username(); user != "" {
*flUsername = user
}
Expand Down
40 changes: 39 additions & 1 deletion test_e2e.sh
Original file line number Diff line number Diff line change
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
Loading