diff options
| author | nsfisis <nsfisis@gmail.com> | 2026-06-21 02:51:44 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2026-06-21 02:51:44 +0900 |
| commit | 619eea3af7b9c5352de42af124988eab76604cd4 (patch) | |
| tree | d62720b6d345cb103c927dc933a9fedf45c2b298 /crates | |
| parent | b5a9d37a7880b05cb3ba1fdbe5b8873295621514 (diff) | |
| download | php-shirabe-619eea3af7b9c5352de42af124988eab76604cd4.tar.gz php-shirabe-619eea3af7b9c5352de42af124988eab76604cd4.tar.zst php-shirabe-619eea3af7b9c5352de42af124988eab76604cd4.zip | |
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) <noreply@anthropic.com>
Diffstat (limited to 'crates')
| -rw-r--r-- | crates/shirabe/tests/util/main.rs | 1 | ||||
| -rw-r--r-- | crates/shirabe/tests/util/no_proxy_pattern_test.rs | 79 |
2 files changed, 80 insertions, 0 deletions
diff --git a/crates/shirabe/tests/util/main.rs b/crates/shirabe/tests/util/main.rs index 1bcc75e..e0ce148 100644 --- a/crates/shirabe/tests/util/main.rs +++ b/crates/shirabe/tests/util/main.rs @@ -1,6 +1,7 @@ mod config_validator_test; mod forgejo_url_test; mod http; +mod no_proxy_pattern_test; mod platform_test; mod silencer_test; mod tar_test; 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); +} |
