fn x509_credentials_empty_success()

in crates/libs/core/src/types/common/security_credentials/x509_credentials.rs [220:275]


    fn x509_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_X509);

                let value = creds_ref.Value as *const FABRIC_X509_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: AllowedCommonNameCount and AllowedCommonNames go together. Should be valid for dereference.
                unsafe {
                    check_array_parameter(
                        [],
                        value_ref.AllowedCommonNameCount,
                        value_ref.AllowedCommonNames,
                    )
                };

                assert_eq!(value_ref.FindType, FABRIC_X509_FIND_TYPE_FINDBYSUBJECTNAME);
                let find_val_ptr = value_ref.FindValue as *const u16;
                assert!(!find_val_ptr.is_null() && find_val_ptr.is_aligned());
                let val_str = WStringWrap::from(PCWSTR::from_raw(find_val_ptr))
                    .into_wstring()
                    .to_string_lossy();
                assert_eq!(val_str.as_str(), TEST_SERVER_NAME_1);
                assert_eq!(
                    value_ref.StoreLocation,
                    FABRIC_X509_STORE_LOCATION_CURRENTUSER
                );
                assert_eq!(
                    WStringWrap::from(value_ref.StoreName)
                        .into_wstring()
                        .to_string_lossy()
                        .as_str(),
                    TEST_STORE_2
                );

                assert_eq!(value_ref.ProtectionLevel, FABRIC_PROTECTION_LEVEL_NONE);
                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_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)
    }