Skip to content

Commit

Permalink
Updated the test cases for jni 0.21
Browse files Browse the repository at this point in the history
  • Loading branch information
Cyannide committed Nov 9, 2024
1 parent b26f0bc commit eb21840
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 13 deletions.
Binary file not shown.
20 changes: 10 additions & 10 deletions rustls-platform-verifier/src/tests/ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ mod android {
const SUCCESS_MARKER: &str = "success";

fn run_android_test<'a>(
env: &'a JNIEnv,
env: &'a mut JNIEnv,
cx: JObject,
suite_name: &'static str,
test_cases: &'static [fn()],
Expand Down Expand Up @@ -86,53 +86,53 @@ mod android {

#[export_name = "Java_org_rustls_platformverifier_CertificateVerifierTests_mockTests"]
pub extern "C" fn rustls_platform_verifier_mock_test_suite(
env: JNIEnv,
mut env: JNIEnv,
_class: JClass,
cx: JObject,
) -> jstring {
log::info!("running mock test suite...");

run_android_test(
&env,
&mut env,
cx,
"mock tests",
tests::verification_mock::ALL_TEST_CASES,
)
.into_inner()
.into_raw()
}

#[export_name = "Java_org_rustls_platformverifier_CertificateVerifierTests_verifyMockRootUsage"]
pub extern "C" fn rustls_platform_verifier_verify_mock_root_usage(
env: JNIEnv,
mut env: JNIEnv,
_class: JClass,
cx: JObject,
) -> jstring {
log::info!("verifying mock roots are not used by default...");

run_android_test(
&env,
&mut env,
cx,
"mock root verification",
&[tests::verification_mock::verification_without_mock_root],
)
.into_inner()
.into_raw()
}

#[export_name = "Java_org_rustls_platformverifier_CertificateVerifierTests_realWorldTests"]
pub extern "C" fn rustls_platform_verifier_real_world_test_suite(
env: JNIEnv,
mut env: JNIEnv,
_class: JClass,
cx: JObject,
) -> jstring {
log::info!("running real world suite...");

run_android_test(
&env,
&mut env,
cx,
"real world",
tests::verification_real_world::ALL_TEST_CASES,
)
.into_inner()
.into_raw()
}
}

Expand Down
5 changes: 2 additions & 3 deletions rustls-platform-verifier/src/verification/android.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,7 @@ impl Default for Verifier {
#[cfg(any(test, feature = "ffi-testing"))]
impl Drop for Verifier {
fn drop(&mut self) {
with_context::<_, ()>(|cx| {
let env = cx.env();
with_context::<_, ()>(|cx, env| {
env.call_static_method(CERT_VERIFIER_CLASS.get(cx)?, "clearMockRoots", "()V", &[])?
.v()?;
Ok(())
Expand Down Expand Up @@ -160,7 +159,7 @@ impl Verifier {
CERT_VERIFIER_CLASS.get(cx)?,
"addMockRoot",
"([B)V",
&[JValue::from(mock_root)],
&[JValue::from(&mock_root)],
)?
.v()
.expect("failed to add test root")
Expand Down

0 comments on commit eb21840

Please sign in to comment.