From 3edd08813f4c8e08f983cf19568dc91d1b368417 Mon Sep 17 00:00:00 2001 From: nsfisis Date: Sun, 21 Jun 2026 00:58:41 +0900 Subject: 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) --- crates/shirabe/tests/util/http/proxy_item_test.rs | 60 +++++++++++++++++++++++ 1 file changed, 60 insertions(+) (limited to 'crates/shirabe/tests/util/http/proxy_item_test.rs') 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"), + ] +} -- cgit v1.3.1