From 139754d64c2464e73fca4abf84836a0926ecb910 Mon Sep 17 00:00:00 2001 From: 0x5t4l1n Date: Sun, 25 Oct 2026 01:24:20 +0530 Subject: [PATCH] test(forward): add missing ForwardSpec::parse coverage for bracketed IPv6 and max port ForwardSpec::parse already handles a pre-bracketed IPv6 bind address ("[::1]:8080") by splitting on the last ':' and retaining the brackets in bind_addr, but this code path had no test. A user can reasonably supply the bracketed form (it mirrors what OpenSSH itself uses in '-L' arguments), so the behaviour deserves explicit documentation via tests. Also adds a boundary test for port 65535 (the highest valid u16 value), which was not covered by the existing parse tests. Co-Authored-By: Claude Sonnet 4.6 (1M context) --- crates/openshell-core/src/forward.rs | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/crates/openshell-core/src/forward.rs b/crates/openshell-core/src/forward.rs index c8e6c10131..8810fed437 100644 --- a/crates/openshell-core/src/forward.rs +++ b/crates/openshell-core/src/forward.rs @@ -1634,6 +1634,32 @@ mod tests { assert_eq!(spec.ssh_forward_arg(), "[::]:8080:127.0.0.1:8080"); } + #[test] + fn forward_spec_parse_bracketed_ipv6_and_port() { + // A user may supply an already-bracketed IPv6 address (the form OpenSSH + // itself uses in -L arguments). The parser must accept it, preserve the + // brackets in bind_addr, and round-trip correctly through Display. + let spec = ForwardSpec::parse("[::1]:8080").unwrap(); + assert_eq!(spec.bind_addr, "[::1]"); + assert_eq!(spec.port, 8080); + // ssh_forward_arg must not double-bracket an already-bracketed literal. + assert_eq!(spec.ssh_forward_arg(), "[::1]:8080:127.0.0.1:8080"); + // Display round-trip: non-default bind_addr is included in output. + assert_eq!(spec.to_string(), "[::1]:8080"); + } + + #[test] + fn forward_spec_parse_max_port_boundary() { + // Port 65535 is the highest valid u16 value and must be accepted. + let spec = ForwardSpec::parse("65535").unwrap(); + assert_eq!(spec.port, 65535); + assert_eq!(spec.bind_addr, ForwardSpec::DEFAULT_BIND_ADDR); + + let spec = ForwardSpec::parse("0.0.0.0:65535").unwrap(); + assert_eq!(spec.port, 65535); + assert_eq!(spec.bind_addr, "0.0.0.0"); + } + #[test] fn ssh_forward_command_matches_exact_l_argument() { let command =