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());
}
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());
}
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());
}
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());
}
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());
}
Aggregations