From 619eea3af7b9c5352de42af124988eab76604cd4 Mon Sep 17 00:00:00 2001 From: nsfisis Date: Sun, 21 Jun 2026 02:51:44 +0900 Subject: test(util): port NoProxyPatternTest NoProxyPattern::test reaches a todo!() (substr_count) in the php-shim, so all cases are marked #[ignore] while the test code compiles. Co-Authored-By: Claude Opus 4.8 (1M context) --- crates/shirabe/tests/util/no_proxy_pattern_test.rs | 79 ++++++++++++++++++++++ 1 file changed, 79 insertions(+) (limited to 'crates/shirabe/tests/util/no_proxy_pattern_test.rs') diff --git a/crates/shirabe/tests/util/no_proxy_pattern_test.rs b/crates/shirabe/tests/util/no_proxy_pattern_test.rs index 82e0ae7..8585eea 100644 --- a/crates/shirabe/tests/util/no_proxy_pattern_test.rs +++ b/crates/shirabe/tests/util/no_proxy_pattern_test.rs @@ -1 +1,80 @@ //! ref: composer/tests/Composer/Test/Util/NoProxyPatternTest.php + +use shirabe::util::no_proxy_pattern::NoProxyPattern; + +fn run_test(noproxy: &str, url: &str, expected: bool) { + let mut matcher = NoProxyPattern::new(noproxy); + let url = get_url(url); + assert_eq!(expected, matcher.test(&url).unwrap()); +} + +/// Appends a scheme to the test url if it is missing. +fn get_url(url: &str) -> String { + if url.contains("://") { + return url.to_string(); + } + + let mut scheme = "http"; + + if !url.starts_with('[') && url.rfind(':').is_some() { + let port = url.split(':').nth(1).unwrap_or(""); + + if port == "443" { + scheme = "https"; + } + } + + format!("{}://{}", scheme, url) +} + +#[test] +#[ignore = "NoProxyPattern::test reaches a todo!() (substr_count) in the php-shim"] +fn test_host_name() { + let noproxy = "foobar.com, .barbaz.net"; + + run_test(noproxy, "foobar.com", true); + run_test(noproxy, "www.foobar.com", true); + run_test(noproxy, "foofoobar.com", false); + run_test(noproxy, "barbaz.net", true); + run_test(noproxy, "www.barbaz.net", true); + run_test(noproxy, "barbarbaz.net", false); + run_test(noproxy, "barbaz.com", false); + run_test(noproxy, "foobar.com.", false); +} + +#[test] +#[ignore = "NoProxyPattern::test reaches a todo!() (substr_count) in the php-shim"] +fn test_ip_address() { + let noproxy = "192.168.1.1, 2001:db8::52:0:1"; + + run_test(noproxy, "192.168.1.1", true); + run_test(noproxy, "192.168.1.4", false); + run_test(noproxy, "[2001:db8:0:0:0:52:0:1]", true); + run_test(noproxy, "[2001:db8:0:0:0:52:0:2]", false); + run_test(noproxy, "[::FFFF:C0A8:0101]", true); + run_test(noproxy, "[::FFFF:C0A8:0104]", false); +} + +#[test] +#[ignore = "NoProxyPattern::test reaches a todo!() (substr_count) in the php-shim"] +fn test_ip_range() { + let noproxy = "10.0.0.0/30, 2002:db8:a::45/121"; + + run_test(noproxy, "10.0.0.2", true); + run_test(noproxy, "10.0.0.4", false); + run_test(noproxy, "[2002:db8:a:0:0:0:0:7f]", true); + run_test(noproxy, "[2002:db8:a:0:0:0:0:ff]", false); + run_test(noproxy, "[::FFFF:0A00:0002]", true); + run_test(noproxy, "[::FFFF:0A00:0004]", false); +} + +#[test] +#[ignore = "NoProxyPattern::test reaches a todo!() (substr_count) in the php-shim"] +fn test_port() { + let noproxy = "192.168.1.2:81, 192.168.1.3:80, [2001:db8::52:0:2]:443, [2001:db8::52:0:3]:80"; + + run_test(noproxy, "192.168.1.3", true); + run_test(noproxy, "192.168.1.2", false); + run_test(noproxy, "[2001:db8::52:0:3]", true); + run_test(noproxy, "[2001:db8::52:0:2]", false); +} -- cgit v1.3.1