@@ -505,12 +505,17 @@ - (void)testGetWPJKeysWithNilTenantId_WithNoSecureEnclave_shouldReturnPrimaryReg
505505- (void )testGetWPJKeysWithTenantId_whenEccRegistrationWithTransportKey_shouldReturnBothKeys
506506{
507507 [self insertDummyEccRegistrationForTenantIdentifier: self .tenantId certIdentifier: kDummyTenant1CertIdentifier useSecureEnclave: YES ];
508- [self insertEccStkKeyForTenantIdentifier: self .tenantId];
509508 MSIDWPJKeyPairWithCert *result = [MSIDWorkPlaceJoinUtil getWPJKeysWithTenantId: self .tenantId context: nil ];
510509
511510 XCTAssertNotNil (result);
512511 XCTAssertEqual (result.keyChainVersion , MSIDWPJKeychainAccessGroupV2);
513512 XCTAssertTrue (result.privateKeyRef != NULL );
513+ XCTAssertTrue (result.privateTransportKeyRef == NULL );
514+
515+ [self insertEccStkKeyForTenantIdentifier: self .tenantId];
516+ result = [MSIDWorkPlaceJoinUtil getWPJKeysWithTenantId: self .tenantId context: nil ];
517+ XCTAssertEqual (result.keyChainVersion , MSIDWPJKeychainAccessGroupV2);
518+ XCTAssertTrue (result.privateKeyRef != NULL );
514519 XCTAssertTrue (result.privateTransportKeyRef != NULL );
515520}
516521
@@ -541,28 +546,6 @@ - (void)testGetWPJKeysWithTenantId_whenLegacyRegistration_shouldHaveNoTransportK
541546 XCTAssertTrue (result.privateKeyRef != NULL , @" Legacy registration should have device key" );
542547 XCTAssertTrue (result.privateTransportKeyRef == NULL , @" Legacy registration should not have transport key" );
543548}
544- /*
545- - (void)testGetWPJKeysWithTenantId_whenEccRegistrationWithMissingTransportKey_shouldReturnOnlyDeviceKey
546- {
547- NSString *tid = self.tenantId;
548- OSStatus status = [self insertDummyEccRegistrationForTenantIdentifier:tid certIdentifier:kDummyTenant1CertIdentifier useSecureEnclave:YES];
549- // Don't insert transport key - simulate missing STK scenario
550- if (status != errSecSuccess)
551- {
552- XCTFail(@"Could not insert WPJ registration for tenant %@. Error code: %d", tid, (int)status);
553- }
554- MSIDWPJKeyPairWithCert *result = [MSIDWorkPlaceJoinUtil getWPJKeysWithTenantId:tid context:nil];
555- if (!result)
556- {
557- XCTFail(@"Could not retrieve WPJ keys for tenant %@. result : %@", tid, result);
558- }
559-
560- XCTAssertNotNil(result);
561- XCTAssertEqual(result.keyChainVersion, MSIDWPJKeychainAccessGroupV2);
562- XCTAssertTrue(result.privateKeyRef != NULL);
563- XCTAssertTrue(result.privateTransportKeyRef == NULL, @"Expected privateTransportKeyRef to be nil when transport key is missing");
564- }
565- */
566549
567550- (void )testGetWPJKeysWithTenantId_whenRSARegistrationInV2Format_shouldNotHaveTransportKey
568551{
@@ -580,41 +563,6 @@ - (void)testGetWPJKeysWithTenantId_whenRSARegistrationInV2Format_shouldNotHaveTr
580563 XCTAssertTrue (result.privateTransportKeyRef == NULL , @" Expected privateTransportKeyRef to be nil for RSA registration in V2 format" );
581564}
582565
583- - (void )testGetWPJKeysWithTenantId_concurrentAccess_shouldBeThreadSafe
584- {
585- [self insertDummyEccRegistrationForTenantIdentifier: self .tenantId certIdentifier: kDummyTenant1CertIdentifier useSecureEnclave: YES ];
586- [self insertEccStkKeyForTenantIdentifier: self .tenantId];
587- dispatch_group_t group = dispatch_group_create ();
588- __block NSMutableArray *results = [NSMutableArray array ];
589- __block NSLock *lock = [[NSLock alloc ] init ];
590-
591- // Launch multiple concurrent requests
592- for (int i = 0 ; i < 5 ; i++) {
593- dispatch_group_async (group, dispatch_get_global_queue (DISPATCH_QUEUE_PRIORITY_DEFAULT, 0 ), ^{
594- MSIDWPJKeyPairWithCert *result = [MSIDWorkPlaceJoinUtil getWPJKeysWithTenantId: self .tenantId context: nil ];
595-
596- [lock lock ];
597- if (result) {
598- [results addObject: result];
599- }
600- [lock unlock ];
601- });
602- }
603-
604- // Wait for all requests to complete
605- dispatch_group_wait (group, dispatch_time (DISPATCH_TIME_NOW, 5 * NSEC_PER_SEC));
606-
607- // All requests should succeed
608- XCTAssertTrue (results.count == 5 , @" All concurrent requests should succeed" );
609-
610- // Verify all results have transport keys
611- for (MSIDWPJKeyPairWithCert *result in results) {
612- XCTAssertTrue (result.privateKeyRef != NULL );
613- XCTAssertTrue (result.privateTransportKeyRef != NULL );
614- }
615-
616- }
617-
618566#endif
619567
620568#pragma mark - Helpers
0 commit comments