diff options
| author | nsfisis <nsfisis@gmail.com> | 2026-06-22 02:09:59 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2026-06-22 02:09:59 +0900 |
| commit | 822d9a872807a92a5337ee8b7bab96dc9845cdbb (patch) | |
| tree | 4931365df5978caffade69cad2154718a9076f66 /crates/shirabe/tests/util/stream_context_factory_test.rs | |
| parent | f691b864b687f251c3b266e8cff2774d730567ba (diff) | |
| download | php-shirabe-822d9a872807a92a5337ee8b7bab96dc9845cdbb.tar.gz php-shirabe-822d9a872807a92a5337ee8b7bab96dc9845cdbb.tar.zst php-shirabe-822d9a872807a92a5337ee8b7bab96dc9845cdbb.zip | |
test: port more test cases
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Diffstat (limited to 'crates/shirabe/tests/util/stream_context_factory_test.rs')
| -rw-r--r-- | crates/shirabe/tests/util/stream_context_factory_test.rs | 66 |
1 files changed, 53 insertions, 13 deletions
diff --git a/crates/shirabe/tests/util/stream_context_factory_test.rs b/crates/shirabe/tests/util/stream_context_factory_test.rs index f58ee75..23d4392 100644 --- a/crates/shirabe/tests/util/stream_context_factory_test.rs +++ b/crates/shirabe/tests/util/stream_context_factory_test.rs @@ -3,8 +3,11 @@ // These build a stream context and assert proxy/option handling driven by HTTP(S)_PROXY / // no_proxy environment variables; the env-dependent setup (without its setUp/tearDown // isolation) is not ported. +use indexmap::IndexMap; use shirabe::util::http::proxy_manager::ProxyManager; use shirabe::util::platform::Platform; +use shirabe::util::stream_context_factory::StreamContextFactory; +use shirabe_php_shim::{PhpMixed, implode, stripos}; fn set_up() { Platform::clear_env("HTTP_PROXY"); @@ -35,7 +38,7 @@ impl Drop for TearDown { } #[test] -#[ignore = "not yet ported (StreamContextFactory proxy/option building is driven by proxy env vars)"] +#[ignore = "stream_context_get_options/stream_context_get_params shim functions do not exist; cannot read back created context to assert"] fn test_get_context() { let _tear_down = TearDown; set_up(); @@ -43,7 +46,7 @@ fn test_get_context() { } #[test] -#[ignore = "not yet ported (StreamContextFactory proxy/option building is driven by proxy env vars)"] +#[ignore = "stream_context_get_options shim function does not exist; cannot read back created context to assert"] fn test_http_proxy() { let _tear_down = TearDown; set_up(); @@ -51,7 +54,7 @@ fn test_http_proxy() { } #[test] -#[ignore = "not yet ported (StreamContextFactory proxy/option building is driven by proxy env vars)"] +#[ignore = "stream_context_get_options shim function does not exist; cannot read back created context to assert"] fn test_http_proxy_with_no_proxy() { let _tear_down = TearDown; set_up(); @@ -59,7 +62,7 @@ fn test_http_proxy_with_no_proxy() { } #[test] -#[ignore = "not yet ported (StreamContextFactory proxy/option building is driven by proxy env vars)"] +#[ignore = "stream_context_get_options shim function does not exist; cannot read back created context to assert"] fn test_http_proxy_with_no_proxy_wildcard() { let _tear_down = TearDown; set_up(); @@ -67,7 +70,7 @@ fn test_http_proxy_with_no_proxy_wildcard() { } #[test] -#[ignore = "not yet ported (StreamContextFactory proxy/option building is driven by proxy env vars)"] +#[ignore = "stream_context_get_options shim function does not exist; cannot read back created context to assert"] fn test_options_are_preserved() { let _tear_down = TearDown; set_up(); @@ -75,7 +78,7 @@ fn test_options_are_preserved() { } #[test] -#[ignore = "not yet ported (StreamContextFactory proxy/option building is driven by proxy env vars)"] +#[ignore = "stream_context_get_options shim function does not exist; cannot read back created context to assert"] fn test_http_proxy_without_port() { let _tear_down = TearDown; set_up(); @@ -83,7 +86,7 @@ fn test_http_proxy_without_port() { } #[test] -#[ignore = "not yet ported (StreamContextFactory proxy/option building is driven by proxy env vars)"] +#[ignore = "stream_context_get_options shim function does not exist; cannot read back created context to assert"] fn test_https_proxy_override() { let _tear_down = TearDown; set_up(); @@ -91,7 +94,7 @@ fn test_https_proxy_override() { } #[test] -#[ignore = "not yet ported (StreamContextFactory proxy/option building is driven by proxy env vars)"] +#[ignore = "stream_context_get_options shim function does not exist; cannot read back created context to assert"] fn test_ssl_proxy() { let _tear_down = TearDown; set_up(); @@ -99,7 +102,7 @@ fn test_ssl_proxy() { } #[test] -#[ignore = "not yet ported (StreamContextFactory proxy/option building is driven by proxy env vars)"] +#[ignore = "stream_context_get_options shim function does not exist; cannot read back created context to assert"] fn test_ensure_thatfix_http_header_field_moves_content_type_to_end_of_options() { let _tear_down = TearDown; set_up(); @@ -107,17 +110,54 @@ fn test_ensure_thatfix_http_header_field_moves_content_type_to_end_of_options() } #[test] -#[ignore = "not yet ported (StreamContextFactory proxy/option building is driven by proxy env vars)"] +#[ignore] fn test_init_options_does_include_proxy_auth_headers() { let _tear_down = TearDown; set_up(); - todo!() + Platform::put_env( + "https_proxy", + "http://username:password@proxyserver.net:3128/", + ); + + let options: IndexMap<String, PhpMixed> = IndexMap::new(); + let options = + StreamContextFactory::init_options("https://example.org", options, false).unwrap(); + let header_list: Vec<String> = options + .get("http") + .and_then(|v| v.as_array()) + .and_then(|a| a.get("header")) + .and_then(|v| v.as_list()) + .unwrap() + .iter() + .filter_map(|item| item.as_string().map(|s| s.to_string())) + .collect(); + let headers = implode(" ", &header_list); + + assert!(stripos(&headers, "Proxy-Authorization").is_some()); } #[test] -#[ignore = "not yet ported (StreamContextFactory proxy/option building is driven by proxy env vars)"] +#[ignore] fn test_init_options_for_curl_does_not_include_proxy_auth_headers() { let _tear_down = TearDown; set_up(); - todo!() + Platform::put_env( + "http_proxy", + "http://username:password@proxyserver.net:3128/", + ); + + let options: IndexMap<String, PhpMixed> = IndexMap::new(); + let options = StreamContextFactory::init_options("https://example.org", options, true).unwrap(); + let header_list: Vec<String> = options + .get("http") + .and_then(|v| v.as_array()) + .and_then(|a| a.get("header")) + .and_then(|v| v.as_list()) + .unwrap() + .iter() + .filter_map(|item| item.as_string().map(|s| s.to_string())) + .collect(); + let headers = implode(" ", &header_list); + + assert!(stripos(&headers, "Proxy-Authorization").is_none()); } |
