diff options
| author | nsfisis <nsfisis@gmail.com> | 2026-08-11 00:07:15 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2026-08-11 00:08:05 +0900 |
| commit | 144d059b725e2d178d7f4a6403cde9474fe65dcc (patch) | |
| tree | 09f48dc2296a1c1e052018968b34fec31b364767 /crates/shirabe/tests/util | |
| parent | b65e338d4cf06afb8237512e49a51e354277196d (diff) | |
| download | php-shirabe-144d059b725e2d178d7f4a6403cde9474fe65dcc.tar.gz php-shirabe-144d059b725e2d178d7f4a6403cde9474fe65dcc.tar.zst php-shirabe-144d059b725e2d178d7f4a6403cde9474fe65dcc.zip | |
refactor(util): drop the unused TlsHelper port
Composer's Composer\Util\TlsHelper is marked deprecated for removal in
Composer 3.0 and has no caller in composer/composer outside its own
test: PHP's stream layer verifies certificate hostnames itself, and the
one surviving method delegates to composer/ca-bundle.
The Rust port had no caller either, so it, its test, and the
openssl_x509_parse shim it was the sole user of are removed.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Diffstat (limited to 'crates/shirabe/tests/util')
| -rw-r--r-- | crates/shirabe/tests/util/main.rs | 1 | ||||
| -rw-r--r-- | crates/shirabe/tests/util/tls_helper_test.rs | 138 |
2 files changed, 0 insertions, 139 deletions
diff --git a/crates/shirabe/tests/util/main.rs b/crates/shirabe/tests/util/main.rs index 0208ca48..05e8ea14 100644 --- a/crates/shirabe/tests/util/main.rs +++ b/crates/shirabe/tests/util/main.rs @@ -33,6 +33,5 @@ mod silencer_test; mod stream_context_factory_test; mod svn_test; mod tar_test; -mod tls_helper_test; mod url_test; mod zip_test; diff --git a/crates/shirabe/tests/util/tls_helper_test.rs b/crates/shirabe/tests/util/tls_helper_test.rs deleted file mode 100644 index 53e39d69..00000000 --- a/crates/shirabe/tests/util/tls_helper_test.rs +++ /dev/null @@ -1,138 +0,0 @@ -//! ref: composer/tests/Composer/Test/Util/TlsHelperTest.php - -use indexmap::IndexMap; -use shirabe::util::tls_helper::TlsHelper; -use shirabe_php_shim::PhpMixed; - -// Builds the `['subject' => ['commonName' => ..], 'extensions' => ['subjectAltName' => ..]]` -// certificate array used by the test, given the common name and the subjectAltName string. -fn certificate(common_name: &str, subject_alt_name: &str) -> PhpMixed { - let mut subject = IndexMap::new(); - subject.insert( - "commonName".to_string(), - PhpMixed::String(common_name.to_string()), - ); - let mut extensions = IndexMap::new(); - extensions.insert( - "subjectAltName".to_string(), - PhpMixed::String(subject_alt_name.to_string()), - ); - let mut cert = IndexMap::new(); - cert.insert("subject".to_string(), PhpMixed::Array(subject)); - cert.insert("extensions".to_string(), PhpMixed::Array(extensions)); - PhpMixed::Array(cert) -} - -/// ref: TlsHelperTest::dataCheckCertificateHost -fn data_check_certificate_host() -> Vec<(bool, &'static str, Vec<&'static str>)> { - vec![ - (true, "getcomposer.org", vec!["getcomposer.org"]), - ( - true, - "getcomposer.org", - vec!["getcomposer.org", "packagist.org"], - ), - ( - true, - "getcomposer.org", - vec!["packagist.org", "getcomposer.org"], - ), - (true, "foo.getcomposer.org", vec!["*.getcomposer.org"]), - (false, "xyz.foo.getcomposer.org", vec!["*.getcomposer.org"]), - ( - true, - "foo.getcomposer.org", - vec!["getcomposer.org", "*.getcomposer.org"], - ), - ( - true, - "foo.getcomposer.org", - vec!["foo.getcomposer.org", "foo*.getcomposer.org"], - ), - ( - true, - "foo1.getcomposer.org", - vec!["foo.getcomposer.org", "foo*.getcomposer.org"], - ), - ( - true, - "foo2.getcomposer.org", - vec!["foo.getcomposer.org", "foo*.getcomposer.org"], - ), - ( - false, - "foo2.another.getcomposer.org", - vec!["foo.getcomposer.org", "foo*.getcomposer.org"], - ), - ( - false, - "test.example.net", - vec!["**.example.net", "**.example.net"], - ), - ( - false, - "test.example.net", - vec!["t*t.example.net", "t*t.example.net"], - ), - ( - false, - "xyz.example.org", - vec!["*z.example.org", "*z.example.org"], - ), - ( - false, - "foo.bar.example.com", - vec!["foo.*.example.com", "foo.*.example.com"], - ), - (false, "example.com", vec!["example.*", "example.*"]), - (true, "localhost", vec!["localhost"]), - (false, "localhost", vec!["*"]), - (false, "localhost", vec!["local*"]), - (false, "example.net", vec!["*.net", "*.org", "ex*.net"]), - (true, "example.net", vec!["*.net", "*.org", "example.net"]), - ] -} - -#[test] -fn test_check_certificate_host() { - for (expected_result, hostname, mut cert_names) in data_check_certificate_host() { - let expected_cn = cert_names.remove(0); - let subject_alt_name = if cert_names.is_empty() { - String::new() - } else { - format!("DNS:{}", cert_names.join(",DNS:")) - }; - let cert = certificate(expected_cn, &subject_alt_name); - - let mut found_cn: Option<String> = None; - let result = TlsHelper::check_certificate_host(&cert, hostname, &mut found_cn); - - if expected_result { - assert!(result, "hostname {hostname} should match"); - assert_eq!(found_cn.as_deref(), Some(expected_cn)); - } else { - assert!(!result, "hostname {hostname} should not match"); - assert_eq!(found_cn, None); - } - } -} - -#[test] -fn test_get_certificate_names() { - let cert = certificate( - "example.net", - "DNS: example.com, IP: 127.0.0.1, DNS: getcomposer.org, Junk: blah, DNS: composer.example.org", - ); - - let names = TlsHelper::get_certificate_names(&cert).unwrap(); - - assert_eq!(names.cn, "example.net"); - assert_eq!( - names.san, - vec![ - "example.com".to_string(), - "getcomposer.org".to_string(), - "composer.example.org".to_string(), - ] - ); -} |
