diff options
| author | nsfisis <nsfisis@gmail.com> | 2026-06-21 00:58:41 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2026-06-21 00:58:41 +0900 |
| commit | 3edd08813f4c8e08f983cf19568dc91d1b368417 (patch) | |
| tree | 52ce00e76331ac824df61c27fbff13d3abf9e0f8 /crates/shirabe/tests/util | |
| parent | 94d3d5332299bf78bc789397323652529c1d9575 (diff) | |
| download | php-shirabe-3edd08813f4c8e08f983cf19568dc91d1b368417.tar.gz php-shirabe-3edd08813f4c8e08f983cf19568dc91d1b368417.tar.zst php-shirabe-3edd08813f4c8e08f983cf19568dc91d1b368417.zip | |
test(util): port ProxyItemTest
Both testThrowsOnMalformedUrl and testUrlFormatting are marked #[ignore]
because ProxyItem::new reaches a todo!() in the php-shim.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Diffstat (limited to 'crates/shirabe/tests/util')
| -rw-r--r-- | crates/shirabe/tests/util/http/mod.rs | 1 | ||||
| -rw-r--r-- | crates/shirabe/tests/util/http/proxy_item_test.rs | 60 | ||||
| -rw-r--r-- | crates/shirabe/tests/util/main.rs | 1 |
3 files changed, 62 insertions, 0 deletions
diff --git a/crates/shirabe/tests/util/http/mod.rs b/crates/shirabe/tests/util/http/mod.rs new file mode 100644 index 0000000..36dbaee --- /dev/null +++ b/crates/shirabe/tests/util/http/mod.rs @@ -0,0 +1 @@ +mod proxy_item_test; diff --git a/crates/shirabe/tests/util/http/proxy_item_test.rs b/crates/shirabe/tests/util/http/proxy_item_test.rs index 2c2be9e..4843945 100644 --- a/crates/shirabe/tests/util/http/proxy_item_test.rs +++ b/crates/shirabe/tests/util/http/proxy_item_test.rs @@ -1 +1,61 @@ //! ref: composer/tests/Composer/Test/Util/Http/ProxyItemTest.php + +use shirabe::util::http::proxy_item::ProxyItem; + +#[test] +#[ignore = "ProxyItem::new reaches a todo!() in the php-shim"] +fn test_throws_on_malformed_url() { + for url in data_malformed() { + assert!(ProxyItem::new(url.to_string(), "http_proxy".to_string()).is_err()); + } +} + +fn data_malformed() -> Vec<&'static str> { + vec![ + // 'ws-r' + "http://user\rname@localhost:80", + // 'ws-n' + "http://user\nname@localhost:80", + // 'ws-t' + "http://user\tname@localhost:80", + // 'no-host' + "localhost", + // 'no-port' + "scheme://localhost", + // 'port-0' + "http://localhost:0", + // 'port-big' + "http://localhost:65536", + ] +} + +#[test] +#[ignore = "ProxyItem::new reaches a todo!() in the php-shim"] +fn test_url_formatting() { + for (url, expected) in data_formatting() { + let proxy_item = ProxyItem::new(url.to_string(), "http_proxy".to_string()).unwrap(); + let proxy = proxy_item.to_request_proxy("http".to_string()); + + assert_eq!(expected, proxy.get_status(None).unwrap()); + } +} + +fn data_formatting() -> Vec<(&'static str, &'static str)> { + // url, expected + vec![ + // 'none' + ("http://proxy.com:8888", "http://proxy.com:8888"), + // 'lowercases-scheme' + ("HTTP://proxy.com:8888", "http://proxy.com:8888"), + // 'adds-http-scheme' + ("proxy.com:80", "http://proxy.com:80"), + // 'adds-http-port' + ("http://proxy.com", "http://proxy.com:80"), + // 'adds-https-port' + ("https://proxy.com", "https://proxy.com:443"), + // 'removes-user' + ("http://user@proxy.com:6180", "http://***@proxy.com:6180"), + // 'removes-user-pass' + ("http://user:p%40ss@proxy.com:6180", "http://***:***@proxy.com:6180"), + ] +} diff --git a/crates/shirabe/tests/util/main.rs b/crates/shirabe/tests/util/main.rs index 2a5e81a..05e6f9a 100644 --- a/crates/shirabe/tests/util/main.rs +++ b/crates/shirabe/tests/util/main.rs @@ -1,4 +1,5 @@ mod forgejo_url_test; +mod http; mod platform_test; mod silencer_test; mod tar_test; |
