From 1c21fedd705837ecb404dc9fccee4d2cede61513 Mon Sep 17 00:00:00 2001 From: stormshield-gt <143998166+stormshield-gt@users.noreply.github.com.> Date: Mon, 26 Aug 2024 09:15:27 +0200 Subject: [PATCH] Add test for new_with_extra_roots --- Cargo.lock | 7 +++ rustls-platform-verifier/Cargo.toml | 1 + .../src/tests/verification_mock/mod.rs | 43 +++++++++++++++++-- 3 files changed, 47 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index e54f400..90f67de 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -196,6 +196,12 @@ version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" +[[package]] +name = "paste" +version = "1.0.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "57c0d7b74b563b49d38dae00a0c37d4d6de9b432382b2892f0574ddcae73fd0a" + [[package]] name = "proc-macro2" version = "1.0.86" @@ -312,6 +318,7 @@ dependencies = [ "jni", "log", "once_cell", + "paste", "rustls", "rustls-native-certs", "rustls-platform-verifier-android", diff --git a/rustls-platform-verifier/Cargo.toml b/rustls-platform-verifier/Cargo.toml index 4680337..7b78d14 100644 --- a/rustls-platform-verifier/Cargo.toml +++ b/rustls-platform-verifier/Cargo.toml @@ -34,6 +34,7 @@ log = { version = "0.4" } base64 = { version = "0.22", optional = true } # Only used when the `cert-logging` feature is enabled. jni = { version = "0.19", default-features = false, optional = true } # Only used during doc generation once_cell = "1.9" +paste = "1.0.15" [target.'cfg(all(unix, not(target_os = "android"), not(target_os = "macos"), not(target_os = "ios"), not(target_os = "tvos"), not(target_arch = "wasm32")))'.dependencies] rustls-native-certs = "0.7" diff --git a/rustls-platform-verifier/src/tests/verification_mock/mod.rs b/rustls-platform-verifier/src/tests/verification_mock/mod.rs index 87d0294..1e4b7a4 100644 --- a/rustls-platform-verifier/src/tests/verification_mock/mod.rs +++ b/rustls-platform-verifier/src/tests/verification_mock/mod.rs @@ -41,6 +41,14 @@ macro_rules! mock_root_test_cases { pub fn $name() { super::$name() } + + paste::paste!{ + #[cfg(all($target, not(windows), not(target_os = "android")))] + #[test] + pub fn [<$name _extra>](){ + super::[<$name _extra>]() + } + } )+ } @@ -49,8 +57,15 @@ macro_rules! mock_root_test_cases { pub static ALL_TEST_CASES: &'static [fn()] = &[ $( #[cfg($target)] - $name + $name, + + paste::paste!{ + #[cfg(all($target, not(windows), not(target_os = "android")))] + [<$name _extra>] + } + ),+ + ]; }; @@ -58,7 +73,14 @@ macro_rules! mock_root_test_cases { $( #[cfg($target)] pub(super) fn $name() { - test_with_mock_root(&$test_case); + test_with_mock_root(&$test_case, Roots::OnlyExtra); + } + + paste::paste!{ + #[cfg(all($target, not(windows), not(target_os = "android")))] + pub(super) fn [<$name _extra>]() { + test_with_mock_root(&$test_case, Roots::ExtraAndPlatform); + } } )+ }; @@ -301,11 +323,18 @@ mock_root_test_cases! { }, } -fn test_with_mock_root(test_case: &TestCase) { +fn test_with_mock_root( + test_case: &TestCase, + root_src: Roots, +) { ensure_global_state(); log::info!("verifying {:?}", test_case.expected_result); - let verifier = Verifier::new_with_fake_root(ROOT1); // TODO: time + let verifier = match root_src { + Roots::OnlyExtra => Verifier::new_with_fake_root(ROOT1), // TODO: time + #[cfg(all(unix, not(target_os = "android")))] + Roots::ExtraAndPlatform => Verifier::new_with_extra_roots([ROOT1]), + }; let mut chain = test_case .chain .iter() @@ -337,3 +366,9 @@ fn test_with_mock_root(test_case: &T ); // TODO: get into specifics of errors returned when it fails. } + +enum Roots { + OnlyExtra, + #[cfg(all(unix, not(target_os = "android")))] + ExtraAndPlatform, +}