Skip to content

Commit

Permalink
tests: Excercise parsing of various NSS options
Browse files Browse the repository at this point in the history
Signed-off-by: Jakub Jelen <[email protected]>
  • Loading branch information
Jakuje committed Dec 11, 2024
1 parent cae9b03 commit 602e321
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions src/tests/nssdb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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=<My Kryoptic> \
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();
}

0 comments on commit 602e321

Please sign in to comment.