Parse SSH URL usernames consistently
ci / test (push) Canceled after 0s
ci / fuzz-smoke (push) Canceled after 0s
ci / macos-client (macos-aarch64, macos-14) (push) Canceled after 0s
ci / macos-client (macos-x86_64, macos-13) (push) Canceled after 0s
ci / windows-client (push) Canceled after 0s
ci / package-release (linux-x86_64, ubuntu-latest, , , ) (push) Canceled after 0s
ci / package-release (macos-aarch64, macos-14, , , ) (push) Canceled after 0s
ci / package-release (macos-x86_64, macos-13, , , ) (push) Canceled after 0s
ci / package-release (windows-aarch64, windows-latest, aarch64, windows, aarch64-pc-windows-msvc) (push) Canceled after 0s
ci / package-release (windows-x86_64, windows-latest, , , ) (push) Canceled after 0s
ci / remote-bench (push) Canceled after 0s
ci / publish-gitea-release (push) Canceled after 0s
ci / test (push) Canceled after 0s
ci / fuzz-smoke (push) Canceled after 0s
ci / macos-client (macos-aarch64, macos-14) (push) Canceled after 0s
ci / macos-client (macos-x86_64, macos-13) (push) Canceled after 0s
ci / windows-client (push) Canceled after 0s
ci / package-release (linux-x86_64, ubuntu-latest, , , ) (push) Canceled after 0s
ci / package-release (macos-aarch64, macos-14, , , ) (push) Canceled after 0s
ci / package-release (macos-x86_64, macos-13, , , ) (push) Canceled after 0s
ci / package-release (windows-aarch64, windows-latest, aarch64, windows, aarch64-pc-windows-msvc) (push) Canceled after 0s
ci / package-release (windows-x86_64, windows-latest, , , ) (push) Canceled after 0s
ci / remote-bench (push) Canceled after 0s
ci / publish-gitea-release (push) Canceled after 0s
This commit is contained in:
@@ -5271,6 +5271,7 @@ fn native_proxy_udp_warning(
|
|||||||
|
|
||||||
fn ssh_username(server: &str) -> Option<String> {
|
fn ssh_username(server: &str) -> Option<String> {
|
||||||
let (user, _) = server.rsplit_once('@')?;
|
let (user, _) = server.rsplit_once('@')?;
|
||||||
|
let user = user.strip_prefix("ssh://").unwrap_or(user);
|
||||||
if user.is_empty() {
|
if user.is_empty() {
|
||||||
None
|
None
|
||||||
} else {
|
} else {
|
||||||
@@ -11433,7 +11434,16 @@ mod tests {
|
|||||||
#[test]
|
#[test]
|
||||||
fn parses_user_from_ssh_destination() {
|
fn parses_user_from_ssh_destination() {
|
||||||
assert_eq!(ssh_username("alice@example.com"), Some("alice".to_string()));
|
assert_eq!(ssh_username("alice@example.com"), Some("alice".to_string()));
|
||||||
|
assert_eq!(
|
||||||
|
ssh_username("ssh://alice@example.com:2222/srv/app"),
|
||||||
|
Some("alice".to_string())
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
ssh_username("ssh://alice@[2001:db8::1]:2222/srv/app"),
|
||||||
|
Some("alice".to_string())
|
||||||
|
);
|
||||||
assert_eq!(ssh_username("example.com"), None);
|
assert_eq!(ssh_username("example.com"), None);
|
||||||
|
assert_eq!(ssh_username("ssh://example.com:2222/srv/app"), None);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|||||||
+9
-1
@@ -786,7 +786,7 @@ fn selected_sdk_udp_host(
|
|||||||
fn user_from_destination(destination: &str) -> Option<String> {
|
fn user_from_destination(destination: &str) -> Option<String> {
|
||||||
destination
|
destination
|
||||||
.rsplit_once('@')
|
.rsplit_once('@')
|
||||||
.map(|(user, _)| user.to_string())
|
.map(|(user, _)| user.strip_prefix("ssh://").unwrap_or(user).to_string())
|
||||||
.filter(|user| !user.is_empty())
|
.filter(|user| !user.is_empty())
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -819,6 +819,14 @@ mod tests {
|
|||||||
user_from_destination("palav@example.com").as_deref(),
|
user_from_destination("palav@example.com").as_deref(),
|
||||||
Some("palav")
|
Some("palav")
|
||||||
);
|
);
|
||||||
|
assert_eq!(
|
||||||
|
user_from_destination("ssh://palav@example.com:2222/srv/app").as_deref(),
|
||||||
|
Some("palav")
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
user_from_destination("ssh://palav@[2001:db8::2]:2222/srv/app").as_deref(),
|
||||||
|
Some("palav")
|
||||||
|
);
|
||||||
assert_eq!(destination_host("palav@example.com"), "example.com");
|
assert_eq!(destination_host("palav@example.com"), "example.com");
|
||||||
assert_eq!(destination_host("example.com:2222"), "example.com");
|
assert_eq!(destination_host("example.com:2222"), "example.com");
|
||||||
assert_eq!(destination_host("palav@[2001:db8::1]:2222"), "2001:db8::1");
|
assert_eq!(destination_host("palav@[2001:db8::1]:2222"), "2001:db8::1");
|
||||||
|
|||||||
Reference in New Issue
Block a user