in crates/libs/core/src/types/common/security_credentials/claims_credentials.rs [212:278]
fn claims_credentials_filled_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(
[TEST_THUMBPRINT_1, TEST_THUMBPRINT_2],
value_ref.IssuerThumbprintCount,
value_ref.IssuerThumbprints,
)
};
let local_claim = WStringWrap::from(value_ref.LocalClaims)
.into_wstring()
.to_string_lossy();
assert_eq!(&local_claim, TEST_CLAIMS);
assert_eq!(
value_ref.ProtectionLevel,
FABRIC_PROTECTION_LEVEL_ENCRYPTANDSIGN
);
// SAFETY: ServerCommonNameCount and ServerCommonNames go together. Should be valid for dereference.
unsafe {
check_array_parameter(
[TEST_SERVER_NAME_1],
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(
[TEST_THUMBPRINT_3, TEST_THUMBPRINT_4],
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();
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)
}