use of com.microsoft.identity.common.internal.cache.ICacheRecord in project microsoft-authentication-library-common-for-android by AzureAD.
the class MsalOAuth2TokenCacheTest method saveTokensWithAggregationSingleEntryWithMalformedDataInCache.
@Test
public void saveTokensWithAggregationSingleEntryWithMalformedDataInCache() throws ClientException {
// Prepopulate the cache with unparseable, junk data
mSharedPreferencesFileManager.putString(JUNK_KEY, JUNK_VALUE);
final List<ICacheRecord> result = loadTestBundleIntoCacheWithAggregation(defaultTestBundleV2);
assertEquals(1, result.size());
final ICacheRecord entry = result.get(0);
assertEquals(defaultTestBundleV2.mGeneratedAccount, entry.getAccount());
assertEquals(defaultTestBundleV2.mGeneratedIdToken, entry.getIdToken());
assertEquals(defaultTestBundleV2.mGeneratedAccessToken, entry.getAccessToken());
assertEquals(defaultTestBundleV2.mGeneratedRefreshToken, entry.getRefreshToken());
// Verify that our junk data still exists
assertEquals(JUNK_VALUE, mSharedPreferencesFileManager.getString(JUNK_KEY));
}
use of com.microsoft.identity.common.internal.cache.ICacheRecord in project microsoft-authentication-library-common-for-android by AzureAD.
the class MsalOAuth2TokenCacheTest method saveAccountDirect.
private void saveAccountDirect(@NonNull final AccountCredentialTestBundle testBundle) {
mOauth2TokenCache.save(testBundle.mGeneratedAccount, testBundle.mGeneratedIdToken);
final AccountRecord account = mOauth2TokenCache.getAccount(ENVIRONMENT, CLIENT_ID, HOME_ACCOUNT_ID, REALM);
final ICacheRecord cacheRecord = mOauth2TokenCache.load(CLIENT_ID, TARGET, account, BEARER_AUTHENTICATION_SCHEME);
assertNotNull(cacheRecord);
assertNotNull(cacheRecord.getAccount());
if (testBundle == defaultTestBundleV2) {
assertNotNull(cacheRecord.getIdToken());
assertNull(cacheRecord.getV1IdToken());
assertEquals(testBundle.mGeneratedIdToken, cacheRecord.getIdToken());
} else {
assertNotNull(cacheRecord.getV1IdToken());
assertNull(cacheRecord.getIdToken());
assertEquals(testBundle.mGeneratedIdToken, cacheRecord.getV1IdToken());
}
assertNull(cacheRecord.getAccessToken());
assertNull(cacheRecord.getRefreshToken());
assertEquals(testBundle.mGeneratedAccount, cacheRecord.getAccount());
}
use of com.microsoft.identity.common.internal.cache.ICacheRecord in project microsoft-authentication-library-common-for-android by AzureAD.
the class MsalOAuth2TokenCacheTest method getAccountsWithAggregatedAccountData.
@Test
public void getAccountsWithAggregatedAccountData() throws ClientException {
loadTestBundleIntoCache(defaultTestBundleV2);
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.getIdToken());
assertNull(cacheRecord.getAccessToken());
assertNull(cacheRecord.getRefreshToken());
assertNull(cacheRecord.getV1IdToken());
}
use of com.microsoft.identity.common.internal.cache.ICacheRecord in project azure-activedirectory-library-for-android by AzureAD.
the class TokenCacheAccessorTests method testMsalCacheIsUpdated.
/**
* This test asserts that the MSAL cache is updated by writes to the ADAL cache.
* The ADAL class {@link TokenCacheAccessor} receives an instance of the cache supplied by the host
* app. If the caller has set an instance of {@link DefaultTokenCacheStore}, then ADAL should write a
* matching ID, AT, and Account to the MSAL cache for migration/SSO purposes.
*/
@Test
public void testMsalCacheIsUpdated() throws ServiceException, MalformedURLException {
// Assert our cache is configured for WW
assertEquals(WORLDWIDE_AUTHORITY, mTokenCacheAccessor.getAuthorityUrlWithPreferredCache());
// Create a request to WW
final AuthenticationRequest request = new AuthenticationRequest(WORLDWIDE_AUTHORITY, RESOURCE, CLIENT, REDIRECT, "", PromptBehavior.Auto, "", UUID.randomUUID(), false, null);
final AuthenticationResult result = new AuthenticationResult(MOCK_AT, MOCK_RT, new Date(System.currentTimeMillis() + (3600 * 1000)), false, new UserInfo(USERID_1, GIVEN_NAME, FAMILY_NAME, IDENTITY, USERID_1), TID, MOCK_ID_TOKEN_WITH_CLAIMS, null, CLIENT);
result.setAuthority(WORLDWIDE_AUTHORITY);
result.setClientInfo(new ClientInfo(MOCK_CLIENT_INFO));
result.setResponseReceived(System.currentTimeMillis());
result.setExpiresIn(TimeUnit.HOURS.toSeconds(1));
// Save this to the cache
mTokenCacheAccessor.updateTokenCache(request, result);
assertEquals(WORLDWIDE_AUTHORITY, mTokenCacheAccessor.getAuthorityUrlWithPreferredCache());
// Assert the MSAL replicated cache now contains the account & RT
final IAccountCredentialCache accountCredentialCache = new SharedPreferencesAccountCredentialCache(new CacheKeyValueDelegate(), new SharedPreferencesFileManager(mContext, DEFAULT_ACCOUNT_CREDENTIAL_SHARED_PREFERENCES, new StorageHelper(mContext)));
final MsalOAuth2TokenCache msalCache = new MsalOAuth2TokenCache(mContext, accountCredentialCache, new MicrosoftStsAccountCredentialAdapter());
// Assert the presence of the account
final AccountRecord accountRecord = msalCache.getAccount(LOGIN_WINDOWS_NET, CLIENT, MOCK_UID + "." + MOCK_UTID, MOCK_UTID);
Assert.assertNotNull(accountRecord);
// The RT
final ICacheRecord cacheRecord = msalCache.load(CLIENT, null, accountRecord, new BearerAuthenticationSchemeInternal());
final IdTokenRecord idToken = cacheRecord.getIdToken();
final RefreshTokenRecord refreshToken = cacheRecord.getRefreshToken();
Assert.assertEquals(MOCK_UTID, idToken.getRealm());
Assert.assertEquals(CLIENT, idToken.getClientId());
Assert.assertEquals(accountRecord.getHomeAccountId(), idToken.getHomeAccountId());
Assert.assertEquals(LOGIN_WINDOWS_NET, refreshToken.getEnvironment());
Assert.assertEquals(CLIENT, refreshToken.getClientId());
Assert.assertEquals(accountRecord.getHomeAccountId(), refreshToken.getHomeAccountId());
}
use of com.microsoft.identity.common.internal.cache.ICacheRecord in project microsoft-authentication-library-common-for-android by AzureAD.
the class MsalOAuth2TokenCacheTest method loadTokens.
@Test
public void loadTokens() throws ClientException {
// Save an Account into the cache
final ICacheRecord result = mOauth2TokenCache.save(mockStrategy, mockRequest, mockResponse);
assertEquals(defaultTestBundleV2.mGeneratedAccount, result.getAccount());
assertEquals(defaultTestBundleV2.mGeneratedAccessToken, result.getAccessToken());
assertEquals(defaultTestBundleV2.mGeneratedRefreshToken, result.getRefreshToken());
assertEquals(defaultTestBundleV2.mGeneratedIdToken, result.getIdToken());
final ICacheRecord secondaryLoad = mOauth2TokenCache.load(CLIENT_ID, TARGET, defaultTestBundleV2.mGeneratedAccount, BEARER_AUTHENTICATION_SCHEME);
assertEquals(result, secondaryLoad);
}
Aggregations