summaryrefslogtreecommitdiffstats
path: root/third_party/rust/neqo-crypto/tests/init.rs
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--third_party/rust/neqo-crypto/tests/init.rs51
1 files changed, 40 insertions, 11 deletions
diff --git a/third_party/rust/neqo-crypto/tests/init.rs b/third_party/rust/neqo-crypto/tests/init.rs
index 13218cc340..ee7d808e29 100644
--- a/third_party/rust/neqo-crypto/tests/init.rs
+++ b/third_party/rust/neqo-crypto/tests/init.rs
@@ -15,13 +15,7 @@ use neqo_crypto::{assert_initialized, init_db};
// Pull in the NSS internals so that we can ask NSS if it thinks that
// it is properly initialized.
-#[allow(
- dead_code,
- non_upper_case_globals,
- clippy::redundant_static_lifetimes,
- clippy::unseparated_literal_suffix,
- clippy::upper_case_acronyms
-)]
+#[allow(dead_code, non_upper_case_globals)]
mod nss {
include!(concat!(env!("OUT_DIR"), "/nss_init.rs"));
}
@@ -29,19 +23,54 @@ mod nss {
#[cfg(nss_nodb)]
#[test]
fn init_nodb() {
- init();
+ neqo_crypto::init().unwrap();
assert_initialized();
unsafe {
- assert!(nss::NSS_IsInitialized() != 0);
+ assert_ne!(nss::NSS_IsInitialized(), 0);
}
}
+#[cfg(nss_nodb)]
+#[test]
+fn init_twice_nodb() {
+ unsafe {
+ nss::NSS_NoDB_Init(std::ptr::null());
+ assert_ne!(nss::NSS_IsInitialized(), 0);
+ }
+ // Now do it again
+ init_nodb();
+}
+
#[cfg(not(nss_nodb))]
#[test]
fn init_withdb() {
- init_db(::test_fixture::NSS_DB_PATH);
+ init_db(::test_fixture::NSS_DB_PATH).unwrap();
assert_initialized();
unsafe {
- assert!(nss::NSS_IsInitialized() != 0);
+ assert_ne!(nss::NSS_IsInitialized(), 0);
+ }
+}
+
+#[cfg(not(nss_nodb))]
+#[test]
+fn init_twice_withdb() {
+ use std::{ffi::CString, path::PathBuf};
+
+ let empty = CString::new("").unwrap();
+ let path: PathBuf = ::test_fixture::NSS_DB_PATH.into();
+ assert!(path.is_dir());
+ let pathstr = path.to_str().unwrap();
+ let dircstr = CString::new(pathstr).unwrap();
+ unsafe {
+ nss::NSS_Initialize(
+ dircstr.as_ptr(),
+ empty.as_ptr(),
+ empty.as_ptr(),
+ nss::SECMOD_DB.as_ptr().cast(),
+ nss::NSS_INIT_READONLY,
+ );
+ assert_ne!(nss::NSS_IsInitialized(), 0);
}
+ // Now do it again
+ init_withdb();
}