Search in sources :

Example 31 with ICacheRecord

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

the class MsalOAuth2TokenCacheTest method loadTokensV1Compat.

@Test
public void loadTokensV1Compat() throws ClientException {
    final ICacheRecord result = loadTestBundleIntoCache(defaultTestBundleV1);
    assertEquals(defaultTestBundleV1.mGeneratedAccount, result.getAccount());
    assertEquals(defaultTestBundleV1.mGeneratedAccessToken, result.getAccessToken());
    assertEquals(defaultTestBundleV1.mGeneratedRefreshToken, result.getRefreshToken());
    assertEquals(defaultTestBundleV1.mGeneratedIdToken, result.getV1IdToken());
    final ICacheRecord secondaryLoad = mOauth2TokenCache.load(CLIENT_ID, TARGET, defaultTestBundleV1.mGeneratedAccount, BEARER_AUTHENTICATION_SCHEME);
    assertEquals(result, secondaryLoad);
}
Also used : ICacheRecord(com.microsoft.identity.common.internal.cache.ICacheRecord) Test(org.junit.Test)

Example 32 with ICacheRecord

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

the class MsalOAuth2TokenCacheTest method removeAccessToken.

@Test
public void removeAccessToken() throws ClientException {
    // Save an Account into the cache
    final ICacheRecord result = mOauth2TokenCache.save(mockStrategy, mockRequest, mockResponse);
    mOauth2TokenCache.removeCredential(result.getAccessToken());
    final ICacheRecord secondaryLoad = mOauth2TokenCache.load(CLIENT_ID, TARGET, defaultTestBundleV2.mGeneratedAccount, BEARER_AUTHENTICATION_SCHEME);
    assertEquals(defaultTestBundleV2.mGeneratedAccount, secondaryLoad.getAccount());
    assertNull(secondaryLoad.getAccessToken());
    assertEquals(defaultTestBundleV2.mGeneratedRefreshToken, secondaryLoad.getRefreshToken());
    assertEquals(defaultTestBundleV2.mGeneratedIdToken, secondaryLoad.getIdToken());
}
Also used : ICacheRecord(com.microsoft.identity.common.internal.cache.ICacheRecord) Test(org.junit.Test)

Example 33 with ICacheRecord

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

the class MsalOAuth2TokenCacheTest method getAccountByLocalAccountIdWithAggregatedDataV1.

@Test
public void getAccountByLocalAccountIdWithAggregatedDataV1() throws ClientException {
    // Save an Account into the cache
    loadTestBundleIntoCache(defaultTestBundleV1);
    final ICacheRecord resultRecord = mOauth2TokenCache.getAccountWithAggregatedAccountDataByLocalAccountId(ENVIRONMENT, CLIENT_ID, LOCAL_ACCOUNT_ID);
    assertNotNull(resultRecord);
    assertNotNull(resultRecord.getAccount());
    assertNotNull(resultRecord.getV1IdToken());
    assertNull(resultRecord.getIdToken());
    assertNull(resultRecord.getAccessToken());
    assertNull(resultRecord.getRefreshToken());
}
Also used : ICacheRecord(com.microsoft.identity.common.internal.cache.ICacheRecord) Test(org.junit.Test)

Example 34 with ICacheRecord

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

the class MsalOAuth2TokenCacheTest method getAccountByLocalAccountIdWithAggregatedData.

@Test
public void getAccountByLocalAccountIdWithAggregatedData() throws ClientException {
    // Save an Account into the cache
    mOauth2TokenCache.save(mockStrategy, mockRequest, mockResponse);
    final ICacheRecord resultRecord = mOauth2TokenCache.getAccountWithAggregatedAccountDataByLocalAccountId(ENVIRONMENT, CLIENT_ID, LOCAL_ACCOUNT_ID);
    assertNotNull(resultRecord);
    assertNotNull(resultRecord.getAccount());
    assertNotNull(resultRecord.getIdToken());
    assertNull(resultRecord.getV1IdToken());
    assertNull(resultRecord.getAccessToken());
    assertNull(resultRecord.getRefreshToken());
}
Also used : ICacheRecord(com.microsoft.identity.common.internal.cache.ICacheRecord) Test(org.junit.Test)

Example 35 with ICacheRecord

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

the class MsalOAuth2TokenCacheTest method testFrtFallback.

@Test
public void testFrtFallback() throws ClientException {
    // This test verifies changes in common/#893
    // We will fallback on an FRT in the local cache for the current user if one is avail
    final List<ICacheRecord> result = loadTestBundleIntoCacheWithAggregation(defaultTestBundleV2);
    assertEquals(1, result.size());
    final ICacheRecord entry = result.get(0);
    assertNotNull(entry.getAccount());
    assertNotNull(entry.getIdToken());
    assertNotNull(entry.getAccessToken());
    assertNotNull(entry.getRefreshToken());
    // delete the existing RT and insert our FRT
    accountCredentialCache.removeCredential(entry.getRefreshToken());
    // Modify the existing RT to change the client_id and set a FoCI affiliation
    final String fociRtClientId = UUID.randomUUID().toString();
    final RefreshTokenRecord modifiedRT = entry.getRefreshToken();
    modifiedRT.setFamilyId("1");
    modifiedRT.setClientId(fociRtClientId);
    accountCredentialCache.saveCredential(modifiedRT);
    final ICacheRecord secondaryLoad = mOauth2TokenCache.load(entry.getAccessToken().getClientId(), TARGET, entry.getAccount(), BEARER_AUTHENTICATION_SCHEME);
    assertNotNull(secondaryLoad.getRefreshToken());
    assertEquals(fociRtClientId, secondaryLoad.getRefreshToken().getClientId());
}
Also used : ICacheRecord(com.microsoft.identity.common.internal.cache.ICacheRecord) RefreshTokenRecord(com.microsoft.identity.common.internal.dto.RefreshTokenRecord) PrimaryRefreshTokenRecord(com.microsoft.identity.common.internal.dto.PrimaryRefreshTokenRecord) 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