Skip to content

Commit 9322b1b

Browse files
refactor(agent): reuse shared endpoint::split_endpoint helper in verify-tunnel
1 parent f84d632 commit 9322b1b

1 file changed

Lines changed: 4 additions & 43 deletions

File tree

devolutions-agent/src/verify_tunnel.rs

Lines changed: 4 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -337,10 +337,10 @@ async fn run_verification(conf_handle: &ConfHandle) -> Result<(), ErrorTriple> {
337337
// ----- Resolve gateway endpoint -----
338338

339339
let endpoint_str = &tunnel_conf.gateway_endpoint;
340-
let (gateway_hostname, _port_str) = split_host_port(endpoint_str).ok_or_else(|| {
340+
let (gateway_hostname, _port) = crate::endpoint::split_endpoint(endpoint_str).map_err(|e| {
341341
ErrorTriple::new(
342342
ErrorKind::UnexpectedError,
343-
format!("gateway_endpoint {endpoint_str:?} is malformed (missing port separator)"),
343+
format!("gateway_endpoint {endpoint_str:?} is malformed: {e:#}"),
344344
)
345345
})?;
346346

@@ -497,22 +497,6 @@ where
497497
// Helpers
498498
// ---------------------------------------------------------------------------
499499

500-
/// Split a `host:port` / `[ipv6]:port` endpoint into the host string and the
501-
/// port string. Returns `None` when no port separator is found.
502-
fn split_host_port(endpoint: &str) -> Option<(String, String)> {
503-
let trimmed = endpoint.trim();
504-
if let Some((host, port)) = trimmed.rsplit_once(']') {
505-
// IPv6 form: `[host]:port`.
506-
let host = host.strip_prefix('[')?;
507-
let port = port.strip_prefix(':')?;
508-
Some((host.to_owned(), port.to_owned()))
509-
} else {
510-
// DNS / IPv4 form: `host:port`.
511-
let (host, port) = trimmed.rsplit_once(':')?;
512-
Some((host.to_owned(), port.to_owned()))
513-
}
514-
}
515-
516500
fn dns_failed(host: &str, raw: &str) -> ErrorTriple {
517501
ErrorTriple::new(
518502
ErrorKind::DnsResolutionFailed,
@@ -740,29 +724,6 @@ mod tests {
740724
assert!(triple.detail.contains("log="));
741725
}
742726

743-
#[test]
744-
fn split_host_port_dns() {
745-
let (h, p) = split_host_port("gateway.example.com:4433").unwrap();
746-
assert_eq!(h, "gateway.example.com");
747-
assert_eq!(p, "4433");
748-
}
749-
750-
#[test]
751-
fn split_host_port_ipv4() {
752-
let (h, p) = split_host_port("10.10.0.7:4433").unwrap();
753-
assert_eq!(h, "10.10.0.7");
754-
assert_eq!(p, "4433");
755-
}
756-
757-
#[test]
758-
fn split_host_port_ipv6() {
759-
let (h, p) = split_host_port("[fd00::7]:4433").unwrap();
760-
assert_eq!(h, "fd00::7");
761-
assert_eq!(p, "4433");
762-
}
763-
764-
#[test]
765-
fn split_host_port_rejects_no_port() {
766-
assert!(split_host_port("gateway.example.com").is_none());
767-
}
727+
// Endpoint splitting tests live in `crate::endpoint` — the shared helper
728+
// is the single source of truth for `host:port` / `[ipv6]:port` parsing.
768729
}

0 commit comments

Comments
 (0)