fn windows_credentials_filled_success()

in crates/libs/core/src/types/common/security_credentials/windows_credentials.rs [166:210]


    fn windows_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_WINDOWS);

                let value = creds_ref.Value as *const FABRIC_WINDOWS_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_REMOTE_IDENTITY_1, TEST_REMOTE_IDENTITY_2],
                        value_ref.RemoteIdentityCount,
                        value_ref.RemoteIdentities,
                    )
                };

                let remote_spn = WStringWrap::from(value_ref.RemoteSpn)
                    .into_wstring()
                    .to_string_lossy();
                assert_eq!(&remote_spn, TEST_REMOTE_SPN_1);

                assert_eq!(
                    value_ref.ProtectionLevel,
                    FABRIC_PROTECTION_LEVEL_ENCRYPTANDSIGN
                );
                assert!(value_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)
    }