diff options
| -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; |
