Search in sources :

Example 26 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 saveTokensWithAggregationMultiEntry.

@Test
public void saveTokensWithAggregationMultiEntry() 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(defaultTestBundleV2);
    assertEquals(2, result.size());
    final ICacheRecord entry1 = result.get(0);
    assertNotNull(entry1.getAccount());
    assertNotNull(entry1.getIdToken());
    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 27 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 loadTokensWithAggregatedDataV1.

@Test
public void loadTokensWithAggregatedDataV1() 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 List<ICacheRecord> secondaryLoad = mOauth2TokenCache.loadWithAggregatedAccountData(CLIENT_ID, TARGET, defaultTestBundleV1.mGeneratedAccount, BEARER_AUTHENTICATION_SCHEME);
    assertEquals(1, secondaryLoad.size());
    final ICacheRecord secondaryResult = secondaryLoad.get(0);
    assertEquals(defaultTestBundleV1.mGeneratedAccount, secondaryResult.getAccount());
    assertEquals(defaultTestBundleV1.mGeneratedAccessToken, secondaryResult.getAccessToken());
    assertEquals(defaultTestBundleV1.mGeneratedIdToken, secondaryResult.getV1IdToken());
    assertEquals(defaultTestBundleV1.mGeneratedRefreshToken, secondaryResult.getRefreshToken());
}
Also used : ICacheRecord(com.microsoft.identity.common.internal.cache.ICacheRecord) Test(org.junit.Test)

Example 28 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 removeIdToken.

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

Example 29 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 getAccountsWithAggregatedAccountDataV1.

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

Example 30 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 getAccountsWithIdTokens.

@Test
public void getAccountsWithIdTokens() throws ClientException {
    mOauth2TokenCache.save(mockStrategy, mockRequest, mockResponse);
    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.getIdToken());
    assertNull(retrievedRecord.getV1IdToken());
    assertNull(retrievedRecord.getAccessToken());
    assertNull(retrievedRecord.getRefreshToken());
}
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