@@ -1788,6 +1788,55 @@ - (void)testAccountsWithAuthority_whenReturnSignedInAccountTrue_shouldFilterOutS
17881788 XCTAssertFalse ([accountUPNs
containsObject: @" [email protected] " ]);
17891789}
17901790
1791+ - (void )testAccountsWithAuthority_whenReturnSignedInAccountTrue_AndUserNameNil_shouldNotCrash
1792+ {
1793+ // setup default cache
1794+ [
self saveResponseWithUPN: @" [email protected] " 1795+ clientId: @" test_client_id"
1796+ authority: @" https://login.windows.net/common"
1797+ responseScopes: @" user.read user.write"
1798+ inputScopes: @" user.read user.write"
1799+ uid: @" uid"
1800+ utid: @" utid"
1801+ accessToken: @" access token"
1802+ refreshToken: @" refresh token"
1803+ familyId: @" 3"
1804+ accessor: _nonSSOAccessor];
1805+
1806+ [self saveResponseWithUPN: nil
1807+ clientId: @" test_client_id2"
1808+ authority: @" https://login.windows.net/common"
1809+ responseScopes: @" user.read user.write"
1810+ inputScopes: @" user.read user.write"
1811+ uid: @" uid2"
1812+ utid: @" utid2"
1813+ accessToken: @" access token"
1814+ refreshToken: @" refresh token 2"
1815+ familyId: nil
1816+ accessor: _nonSSOAccessor];
1817+
1818+ // sign out the second account
1819+ NSError *error;
1820+ XCTAssertTrue ([_accountMetadataCache updateSignInStateForHomeAccountId: @" uid2.utid2" clientId: @" test_client_id2" state: MSIDAccountMetadataStateSignedOut context: nil error: &error]);
1821+ XCTAssertNil (error);
1822+
1823+ // setup legacy cache
1824+ [
self saveResponseWithUPN: @" [email protected] " 1825+ clientId: @" test_client_id3"
1826+ authority: @" https://login.windows.net/common"
1827+ responseScopes: @" user.read user.write"
1828+ inputScopes: @" user.read user.write"
1829+ uid: @" uid3"
1830+ utid: @" utid3"
1831+ accessToken: @" access token"
1832+ refreshToken: @" refresh token 2"
1833+ familyId: @" 3"
1834+ accessor: _otherAccessor];
1835+
1836+ NSArray *accounts = [_defaultAccessor accountsWithAuthority: nil clientId: @" test_client_id2" familyId: @" 3" accountIdentifier: nil accountMetadataCache: _accountMetadataCache signedInAccountsOnly: YES context: nil error: &error];
1837+ XCTAssertEqual ([accounts count ], 2 );
1838+ }
1839+
17911840- (void )testAccountsWithAuthority_whenReturnSignedInAccountTrue_shouldFilterOutSignedOutAccountInBothDefaultAndLegacyCache
17921841{
17931842 // setup default cache
@@ -3117,7 +3166,15 @@ - (void)saveResponseWithUPN:(NSString *)upn
31173166 appIdentifier:(NSString *)appIdentifier
31183167 accessor:(id <MSIDCacheAccessor>)accessor
31193168{
3120- NSString *idToken = [MSIDTestIdTokenUtil idTokenWithPreferredUsername: upn subject: @" subject" givenName: @" Hello" familyName: @" World" name: @" Hello World" version: @" 2.0" tid: tenantId];
3169+ NSString *idToken = nil ;
3170+ if (!upn)
3171+ {
3172+ idToken = [MSIDTestIdTokenUtil idTokenWithGivenName: @" Hello" familyName: @" World" name: @" Hello World" version: @" 2.0" tid: tenantId];
3173+ }
3174+ else
3175+ {
3176+ idToken = [MSIDTestIdTokenUtil idTokenWithPreferredUsername: upn subject: @" subject" givenName: @" Hello" familyName: @" World" name: @" Hello World" version: @" 2.0" tid: tenantId];
3177+ }
31213178
31223179 MSIDTokenResponse *response = [MSIDTestTokenResponse v2TokenResponseWithAT: accessToken
31233180 RT: refreshToken
0 commit comments