Search in sources :

Example 16 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 loadTokensWithAggregatedData.

@Test
public void loadTokensWithAggregatedData() throws ClientException {
    final ICacheRecord result = loadTestBundleIntoCache(defaultTestBundleV2);
    assertEquals(defaultTestBundleV2.mGeneratedAccount, result.getAccount());
    assertEquals(defaultTestBundleV2.mGeneratedAccessToken, result.getAccessToken());
    assertEquals(defaultTestBundleV2.mGeneratedRefreshToken, result.getRefreshToken());
    assertEquals(defaultTestBundleV2.mGeneratedIdToken, result.getIdToken());
    final List<ICacheRecord> secondaryLoad = mOauth2TokenCache.loadWithAggregatedAccountData(CLIENT_ID, TARGET, defaultTestBundleV2.mGeneratedAccount, BEARER_AUTHENTICATION_SCHEME);
    assertEquals(1, secondaryLoad.size());
    final ICacheRecord secondaryResult = secondaryLoad.get(0);
    assertEquals(defaultTestBundleV2.mGeneratedAccount, secondaryResult.getAccount());
    assertEquals(defaultTestBundleV2.mGeneratedAccessToken, secondaryResult.getAccessToken());
    assertEquals(defaultTestBundleV2.mGeneratedIdToken, secondaryResult.getIdToken());
    assertEquals(defaultTestBundleV2.mGeneratedRefreshToken, secondaryResult.getRefreshToken());
}
Also used : ICacheRecord(com.microsoft.identity.common.internal.cache.ICacheRecord) Test(org.junit.Test)

Example 17 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 saveTokensWithAggregationSingleEntry.

@Test
public void saveTokensWithAggregationSingleEntry() throws ClientException {
    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());
}
Also used : ICacheRecord(com.microsoft.identity.common.internal.cache.ICacheRecord) Test(org.junit.Test)

Example 18 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 getAccountsWithIdTokensV1.

@Test
public void getAccountsWithIdTokensV1() throws ClientException {
    final ICacheRecord result = loadTestBundleIntoCache(defaultTestBundleV1);
    final List<ICacheRecord> records = mOauth2TokenCache.getAccountsWithAggregatedAccountData(ENVIRONMENT, CLIENT_ID);
    assertEquals(1, records.size());
    final ICacheRecord retrievedRecord = records.get(0);
    assertNotNull(retrievedRecord);
    assertNotNull(retrievedRecord.getAccount());
    assertNotNull(retrievedRecord.getV1IdToken());
    assertNull(retrievedRecord.getIdToken());
    assertNull(retrievedRecord.getAccessToken());
    assertNull(retrievedRecord.getRefreshToken());
}
Also used : ICacheRecord(com.microsoft.identity.common.internal.cache.ICacheRecord) Test(org.junit.Test)

Example 19 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 saveTokensWithAggregationV1MultiEntry.

@Test
public void saveTokensWithAggregationV1MultiEntry() throws ClientException {
    // Load additional creds into the cache to simulate a guest account...
    // at, id, account
    final AccessTokenRecord at = new AccessTokenRecord();
    at.setRealm(REALM2);
    at.setCachedAt(CACHED_AT);
    at.setExpiresOn(EXPIRES_ON);
    at.setSecret(SECRET);
    at.setHomeAccountId(HOME_ACCOUNT_ID);
    at.setEnvironment(ENVIRONMENT);
    at.setCredentialType(AccessToken.name());
    at.setClientId(CLIENT_ID);
    at.setTarget(TARGET);
    final IdTokenRecord id = new IdTokenRecord();
    id.setHomeAccountId(HOME_ACCOUNT_ID);
    id.setEnvironment(ENVIRONMENT);
    id.setRealm(REALM2);
    id.setCredentialType(IdToken.name());
    id.setClientId(CLIENT_ID);
    id.setSecret(MOCK_ID_TOKEN_WITH_CLAIMS);
    id.setAuthority("https://sts.windows.net/0287f963-2d72-4363-9e3a-5705c5b0f031/");
    final AccountRecord acct = new AccountRecord();
    acct.setAuthorityType(AUTHORITY_TYPE);
    acct.setLocalAccountId(UUID.randomUUID().toString());
    acct.setUsername(USERNAME);
    acct.setHomeAccountId(HOME_ACCOUNT_ID);
    acct.setEnvironment(ENVIRONMENT);
    acct.setRealm(REALM2);
    accountCredentialCache.saveAccount(acct);
    accountCredentialCache.saveCredential(at);
    accountCredentialCache.saveCredential(id);
    final List<ICacheRecord> result = loadTestBundleIntoCacheWithAggregation(defaultTestBundleV1);
    assertEquals(2, result.size());
    final ICacheRecord entry1 = result.get(0);
    assertNotNull(entry1.getAccount());
    assertNotNull(entry1.getV1IdToken());
    assertNotNull(entry1.getAccessToken());
    assertNotNull(entry1.getRefreshToken());
    final ICacheRecord entry2 = result.get(1);
    assertNotNull(entry2.getAccount());
    assertNotNull(entry2.getIdToken());
    assertNull(entry2.getAccessToken());
    assertNull(entry2.getRefreshToken());
}
Also used : IdTokenRecord(com.microsoft.identity.common.internal.dto.IdTokenRecord) ICacheRecord(com.microsoft.identity.common.internal.cache.ICacheRecord) AccountRecord(com.microsoft.identity.common.internal.dto.AccountRecord) AccessTokenRecord(com.microsoft.identity.common.internal.dto.AccessTokenRecord) Test(org.junit.Test)

Example 20 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 removeRefreshToken.

@Test
public void removeRefreshToken() throws ClientException {
    // Save an Account into the cache
    final ICacheRecord result = mOauth2TokenCache.save(mockStrategy, mockRequest, mockResponse);
    mOauth2TokenCache.removeCredential(result.getRefreshToken());
    final ICacheRecord secondaryLoad = mOauth2TokenCache.load(CLIENT_ID, TARGET, defaultTestBundleV2.mGeneratedAccount, BEARER_AUTHENTICATION_SCHEME);
    assertEquals(defaultTestBundleV2.mGeneratedAccount, secondaryLoad.getAccount());
    assertEquals(defaultTestBundleV2.mGeneratedAccessToken, secondaryLoad.getAccessToken());
    assertNull(secondaryLoad.getRefreshToken());
    assertEquals(defaultTestBundleV2.mGeneratedIdToken, secondaryLoad.getIdToken());
}
Also used : ICacheRecord(com.microsoft.identity.common.internal.cache.ICacheRecord) 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