Skip to content

Commit

Permalink
Add test for new_with_extra_roots
Browse files Browse the repository at this point in the history
  • Loading branch information
stormshield-gt committed Aug 26, 2024
1 parent 03a5fcd commit 1c21fed
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 4 deletions.
7 changes: 7 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions rustls-platform-verifier/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
43 changes: 39 additions & 4 deletions rustls-platform-verifier/src/tests/verification_mock/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>]()
}
}
)+

}
Expand All @@ -49,16 +57,30 @@ 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>]
}

),+

];
};

{@ $( $name:ident [ $target:meta ] => $test_case:expr ),+ , } => {
$(
#[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);
}
}
)+
};
Expand Down Expand Up @@ -301,11 +323,18 @@ mock_root_test_cases! {
},
}

fn test_with_mock_root<E: std::error::Error + PartialEq + 'static>(test_case: &TestCase<E>) {
fn test_with_mock_root<E: std::error::Error + PartialEq + 'static>(
test_case: &TestCase<E>,
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()
Expand Down Expand Up @@ -337,3 +366,9 @@ fn test_with_mock_root<E: std::error::Error + PartialEq + 'static>(test_case: &T
);
// TODO: get into specifics of errors returned when it fails.
}

enum Roots {
OnlyExtra,
#[cfg(all(unix, not(target_os = "android")))]
ExtraAndPlatform,
}

0 comments on commit 1c21fed

Please sign in to comment.