Search in sources :

Example 1 with AccountDeletionRecord

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());
}
Also used : OAuth2TokenCache(com.microsoft.identity.common.internal.providers.oauth2.OAuth2TokenCache) MicrosoftFamilyOAuth2TokenCache(com.microsoft.identity.common.internal.cache.MicrosoftFamilyOAuth2TokenCache) MsalOAuth2TokenCache(com.microsoft.identity.common.internal.cache.MsalOAuth2TokenCache) BrokerOAuth2TokenCache(com.microsoft.identity.common.internal.cache.BrokerOAuth2TokenCache) ICacheRecord(com.microsoft.identity.common.internal.cache.ICacheRecord) AccountDeletionRecord(com.microsoft.identity.common.internal.cache.AccountDeletionRecord) BrokerApplicationMetadata(com.microsoft.identity.common.internal.cache.BrokerApplicationMetadata) ArrayList(java.util.ArrayList) AccountRecord(com.microsoft.identity.common.internal.dto.AccountRecord) Test(org.junit.Test)

Example 2 with AccountDeletionRecord

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);
}
Also used : AccountDeletionRecord(com.microsoft.identity.common.internal.cache.AccountDeletionRecord) AccountRecord(com.microsoft.identity.common.internal.dto.AccountRecord) Test(org.junit.Test)

Example 3 with AccountDeletionRecord

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);
}
Also used : AccountDeletionRecord(com.microsoft.identity.common.internal.cache.AccountDeletionRecord) AccountRecord(com.microsoft.identity.common.internal.dto.AccountRecord) Test(org.junit.Test)

Example 4 with AccountDeletionRecord

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);
}
Also used : AccountDeletionRecord(com.microsoft.identity.common.internal.cache.AccountDeletionRecord) AccountRecord(com.microsoft.identity.common.internal.dto.AccountRecord) Test(org.junit.Test)

Example 5 with AccountDeletionRecord

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);
}
Also used : AccountDeletionRecord(com.microsoft.identity.common.internal.cache.AccountDeletionRecord) AccountRecord(com.microsoft.identity.common.internal.dto.AccountRecord) Test(org.junit.Test)

Aggregations

AccountDeletionRecord (com.microsoft.identity.common.internal.cache.AccountDeletionRecord)9 AccountRecord (com.microsoft.identity.common.internal.dto.AccountRecord)9 Test (org.junit.Test)9 BrokerApplicationMetadata (com.microsoft.identity.common.internal.cache.BrokerApplicationMetadata)1 BrokerOAuth2TokenCache (com.microsoft.identity.common.internal.cache.BrokerOAuth2TokenCache)1 ICacheRecord (com.microsoft.identity.common.internal.cache.ICacheRecord)1 MicrosoftFamilyOAuth2TokenCache (com.microsoft.identity.common.internal.cache.MicrosoftFamilyOAuth2TokenCache)1 MsalOAuth2TokenCache (com.microsoft.identity.common.internal.cache.MsalOAuth2TokenCache)1 OAuth2TokenCache (com.microsoft.identity.common.internal.providers.oauth2.OAuth2TokenCache)1 ArrayList (java.util.ArrayList)1