in crates/libs/core/src/types/common/security_credentials/claims_credentials.rs [150:209]
fn claims_credentials_empty_success() {
let call_counter = Arc::new(Mutex::new(0));
let call_counter_copy = Arc::clone(&call_counter);
let com = MockIFabricClientSettings::new_with_security_credentials_mock(Box::new(
move |creds: *const FABRIC_SECURITY_CREDENTIALS| {
*call_counter_copy.lock().expect("Not poisoned") += 1;
assert!(!creds.is_null() && creds.is_aligned());
// SAFETY: test code. non-null and alignment is checked above
let creds_ref: &FABRIC_SECURITY_CREDENTIALS = unsafe { creds.as_ref() }.unwrap();
assert_eq!(creds_ref.Kind, FABRIC_SECURITY_CREDENTIAL_KIND_CLAIMS);
let value = creds_ref.Value as *const FABRIC_CLAIMS_CREDENTIALS;
assert!(!value.is_null() && value.is_aligned());
// SAFETY: test code. non-null and alignment is checked above
let value_ref = unsafe { value.as_ref() }.unwrap();
// SAFETY: IssuerThumbprintCount and IssuerThumbprints go together. Should be valid for dereference.
unsafe {
check_array_parameter(
[],
value_ref.IssuerThumbprintCount,
value_ref.IssuerThumbprints,
)
};
// SAFETY: test code. Should point to a null byte even when None.
assert!(unsafe { value_ref.LocalClaims.is_empty() });
assert_eq!(value_ref.ProtectionLevel, FABRIC_PROTECTION_LEVEL_SIGN);
// SAFETY: ServerCommonNameCount and ServerCommonNames go together. Should be valid for dereference.
unsafe {
check_array_parameter(
[],
value_ref.ServerCommonNameCount,
value_ref.ServerCommonNames,
)
};
let ex1 = value_ref.Reserved as *const FABRIC_CLAIMS_CREDENTIALS_EX1;
assert!(!ex1.is_null() && ex1.is_aligned());
// SAFETY: test code. non-null and alignment is checked above
let ex1_ref = unsafe { ex1.as_ref() }.unwrap();
// SAFETY: ServerThumbprintCount and ServerThumbprints go together. Should be valid for dereference.
unsafe {
check_array_parameter(
[],
ex1_ref.ServerThumbprintCount,
ex1_ref.ServerThumbprints,
)
};
assert!(ex1_ref.Reserved.is_null());
Ok(())
},
));
// SF might reject this in reality - that's ok, we're making sure our code doesn't have UB
let creds = make_credentials_with_empty_vecs();
let result = creds.apply_inner(com.into());
assert_eq!(result, Ok(()));
let actual_call_count = *call_counter.lock().expect("Not poisioned");
assert_eq!(actual_call_count, 1)
}