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