use of com.microsoft.identity.common.internal.cache.ICacheRecord in project microsoft-authentication-library-common-for-android by AzureAD.
the class MsalOAuth2TokenCacheTest method removeV1IdToken.
@Test
public void removeV1IdToken() throws ClientException {
final ICacheRecord result = loadTestBundleIntoCache(defaultTestBundleV1);
mOauth2TokenCache.removeCredential(result.getV1IdToken());
final ICacheRecord secondaryLoad = mOauth2TokenCache.load(CLIENT_ID, TARGET, defaultTestBundleV2.mGeneratedAccount, BEARER_AUTHENTICATION_SCHEME);
assertEquals(defaultTestBundleV1.mGeneratedAccount, secondaryLoad.getAccount());
assertEquals(defaultTestBundleV1.mGeneratedAccessToken, secondaryLoad.getAccessToken());
assertEquals(defaultTestBundleV1.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 saveTokensWithAggregationV1SingleEntry.
@Test
public void saveTokensWithAggregationV1SingleEntry() throws ClientException {
final List<ICacheRecord> result = loadTestBundleIntoCacheWithAggregation(defaultTestBundleV1);
assertEquals(1, result.size());
final ICacheRecord entry = result.get(0);
assertNotNull(entry.getAccount());
assertNotNull(entry.getV1IdToken());
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 BrokerOAuth2TokenCacheTest method testGetAccountsMsal.
@Test
public void testGetAccountsMsal() throws ClientException {
// Load up the 'other caches' which a bunch of test credentials, see if we can get them out...
int ii = 0;
for (final OAuth2TokenCache cache : mOtherAppTokenCaches) {
configureMocks(mOtherCacheTestBundles.get(ii));
final ICacheRecord cacheRecord = cache.save(mockStrategy, mockRequest, mockResponse);
final BrokerApplicationMetadata applicationMetadata = new BrokerApplicationMetadata();
applicationMetadata.setClientId(cacheRecord.getIdToken().getClientId());
applicationMetadata.setEnvironment(cacheRecord.getIdToken().getEnvironment());
applicationMetadata.setFoci(cacheRecord.getRefreshToken().getFamilyId());
applicationMetadata.setUid(testAppUids[ii++]);
mApplicationMetadataCache.insert(applicationMetadata);
}
final List<String> clientIds = new ArrayList<>();
for (final MsalOAuth2TokenCacheTest.AccountCredentialTestBundle testBundle : mOtherCacheTestBundles) {
clientIds.add(testBundle.mGeneratedRefreshToken.getClientId());
}
final List<AccountRecord> xAppAccounts = new ArrayList<>();
for (final int testUid : testAppUids) {
// Create the cache to query...
mBrokerOAuth2TokenCache = new BrokerOAuth2TokenCache(InstrumentationRegistry.getContext(), testUid, mApplicationMetadataCache, new BrokerOAuth2TokenCache.ProcessUidCacheFactory() {
@Override
public MsalOAuth2TokenCache getTokenCache(Context context, int bindingProcessUid) {
return initAppUidCache(context, bindingProcessUid);
}
}, mFociCache);
for (final String clientId : clientIds) {
final List<AccountRecord> accountsInCache = mBrokerOAuth2TokenCache.getAccounts(ENVIRONMENT, clientId);
xAppAccounts.addAll(accountsInCache);
}
}
assertEquals(clientIds.size(), xAppAccounts.size());
final List<AccountRecord> xAppAccountsNoParam = new ArrayList<>(mBrokerOAuth2TokenCache.getAccounts());
assertEquals(xAppAccounts.size(), xAppAccountsNoParam.size());
final Context context = InstrumentationRegistry.getContext();
final BrokerOAuth2TokenCache brokerOAuth2TokenCache = new BrokerOAuth2TokenCache(context, TEST_APP_UID, new SharedPreferencesBrokerApplicationMetadataCache(context));
assertEquals(0, brokerOAuth2TokenCache.getAccounts(ENVIRONMENT, CLIENT_ID).size());
final BrokerOAuth2TokenCache brokerOAuth2TokenCache2 = new BrokerOAuth2TokenCache(context, TEST_APP_UID, new SharedPreferencesBrokerApplicationMetadataCache(context));
assertEquals(xAppAccounts.size(), brokerOAuth2TokenCache2.getAccounts().size());
}
use of com.microsoft.identity.common.internal.cache.ICacheRecord in project microsoft-authentication-library-common-for-android by AzureAD.
the class MicrosoftFamilyOAuth2TokenCacheTest method testDualStackIdTokenRetrieval.
@Test
public void testDualStackIdTokenRetrieval() throws ClientException {
final String randomHomeAccountId = UUID.randomUUID().toString();
final String randomRealm = UUID.randomUUID().toString();
final AccountCredentialTestBundle frtTestBundleV2 = new AccountCredentialTestBundle(MicrosoftAccount.AUTHORITY_TYPE_V1_V2, UUID.randomUUID().toString(), "test.user@tenant.onmicrosoft.com", randomHomeAccountId, ENVIRONMENT, randomRealm, TARGET, CACHED_AT, EXPIRES_ON, SECRET, CLIENT_ID, SECRET, MicrosoftStsAccountCredentialAdapterTest.MOCK_ID_TOKEN_WITH_CLAIMS, "1", SESSION_KEY, CredentialType.IdToken);
when(mockCredentialAdapter.createAccount(mockStrategy, mockRequest, mockResponse)).thenReturn(frtTestBundleV2.mGeneratedAccount);
when(mockCredentialAdapter.createAccessToken(mockStrategy, mockRequest, mockResponse)).thenReturn(frtTestBundleV2.mGeneratedAccessToken);
when(mockCredentialAdapter.createRefreshToken(mockStrategy, mockRequest, mockResponse)).thenReturn(frtTestBundleV2.mGeneratedRefreshToken);
when(mockCredentialAdapter.createIdToken(mockStrategy, mockRequest, mockResponse)).thenReturn(frtTestBundleV2.mGeneratedIdToken);
// Save the family token data
mOauth2TokenCache.save(mockStrategy, mockRequest, mockResponse);
final AccountCredentialTestBundle frtTestBundleV1 = new AccountCredentialTestBundle(MicrosoftAccount.AUTHORITY_TYPE_V1_V2, UUID.randomUUID().toString(), "test.user@tenant.onmicrosoft.com", randomHomeAccountId, ENVIRONMENT, randomRealm, TARGET, CACHED_AT, EXPIRES_ON, SECRET, CLIENT_ID, SECRET, MicrosoftStsAccountCredentialAdapterTest.MOCK_ID_TOKEN_WITH_CLAIMS, "1", SESSION_KEY, CredentialType.V1IdToken);
when(mockCredentialAdapter.createAccount(mockStrategy, mockRequest, mockResponse)).thenReturn(frtTestBundleV1.mGeneratedAccount);
when(mockCredentialAdapter.createAccessToken(mockStrategy, mockRequest, mockResponse)).thenReturn(frtTestBundleV1.mGeneratedAccessToken);
when(mockCredentialAdapter.createRefreshToken(mockStrategy, mockRequest, mockResponse)).thenReturn(frtTestBundleV1.mGeneratedRefreshToken);
when(mockCredentialAdapter.createIdToken(mockStrategy, mockRequest, mockResponse)).thenReturn(frtTestBundleV1.mGeneratedIdToken);
// Save the family token data
mOauth2TokenCache.save(mockStrategy, mockRequest, mockResponse);
final ICacheRecord familyCacheRecord = mOauth2TokenCache.loadByFamilyId(CLIENT_ID, TARGET, frtTestBundleV1.mGeneratedAccount, BEARER_SCHEME);
assertNotNull(familyCacheRecord);
assertNotNull(familyCacheRecord.getAccount());
assertNotNull(familyCacheRecord.getRefreshToken());
assertNotNull(familyCacheRecord.getIdToken());
assertNotNull(familyCacheRecord.getV1IdToken());
assertNotNull(familyCacheRecord.getAccessToken());
}
use of com.microsoft.identity.common.internal.cache.ICacheRecord in project microsoft-authentication-library-common-for-android by AzureAD.
the class BrokerOAuth2TokenCacheTest method testCacheMiss.
@Test
public void testCacheMiss() {
final ICacheRecord cacheRecord = mBrokerOAuth2TokenCache.load(CLIENT_ID, TARGET, mDefaultAppUidTestBundle.mGeneratedAccount, BEARER_AUTHENTICATION_SCHEME);
assertNotNull(cacheRecord);
assertNotNull(cacheRecord.getAccount());
assertNull(cacheRecord.getAccessToken());
assertNull(cacheRecord.getRefreshToken());
assertNull(cacheRecord.getIdToken());
}
Aggregations