Search in sources :

Example 1 with ICacheRecord

use of com.microsoft.identity.common.internal.cache.ICacheRecord in project microsoft-authentication-library-common-for-android by AzureAD.

the class BrokerOAuth2TokenCacheTest method testWPJSaveNonFoci.

@Test
public void testWPJSaveNonFoci() throws ClientException {
    final ICacheRecord saveResult = mBrokerOAuth2TokenCache.save(mDefaultAppUidTestBundle.mGeneratedAccount, mDefaultAppUidTestBundle.mGeneratedIdToken, mDefaultAppUidTestBundle.mGeneratedAccessToken, mDefaultAppUidTestBundle.mGeneratedRefreshToken, null);
    assertNotNull(saveResult);
    assertNotNull(saveResult.getAccount());
    assertNotNull(saveResult.getIdToken());
    assertNotNull(saveResult.getAccessToken());
    assertNotNull(saveResult.getRefreshToken());
    assertEquals(mDefaultAppUidTestBundle.mGeneratedAccount, saveResult.getAccount());
    assertEquals(mDefaultAppUidTestBundle.mGeneratedIdToken, saveResult.getIdToken());
    assertEquals(mDefaultAppUidTestBundle.mGeneratedAccessToken, saveResult.getAccessToken());
    assertEquals(mDefaultAppUidTestBundle.mGeneratedRefreshToken, saveResult.getRefreshToken());
    final ICacheRecord retrievedResult = mBrokerOAuth2TokenCache.load(mDefaultAppUidTestBundle.mGeneratedIdToken.getClientId(), mDefaultAppUidTestBundle.mGeneratedAccessToken.getTarget(), mDefaultAppUidTestBundle.mGeneratedAccount, BEARER_AUTHENTICATION_SCHEME);
    assertNotNull(retrievedResult);
    assertNotNull(retrievedResult.getAccount());
    assertNotNull(retrievedResult.getIdToken());
    assertNotNull(retrievedResult.getAccessToken());
    assertNotNull(retrievedResult.getRefreshToken());
    assertEquals(mDefaultAppUidTestBundle.mGeneratedAccount, retrievedResult.getAccount());
    assertEquals(mDefaultAppUidTestBundle.mGeneratedIdToken, retrievedResult.getIdToken());
    assertEquals(mDefaultAppUidTestBundle.mGeneratedAccessToken, retrievedResult.getAccessToken());
    assertEquals(mDefaultAppUidTestBundle.mGeneratedRefreshToken, saveResult.getRefreshToken());
}
Also used : ICacheRecord(com.microsoft.identity.common.internal.cache.ICacheRecord) Test(org.junit.Test)

Example 2 with ICacheRecord

use of com.microsoft.identity.common.internal.cache.ICacheRecord in project microsoft-authentication-library-common-for-android by AzureAD.

the class BrokerOAuth2TokenCacheTest method testWPJSaveNonFoci_deprecated.

@Test
public void testWPJSaveNonFoci_deprecated() throws ClientException {
    final ICacheRecord saveResult = mBrokerOAuth2TokenCache.save(mDefaultAppUidTestBundle.mGeneratedAccount, mDefaultAppUidTestBundle.mGeneratedIdToken, mDefaultAppUidTestBundle.mGeneratedAccessToken, null);
    assertNotNull(saveResult);
    assertNotNull(saveResult.getAccount());
    assertNotNull(saveResult.getIdToken());
    assertNotNull(saveResult.getAccessToken());
    assertNull(saveResult.getRefreshToken());
    assertEquals(mDefaultAppUidTestBundle.mGeneratedAccount, saveResult.getAccount());
    assertEquals(mDefaultAppUidTestBundle.mGeneratedIdToken, saveResult.getIdToken());
    assertEquals(mDefaultAppUidTestBundle.mGeneratedAccessToken, saveResult.getAccessToken());
    final ICacheRecord retrievedResult = mBrokerOAuth2TokenCache.load(mDefaultAppUidTestBundle.mGeneratedIdToken.getClientId(), mDefaultAppUidTestBundle.mGeneratedAccessToken.getTarget(), mDefaultAppUidTestBundle.mGeneratedAccount, BEARER_AUTHENTICATION_SCHEME);
    assertNotNull(retrievedResult);
    assertNotNull(retrievedResult.getAccount());
    assertNotNull(retrievedResult.getIdToken());
    assertNotNull(retrievedResult.getAccessToken());
    assertNull(retrievedResult.getRefreshToken());
    assertEquals(mDefaultAppUidTestBundle.mGeneratedAccount, retrievedResult.getAccount());
    assertEquals(mDefaultAppUidTestBundle.mGeneratedIdToken, retrievedResult.getIdToken());
    assertEquals(mDefaultAppUidTestBundle.mGeneratedAccessToken, retrievedResult.getAccessToken());
}
Also used : ICacheRecord(com.microsoft.identity.common.internal.cache.ICacheRecord) Test(org.junit.Test)

Example 3 with ICacheRecord

use of com.microsoft.identity.common.internal.cache.ICacheRecord in project microsoft-authentication-library-common-for-android by AzureAD.

the class BrokerOAuth2TokenCacheTest method testWPJSaveFoci_deprecated.

@Test
public void testWPJSaveFoci_deprecated() throws ClientException {
    final ICacheRecord saveResult = mBrokerOAuth2TokenCache.save(mDefaultFociTestBundle.mGeneratedAccount, mDefaultFociTestBundle.mGeneratedIdToken, mDefaultFociTestBundle.mGeneratedAccessToken, "1");
    assertNotNull(saveResult);
    assertNotNull(saveResult.getAccount());
    assertNotNull(saveResult.getIdToken());
    assertNotNull(saveResult.getAccessToken());
    assertNull(saveResult.getRefreshToken());
    assertEquals(mDefaultFociTestBundle.mGeneratedAccount, saveResult.getAccount());
    assertEquals(mDefaultFociTestBundle.mGeneratedIdToken, saveResult.getIdToken());
    assertEquals(mDefaultFociTestBundle.mGeneratedAccessToken, saveResult.getAccessToken());
    final ICacheRecord retrievedResult = mBrokerOAuth2TokenCache.load(mDefaultFociTestBundle.mGeneratedIdToken.getClientId(), mDefaultFociTestBundle.mGeneratedAccessToken.getTarget(), mDefaultFociTestBundle.mGeneratedAccount, BEARER_AUTHENTICATION_SCHEME);
    assertNotNull(retrievedResult);
    assertNotNull(retrievedResult.getAccount());
    assertNotNull(retrievedResult.getIdToken());
    assertNotNull(retrievedResult.getAccessToken());
    assertNull(retrievedResult.getRefreshToken());
    assertEquals(mDefaultFociTestBundle.mGeneratedAccount, retrievedResult.getAccount());
    assertEquals(mDefaultFociTestBundle.mGeneratedIdToken, retrievedResult.getIdToken());
    assertEquals(mDefaultFociTestBundle.mGeneratedAccessToken, retrievedResult.getAccessToken());
}
Also used : ICacheRecord(com.microsoft.identity.common.internal.cache.ICacheRecord) Test(org.junit.Test)

Example 4 with ICacheRecord

use of com.microsoft.identity.common.internal.cache.ICacheRecord in project microsoft-authentication-library-common-for-android by AzureAD.

the class BrokerOAuth2TokenCacheTest method testRemoveCredentialAppUidCache.

@Test
public void testRemoveCredentialAppUidCache() throws ClientException {
    configureMocksForAppUid();
    mBrokerOAuth2TokenCache.save(mockStrategy, mockRequest, mockResponse);
    final ICacheRecord cacheRecord = mBrokerOAuth2TokenCache.load(CLIENT_ID, TARGET, mDefaultAppUidTestBundle.mGeneratedAccount, BEARER_AUTHENTICATION_SCHEME);
    assertTrue(mBrokerOAuth2TokenCache.removeCredential(mDefaultAppUidTestBundle.mGeneratedAccessToken));
}
Also used : ICacheRecord(com.microsoft.identity.common.internal.cache.ICacheRecord) Test(org.junit.Test)

Example 5 with ICacheRecord

use of com.microsoft.identity.common.internal.cache.ICacheRecord in project microsoft-authentication-library-common-for-android by AzureAD.

the class BrokerOAuth2TokenCacheTest method testGetAccountsAdal.

@Test
public void testGetAccountsAdal() 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 = new ArrayList<>();
    for (final int testUid : testAppUids) {
        // Create the cache to query...
        mBrokerOAuth2TokenCache = new BrokerOAuth2TokenCache(InstrumentationRegistry.getContext(), testUid, mApplicationMetadataCache, new BrokerOAuth2TokenCache.ProcessUidCacheFactory() {

            @Override
            public MsalOAuth2TokenCache getTokenCache(Context context, int bindingProcessUid) {
                return initAppUidCache(context, bindingProcessUid);
            }
        }, mFociCache);
        for (final String clientId : clientIds) {
            final List<AccountRecord> accountsInCache = mBrokerOAuth2TokenCache.getAccounts(ENVIRONMENT, clientId);
            xAppAccounts.addAll(accountsInCache);
        }
    }
    assertEquals(clientIds.size(), xAppAccounts.size());
    final List<AccountRecord> xAppAccountsNoParam = new ArrayList<>(mBrokerOAuth2TokenCache.getAccounts());
    assertEquals(xAppAccounts.size(), xAppAccountsNoParam.size());
}
Also used : Context(android.content.Context) ICacheRecord(com.microsoft.identity.common.internal.cache.ICacheRecord) BrokerApplicationMetadata(com.microsoft.identity.common.internal.cache.BrokerApplicationMetadata) ArrayList(java.util.ArrayList) 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) AccountRecord(com.microsoft.identity.common.internal.dto.AccountRecord) BrokerOAuth2TokenCache(com.microsoft.identity.common.internal.cache.BrokerOAuth2TokenCache) Test(org.junit.Test)

Aggregations

ICacheRecord (com.microsoft.identity.common.internal.cache.ICacheRecord)51 Test (org.junit.Test)40 AccountRecord (com.microsoft.identity.common.internal.dto.AccountRecord)11 ArrayList (java.util.ArrayList)5 MsalOAuth2TokenCache (com.microsoft.identity.common.internal.cache.MsalOAuth2TokenCache)4 OAuth2TokenCache (com.microsoft.identity.common.internal.providers.oauth2.OAuth2TokenCache)4 AcquireTokenResult (com.microsoft.identity.common.internal.result.AcquireTokenResult)4 LocalAuthenticationResult (com.microsoft.identity.common.internal.result.LocalAuthenticationResult)4 ApiEndEvent (com.microsoft.identity.common.internal.telemetry.events.ApiEndEvent)4 ApiStartEvent (com.microsoft.identity.common.internal.telemetry.events.ApiStartEvent)4 ClientException (com.microsoft.identity.common.exception.ClientException)3 BearerAuthenticationSchemeInternal (com.microsoft.identity.common.internal.authscheme.BearerAuthenticationSchemeInternal)3 BrokerApplicationMetadata (com.microsoft.identity.common.internal.cache.BrokerApplicationMetadata)3 BrokerOAuth2TokenCache (com.microsoft.identity.common.internal.cache.BrokerOAuth2TokenCache)3 MicrosoftFamilyOAuth2TokenCache (com.microsoft.identity.common.internal.cache.MicrosoftFamilyOAuth2TokenCache)3 IdTokenRecord (com.microsoft.identity.common.internal.dto.IdTokenRecord)3 RefreshTokenRecord (com.microsoft.identity.common.internal.dto.RefreshTokenRecord)3 OAuth2Strategy (com.microsoft.identity.common.internal.providers.oauth2.OAuth2Strategy)3 OAuth2StrategyParameters (com.microsoft.identity.common.internal.providers.oauth2.OAuth2StrategyParameters)3 TokenResult (com.microsoft.identity.common.internal.providers.oauth2.TokenResult)3