From c24e9b8405b2dc2b3a92e904b2ea822310a94b04 Mon Sep 17 00:00:00 2001 From: Jakub Jelen Date: Wed, 11 Dec 2024 13:35:40 +0100 Subject: [PATCH] tests: Excercise parsing of various NSS options Signed-off-by: Jakub Jelen --- src/tests/nssdb.rs | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/src/tests/nssdb.rs b/src/tests/nssdb.rs index 87b285f..725888a 100644 --- a/src/tests/nssdb.rs +++ b/src/tests/nssdb.rs @@ -220,3 +220,48 @@ fn test_nssdb_init_token() { testtokn.finalize(); } + +#[test] +#[parallel] +fn test_nssdb_init_token_params() { + let name = String::from("test_nssdb_init_token_params"); + let datadir = format!("{}/{}", TESTDIR, name); + + let dbargs = format!( + "configDir={} \ + manufacturerID= \ + libraryDescription='My Library' \ + cryptoTokenDescription=\"My token description\" \ + dbTokenDescription=(db Token Description) \ + cryptoSlotDescription=[my slot description] \ + flags=passwordRequired", + datadir + ); + let dbtype = "nssdb"; + + let mut testtokn = + TestToken::new_type(String::from(dbtype), String::from(""), name); + + /* pre-populate conf so we get the correct slot number assigned */ + let mut slot = config::Slot::with_db(dbtype, Some(dbargs.clone())); + slot.slot = u32::try_from(testtokn.get_slot()).unwrap(); + let ret = add_slot(slot); + + assert_eq!(ret, CKR_OK); + let mut args = TestToken::make_init_args(Some(dbargs.clone())); + let args_ptr = &mut args as *mut CK_C_INITIALIZE_ARGS; + let ret = fn_initialize(args_ptr as *mut std::ffi::c_void); + assert_eq!(ret, CKR_OK); + + /* init once (NSSDB ignores SO pin) */ + let pin_value = "Unused"; + let ret = fn_init_token( + testtokn.get_slot(), + CString::new(pin_value).unwrap().into_raw() as *mut u8, + pin_value.len() as CK_ULONG, + std::ptr::null_mut(), + ); + assert_eq!(ret, CKR_OK); + + testtokn.finalize(); +}