@@ -1450,7 +1450,7 @@ - (void)testRemoveAccessToken_whenTokenProvided_shouldRemoveToken
1450
1450
MSIDAccessToken *secondToken = accessTokens[1 ];
1451
1451
1452
1452
NSError *error = nil ;
1453
- BOOL result = [_defaultAccessor removeAccessToken : secondToken context: nil error: &error];
1453
+ BOOL result = [_defaultAccessor removeToken : secondToken context: nil error: &error];
1454
1454
XCTAssertTrue (result);
1455
1455
XCTAssertNil (error);
1456
1456
@@ -1462,10 +1462,63 @@ - (void)testRemoveAccessToken_whenTokenProvided_shouldRemoveToken
1462
1462
XCTAssertEqual ([remaininRefreshTokens count ], 1 );
1463
1463
}
1464
1464
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
+
1465
1518
- (void )testRemoveAccessToken_whenNilTokenProvided_shouldReturnError
1466
1519
{
1467
1520
NSError *error = nil ;
1468
- BOOL result = [_defaultAccessor removeAccessToken :nil context: nil error: &error];
1521
+ BOOL result = [_defaultAccessor removeToken :nil context: nil error: &error];
1469
1522
XCTAssertFalse (result);
1470
1523
XCTAssertNotNil (error);
1471
1524
XCTAssertEqual (error.code , MSIDErrorInternal);
@@ -1670,42 +1723,53 @@ - (void)testRemoveAccount_whenAccountNotNil_shouldRemoveAccount
1670
1723
XCTAssertNil (error);
1671
1724
1672
1725
accounts = [_defaultAccessor allAccountsForEnvironment: @" login.windows.net" clientId: @" test_client_id" familyId: nil context: nil error: &error];
1673
- XCTAssertNil (accounts);
1674
1726
XCTAssertNil (error);
1675
1727
XCTAssertEqual ([accounts count ], 0 );
1676
1728
}
1677
1729
1678
- #pragma mark - RemoveAllTokensForAccount
1730
+ #pragma mark - clearCacheForAccount
1679
1731
1680
- - (void )testRemoveAllTokensForAccount_whenNilAccount_shouldReturnError
1732
+ - (void )testClearCacheForAccount_whenNilAccount_shouldReturnError
1681
1733
{
1682
1734
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];
1684
1736
XCTAssertFalse (result);
1685
1737
XCTAssertNotNil (error);
1686
1738
XCTAssertEqual (error.code , MSIDErrorInternal);
1687
1739
}
1688
1740
1689
- - (void )testRemoveAllTokensForAccount_whenNilClientId_shouldReturnError
1741
+ - (void )testClearCacheForAccount_whenNilClientId_shouldReturnError
1690
1742
{
1691
1743
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];
1693
1745
XCTAssertFalse (result);
1694
1746
XCTAssertNotNil (error);
1695
1747
XCTAssertEqual (error.code , MSIDErrorInternal);
1696
1748
}
1697
1749
1698
- - (void )testRemoveAllTokensForAccount_whenNilEnvironment_shouldReturnError
1750
+ - (void )testClearCacheForAccount_whenNilEnvironment_shouldReturnError
1699
1751
{
1700
1752
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];
1702
1754
XCTAssertFalse (result);
1703
1755
XCTAssertNotNil (error);
1704
1756
XCTAssertEqual (error.code , MSIDErrorInternal);
1705
1757
}
1706
1758
1707
- - (void )testRemoveAllTokenForAccount_whenAccountProvided_shouldRemoveTokens
1759
+ - (void )testClearCacheForAccount_whenAccountProvided_shouldRemoveTokens
1708
1760
{
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
+
1709
1773
[
self saveResponseWithUPN: @" [email protected] "
1710
1774
clientId: @" test_client_id"
1711
1775
authority: @" https://login.windows.net/common"
@@ -1735,35 +1799,64 @@ - (void)testRemoveAllTokenForAccount_whenAccountProvided_shouldRemoveTokens
1735
1799
1736
1800
XCTAssertNotNil (accounts);
1737
1801
XCTAssertNil (error);
1738
- XCTAssertEqual ([accounts count ], 1 );
1802
+ XCTAssertEqual ([accounts count ], 2 );
1739
1803
1740
1804
NSArray *allATs = [self getAllAccessTokens ];
1741
- XCTAssertEqual ([allATs count ], 2 );
1805
+ XCTAssertEqual ([allATs count ], 3 );
1742
1806
1743
1807
NSArray *allRTs = [self getAllRefreshTokens ];
1744
- XCTAssertEqual ([allRTs count ], 1 );
1808
+ XCTAssertEqual ([allRTs count ], 2 );
1745
1809
1746
1810
NSArray *allIDs = [self getAllIDTokens ];
1747
- XCTAssertEqual ([allIDs count ], 1 );
1811
+ XCTAssertEqual ([allIDs count ], 2 );
1748
1812
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);
1750
1825
1751
1826
MSIDAccountIdentifier *identifier = [MSIDAccountIdentifier new ];
1752
1827
identifier.homeAccountId = account.homeAccountId ;
1753
1828
identifier.legacyAccountId = account.username ;
1754
1829
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];
1756
1831
XCTAssertTrue (result);
1757
1832
XCTAssertNil (error);
1758
1833
1759
1834
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" );
1761
1839
1762
1840
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" );
1764
1845
1765
1846
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" );
1767
1860
}
1768
1861
1769
1862
#pragma mark - Helpers
0 commit comments