@@ -1450,7 +1450,7 @@ - (void)testRemoveAccessToken_whenTokenProvided_shouldRemoveToken
14501450 MSIDAccessToken *secondToken = accessTokens[1 ];
14511451
14521452 NSError *error = nil ;
1453- BOOL result = [_defaultAccessor removeAccessToken : secondToken context: nil error: &error];
1453+ BOOL result = [_defaultAccessor removeToken : secondToken context: nil error: &error];
14541454 XCTAssertTrue (result);
14551455 XCTAssertNil (error);
14561456
@@ -1462,10 +1462,63 @@ - (void)testRemoveAccessToken_whenTokenProvided_shouldRemoveToken
14621462 XCTAssertEqual ([remaininRefreshTokens count ], 1 );
14631463}
14641464
1465+ - (void )testRemoveIDToken_whenTokenProvided_shouldRemoveToken
1466+ {
1467+ // Save first token
1468+ [
self saveResponseWithUPN: @" [email protected] " 1469+ clientId: @" test_client_id2"
1470+ authority: @" https://login.windows.net/common"
1471+ responseScopes: @" user.read user.write"
1472+ inputScopes: @" user.read user.write"
1473+ uid: @" uid"
1474+ utid: @" utid"
1475+ accessToken: @" access token"
1476+ refreshToken: @" refresh token"
1477+ familyId: nil
1478+ accessor: _nonSSOAccessor];
1479+
1480+ // Save first token
1481+ [
self saveResponseWithUPN: @" [email protected] " 1482+ clientId: @" test_client_id"
1483+ authority: @" https://login.windows.net/common"
1484+ responseScopes: @" user.sing"
1485+ inputScopes: @" user.sing"
1486+ uid: @" uid"
1487+ utid: @" utid"
1488+ accessToken: @" access token"
1489+ refreshToken: @" refresh token"
1490+ familyId: nil
1491+ accessor: _nonSSOAccessor];
1492+
1493+ NSArray *accessTokens = [self getAllAccessTokens ];
1494+ XCTAssertEqual ([accessTokens count ], 2 );
1495+
1496+ NSArray *refreshTokens = [self getAllRefreshTokens ];
1497+ XCTAssertEqual ([refreshTokens count ], 2 );
1498+
1499+ NSArray *idTokens = [self getAllIDTokens ];
1500+ XCTAssertEqual ([idTokens count ], 2 );
1501+
1502+ MSIDIdToken *firstToken = idTokens[0 ];
1503+ MSIDIdToken *secondToken = idTokens[1 ];
1504+
1505+ NSError *error = nil ;
1506+ BOOL result = [_defaultAccessor removeToken: secondToken context: nil error: &error];
1507+ XCTAssertTrue (result);
1508+ XCTAssertNil (error);
1509+
1510+ NSArray *remainingIDTokens = [self getAllIDTokens ];
1511+ XCTAssertEqual ([remainingIDTokens count ], 1 );
1512+ XCTAssertEqualObjects (remainingIDTokens[0 ], firstToken);
1513+
1514+ NSArray *remaininRefreshTokens = [self getAllRefreshTokens ];
1515+ XCTAssertEqual ([remaininRefreshTokens count ], 2 );
1516+ }
1517+
14651518- (void )testRemoveAccessToken_whenNilTokenProvided_shouldReturnError
14661519{
14671520 NSError *error = nil ;
1468- BOOL result = [_defaultAccessor removeAccessToken :nil context: nil error: &error];
1521+ BOOL result = [_defaultAccessor removeToken :nil context: nil error: &error];
14691522 XCTAssertFalse (result);
14701523 XCTAssertNotNil (error);
14711524 XCTAssertEqual (error.code , MSIDErrorInternal);
@@ -1670,42 +1723,53 @@ - (void)testRemoveAccount_whenAccountNotNil_shouldRemoveAccount
16701723 XCTAssertNil (error);
16711724
16721725 accounts = [_defaultAccessor allAccountsForEnvironment: @" login.windows.net" clientId: @" test_client_id" familyId: nil context: nil error: &error];
1673- XCTAssertNil (accounts);
16741726 XCTAssertNil (error);
16751727 XCTAssertEqual ([accounts count ], 0 );
16761728}
16771729
1678- #pragma mark - RemoveAllTokensForAccount
1730+ #pragma mark - clearCacheForAccount
16791731
1680- - (void )testRemoveAllTokensForAccount_whenNilAccount_shouldReturnError
1732+ - (void )testClearCacheForAccount_whenNilAccount_shouldReturnError
16811733{
16821734 NSError *error = nil ;
1683- BOOL result = [_defaultAccessor removeAllTokensForAccount :nil environment: @" login.microsoftonline.com" clientId: @" test_client_id" context: nil error: &error];
1735+ BOOL result = [_defaultAccessor clearCacheForAccount :nil environment: @" login.microsoftonline.com" clientId: @" test_client_id" context: nil error: &error];
16841736 XCTAssertFalse (result);
16851737 XCTAssertNotNil (error);
16861738 XCTAssertEqual (error.code , MSIDErrorInternal);
16871739}
16881740
1689- - (void )testRemoveAllTokensForAccount_whenNilClientId_shouldReturnError
1741+ - (void )testClearCacheForAccount_whenNilClientId_shouldReturnError
16901742{
16911743 NSError *error = nil ;
1692- BOOL result = [_defaultAccessor removeAllTokensForAccount : [MSIDAccountIdentifier new ] environment: @" login.microsoftonline.com" clientId: nil context: nil error: &error];
1744+ BOOL result = [_defaultAccessor clearCacheForAccount : [MSIDAccountIdentifier new ] environment: @" login.microsoftonline.com" clientId: nil context: nil error: &error];
16931745 XCTAssertFalse (result);
16941746 XCTAssertNotNil (error);
16951747 XCTAssertEqual (error.code , MSIDErrorInternal);
16961748}
16971749
1698- - (void )testRemoveAllTokensForAccount_whenNilEnvironment_shouldReturnError
1750+ - (void )testClearCacheForAccount_whenNilEnvironment_shouldReturnError
16991751{
17001752 NSError *error = nil ;
1701- BOOL result = [_defaultAccessor removeAllTokensForAccount : [MSIDAccountIdentifier new ] environment: nil clientId: @" test" context: nil error: &error];
1753+ BOOL result = [_defaultAccessor clearCacheForAccount : [MSIDAccountIdentifier new ] environment: nil clientId: @" test" context: nil error: &error];
17021754 XCTAssertFalse (result);
17031755 XCTAssertNotNil (error);
17041756 XCTAssertEqual (error.code , MSIDErrorInternal);
17051757}
17061758
1707- - (void )testRemoveAllTokenForAccount_whenAccountProvided_shouldRemoveTokens
1759+ - (void )testClearCacheForAccount_whenAccountProvided_shouldRemoveTokens
17081760{
1761+ [
self saveResponseWithUPN: @" [email protected] " 1762+ clientId: @" test_client_id"
1763+ authority: @" https://login.windows.net/common"
1764+ responseScopes: @" user.sing"
1765+ inputScopes: @" user.sing"
1766+ uid: @" uid2"
1767+ utid: @" utid2"
1768+ accessToken: @" access token 2"
1769+ refreshToken: @" refresh token"
1770+ familyId: nil
1771+ accessor: _nonSSOAccessor];
1772+
17091773 [
self saveResponseWithUPN: @" [email protected] " 17101774 clientId: @" test_client_id"
17111775 authority: @" https://login.windows.net/common"
@@ -1735,35 +1799,64 @@ - (void)testRemoveAllTokenForAccount_whenAccountProvided_shouldRemoveTokens
17351799
17361800 XCTAssertNotNil (accounts);
17371801 XCTAssertNil (error);
1738- XCTAssertEqual ([accounts count ], 1 );
1802+ XCTAssertEqual ([accounts count ], 2 );
17391803
17401804 NSArray *allATs = [self getAllAccessTokens ];
1741- XCTAssertEqual ([allATs count ], 2 );
1805+ XCTAssertEqual ([allATs count ], 3 );
17421806
17431807 NSArray *allRTs = [self getAllRefreshTokens ];
1744- XCTAssertEqual ([allRTs count ], 1 );
1808+ XCTAssertEqual ([allRTs count ], 2 );
17451809
17461810 NSArray *allIDs = [self getAllIDTokens ];
1747- XCTAssertEqual ([allIDs count ], 1 );
1811+ XCTAssertEqual ([allIDs count ], 2 );
17481812
1749- MSIDAccount *account = accounts[0 ];
1813+ MSIDAccount *account = nil ;
1814+
1815+ for (MSIDAccount *accountInCache in accounts)
1816+ {
1817+ if ([accountInCache.homeAccountId isEqualToString: @" uid.utid" ])
1818+ {
1819+ account = accountInCache;
1820+ break ;
1821+ }
1822+ }
1823+
1824+ XCTAssertNotNil (account);
17501825
17511826 MSIDAccountIdentifier *identifier = [MSIDAccountIdentifier new ];
17521827 identifier.homeAccountId = account.homeAccountId ;
17531828 identifier.legacyAccountId = account.username ;
17541829
1755- BOOL result = [_defaultAccessor removeAllTokensForAccount : identifier environment: @" login.windows.net" clientId: @" test_client_id" context: nil error: &error];
1830+ BOOL result = [_defaultAccessor clearCacheForAccount : identifier environment: @" login.windows.net" clientId: @" test_client_id" context: nil error: &error];
17561831 XCTAssertTrue (result);
17571832 XCTAssertNil (error);
17581833
17591834 allATs = [self getAllAccessTokens ];
1760- XCTAssertEqual ([allATs count ], 0 );
1835+ XCTAssertEqual ([allATs count ], 1 );
1836+
1837+ MSIDAccessToken *accessToken = allATs[0 ];
1838+ XCTAssertEqualObjects (accessToken.homeAccountId , @" uid2.utid2" );
17611839
17621840 allRTs = [self getAllRefreshTokens ];
1763- XCTAssertEqual ([allRTs count ], 0 );
1841+ XCTAssertEqual ([allRTs count ], 1 );
1842+
1843+ MSIDRefreshToken *refreshToken = allRTs[0 ];
1844+ XCTAssertEqualObjects (refreshToken.homeAccountId , @" uid2.utid2" );
17641845
17651846 allIDs = [self getAllIDTokens ];
1766- XCTAssertEqual ([allIDs count ], 0 );
1847+ XCTAssertEqual ([allIDs count ], 1 );
1848+ MSIDIdToken *idToken = allIDs[0 ];
1849+ XCTAssertEqualObjects (idToken.homeAccountId , @" uid2.utid2" );
1850+
1851+ accounts = [_defaultAccessor allAccountsForEnvironment: @" login.windows.net"
1852+ clientId: @" test_client_id"
1853+ familyId: nil
1854+ context: nil
1855+ error: &error];
1856+ XCTAssertEqual ([accounts count ], 1 );
1857+
1858+ MSIDAccount *remainingAccount = accounts[0 ];
1859+ XCTAssertEqualObjects (remainingAccount.homeAccountId , @" uid2.utid2" );
17671860}
17681861
17691862#pragma mark - Helpers
0 commit comments