use of com.microsoft.identity.common.internal.cache.AccountDeletionRecord in project microsoft-authentication-library-common-for-android by AzureAD.
the class BrokerOAuth2TokenCacheTest method testRemoveAccountFromDevice.
@Test
public void testRemoveAccountFromDevice() throws ClientException {
// Load up the 'other caches' which a bunch of test credentials, see if we can get them out...
int ii = 0;
for (final OAuth2TokenCache cache : mOtherAppTokenCaches) {
configureMocks(mOtherCacheTestBundles.get(ii));
final ICacheRecord cacheRecord = cache.save(mockStrategy, mockRequest, mockResponse);
final BrokerApplicationMetadata applicationMetadata = new BrokerApplicationMetadata();
applicationMetadata.setClientId(cacheRecord.getIdToken().getClientId());
applicationMetadata.setEnvironment(cacheRecord.getIdToken().getEnvironment());
applicationMetadata.setFoci(cacheRecord.getRefreshToken().getFamilyId());
applicationMetadata.setUid(testAppUids[ii++]);
mApplicationMetadataCache.insert(applicationMetadata);
}
final List<String> clientIds = new ArrayList<>();
for (final MsalOAuth2TokenCacheTest.AccountCredentialTestBundle testBundle : mOtherCacheTestBundles) {
clientIds.add(testBundle.mGeneratedRefreshToken.getClientId());
}
final List<AccountRecord> xAppAccounts = mBrokerOAuth2TokenCache.getAccounts();
// Deleting one of these AccountRecords should remove all of them...
final AccountDeletionRecord deletionRecord = mBrokerOAuth2TokenCache.removeAccountFromDevice(xAppAccounts.get(0));
assertEquals(xAppAccounts.size(), deletionRecord.size());
assertEquals(0, mBrokerOAuth2TokenCache.getAccounts().size());
}
use of com.microsoft.identity.common.internal.cache.AccountDeletionRecord in project microsoft-authentication-library-common-for-android by AzureAD.
the class MsalCppOAuth2TokenCacheTest method forceRemoveAccountWithHomeAccountIdTest.
@Test
public void forceRemoveAccountWithHomeAccountIdTest() throws ClientException {
// Get the generated account
final AccountRecord generatedAccount = mTestBundle.mGeneratedAccount;
// Save it to the cache
mCppCache.saveAccountRecord(generatedAccount);
// Do not save any credentials for this account...
final AccountDeletionRecord deletionRecord = mCppCache.forceRemoveAccount(generatedAccount.getHomeAccountId(), "", "");
Assert.assertEquals(1, deletionRecord.size());
// Try to restore it
final AccountRecord restoredAccount = mCppCache.getAccount(generatedAccount.getHomeAccountId(), generatedAccount.getEnvironment(), generatedAccount.getRealm());
// Make sure it doesn't exist....
Assert.assertNull(restoredAccount);
}
use of com.microsoft.identity.common.internal.cache.AccountDeletionRecord in project microsoft-authentication-library-common-for-android by AzureAD.
the class MsalCppOAuth2TokenCacheTest method removeAccountNoRTTest.
@Test
public void removeAccountNoRTTest() throws ClientException {
// Get the generated account
final AccountRecord generatedAccount = mTestBundle.mGeneratedAccount;
// Save it to the cache
mCppCache.saveAccountRecord(generatedAccount);
// Call remove
final AccountDeletionRecord deletionRecord = mCppCache.removeAccount(generatedAccount.getHomeAccountId(), generatedAccount.getEnvironment(), generatedAccount.getRealm());
// Check the receipt
Assert.assertEquals(generatedAccount, deletionRecord.get(0));
// Try to restore it
final AccountRecord restoredAccount = mCppCache.getAccount(generatedAccount.getHomeAccountId(), generatedAccount.getEnvironment(), generatedAccount.getRealm());
// Make sure it doesn't exist....
Assert.assertNull(restoredAccount);
}
use of com.microsoft.identity.common.internal.cache.AccountDeletionRecord in project microsoft-authentication-library-common-for-android by AzureAD.
the class MsalCppOAuth2TokenCacheTest method removeTwoAccountsWithDifferentRealmsAndEnvironmentsTest.
@Test
public void removeTwoAccountsWithDifferentRealmsAndEnvironmentsTest() throws ClientException {
// Get the generated account
final AccountRecord generatedAccount = mTestBundle.mGeneratedAccount;
// Save it to the cache
mCppCache.saveAccountRecord(generatedAccount);
mCppCache.saveCredentials(null, mTestBundle.mGeneratedRefreshToken);
// Save the second account with a different realm and environment
generatedAccount.setEnvironment("login.chinacloudapi.cn");
generatedAccount.setRealm(REALM2);
mCppCache.saveAccountRecord(generatedAccount);
// Call remove
final AccountDeletionRecord deletionRecord = mCppCache.removeAccount(generatedAccount.getHomeAccountId(), "", "");
// Check the receipt, should delete both
Assert.assertEquals(2, deletionRecord.size());
// Try to restore them
final AccountRecord restoredAccount = mCppCache.getAccount(generatedAccount.getHomeAccountId(), generatedAccount.getEnvironment(), REALM);
final AccountRecord restoredAccount2 = mCppCache.getAccount(generatedAccount.getHomeAccountId(), "login.chinacloudapi.cn", REALM2);
// Make sure they don't exist....
Assert.assertNull(restoredAccount);
Assert.assertNull(restoredAccount2);
}
use of com.microsoft.identity.common.internal.cache.AccountDeletionRecord in project microsoft-authentication-library-common-for-android by AzureAD.
the class MsalCppOAuth2TokenCacheTest method forceRemoveAccountTest.
@Test
public void forceRemoveAccountTest() throws ClientException {
// Get the generated account
final AccountRecord generatedAccount = mTestBundle.mGeneratedAccount;
// Save it to the cache
mCppCache.saveAccountRecord(generatedAccount);
// Do not save any credentials for this account...
final AccountDeletionRecord deletionRecord = mCppCache.forceRemoveAccount(generatedAccount.getHomeAccountId(), generatedAccount.getEnvironment(), generatedAccount.getRealm());
Assert.assertEquals(1, deletionRecord.size());
// Try to restore it
final AccountRecord restoredAccount = mCppCache.getAccount(generatedAccount.getHomeAccountId(), generatedAccount.getEnvironment(), generatedAccount.getRealm());
// Make sure it doesn't exist....
Assert.assertNull(restoredAccount);
}
Aggregations