use of com.microsoft.identity.common.internal.cache.ICacheRecord in project microsoft-authentication-library-common-for-android by AzureAD.
the class BrokerOAuth2TokenCacheTest method testWPJSaveNonFoci.
@Test
public void testWPJSaveNonFoci() throws ClientException {
final ICacheRecord saveResult = mBrokerOAuth2TokenCache.save(mDefaultAppUidTestBundle.mGeneratedAccount, mDefaultAppUidTestBundle.mGeneratedIdToken, mDefaultAppUidTestBundle.mGeneratedAccessToken, mDefaultAppUidTestBundle.mGeneratedRefreshToken, null);
assertNotNull(saveResult);
assertNotNull(saveResult.getAccount());
assertNotNull(saveResult.getIdToken());
assertNotNull(saveResult.getAccessToken());
assertNotNull(saveResult.getRefreshToken());
assertEquals(mDefaultAppUidTestBundle.mGeneratedAccount, saveResult.getAccount());
assertEquals(mDefaultAppUidTestBundle.mGeneratedIdToken, saveResult.getIdToken());
assertEquals(mDefaultAppUidTestBundle.mGeneratedAccessToken, saveResult.getAccessToken());
assertEquals(mDefaultAppUidTestBundle.mGeneratedRefreshToken, saveResult.getRefreshToken());
final ICacheRecord retrievedResult = mBrokerOAuth2TokenCache.load(mDefaultAppUidTestBundle.mGeneratedIdToken.getClientId(), mDefaultAppUidTestBundle.mGeneratedAccessToken.getTarget(), mDefaultAppUidTestBundle.mGeneratedAccount, BEARER_AUTHENTICATION_SCHEME);
assertNotNull(retrievedResult);
assertNotNull(retrievedResult.getAccount());
assertNotNull(retrievedResult.getIdToken());
assertNotNull(retrievedResult.getAccessToken());
assertNotNull(retrievedResult.getRefreshToken());
assertEquals(mDefaultAppUidTestBundle.mGeneratedAccount, retrievedResult.getAccount());
assertEquals(mDefaultAppUidTestBundle.mGeneratedIdToken, retrievedResult.getIdToken());
assertEquals(mDefaultAppUidTestBundle.mGeneratedAccessToken, retrievedResult.getAccessToken());
assertEquals(mDefaultAppUidTestBundle.mGeneratedRefreshToken, saveResult.getRefreshToken());
}
use of com.microsoft.identity.common.internal.cache.ICacheRecord in project microsoft-authentication-library-common-for-android by AzureAD.
the class BrokerOAuth2TokenCacheTest method testWPJSaveNonFoci_deprecated.
@Test
public void testWPJSaveNonFoci_deprecated() throws ClientException {
final ICacheRecord saveResult = mBrokerOAuth2TokenCache.save(mDefaultAppUidTestBundle.mGeneratedAccount, mDefaultAppUidTestBundle.mGeneratedIdToken, mDefaultAppUidTestBundle.mGeneratedAccessToken, null);
assertNotNull(saveResult);
assertNotNull(saveResult.getAccount());
assertNotNull(saveResult.getIdToken());
assertNotNull(saveResult.getAccessToken());
assertNull(saveResult.getRefreshToken());
assertEquals(mDefaultAppUidTestBundle.mGeneratedAccount, saveResult.getAccount());
assertEquals(mDefaultAppUidTestBundle.mGeneratedIdToken, saveResult.getIdToken());
assertEquals(mDefaultAppUidTestBundle.mGeneratedAccessToken, saveResult.getAccessToken());
final ICacheRecord retrievedResult = mBrokerOAuth2TokenCache.load(mDefaultAppUidTestBundle.mGeneratedIdToken.getClientId(), mDefaultAppUidTestBundle.mGeneratedAccessToken.getTarget(), mDefaultAppUidTestBundle.mGeneratedAccount, BEARER_AUTHENTICATION_SCHEME);
assertNotNull(retrievedResult);
assertNotNull(retrievedResult.getAccount());
assertNotNull(retrievedResult.getIdToken());
assertNotNull(retrievedResult.getAccessToken());
assertNull(retrievedResult.getRefreshToken());
assertEquals(mDefaultAppUidTestBundle.mGeneratedAccount, retrievedResult.getAccount());
assertEquals(mDefaultAppUidTestBundle.mGeneratedIdToken, retrievedResult.getIdToken());
assertEquals(mDefaultAppUidTestBundle.mGeneratedAccessToken, retrievedResult.getAccessToken());
}
use of com.microsoft.identity.common.internal.cache.ICacheRecord in project microsoft-authentication-library-common-for-android by AzureAD.
the class BrokerOAuth2TokenCacheTest method testWPJSaveFoci_deprecated.
@Test
public void testWPJSaveFoci_deprecated() throws ClientException {
final ICacheRecord saveResult = mBrokerOAuth2TokenCache.save(mDefaultFociTestBundle.mGeneratedAccount, mDefaultFociTestBundle.mGeneratedIdToken, mDefaultFociTestBundle.mGeneratedAccessToken, "1");
assertNotNull(saveResult);
assertNotNull(saveResult.getAccount());
assertNotNull(saveResult.getIdToken());
assertNotNull(saveResult.getAccessToken());
assertNull(saveResult.getRefreshToken());
assertEquals(mDefaultFociTestBundle.mGeneratedAccount, saveResult.getAccount());
assertEquals(mDefaultFociTestBundle.mGeneratedIdToken, saveResult.getIdToken());
assertEquals(mDefaultFociTestBundle.mGeneratedAccessToken, saveResult.getAccessToken());
final ICacheRecord retrievedResult = mBrokerOAuth2TokenCache.load(mDefaultFociTestBundle.mGeneratedIdToken.getClientId(), mDefaultFociTestBundle.mGeneratedAccessToken.getTarget(), mDefaultFociTestBundle.mGeneratedAccount, BEARER_AUTHENTICATION_SCHEME);
assertNotNull(retrievedResult);
assertNotNull(retrievedResult.getAccount());
assertNotNull(retrievedResult.getIdToken());
assertNotNull(retrievedResult.getAccessToken());
assertNull(retrievedResult.getRefreshToken());
assertEquals(mDefaultFociTestBundle.mGeneratedAccount, retrievedResult.getAccount());
assertEquals(mDefaultFociTestBundle.mGeneratedIdToken, retrievedResult.getIdToken());
assertEquals(mDefaultFociTestBundle.mGeneratedAccessToken, retrievedResult.getAccessToken());
}
use of com.microsoft.identity.common.internal.cache.ICacheRecord in project microsoft-authentication-library-common-for-android by AzureAD.
the class BrokerOAuth2TokenCacheTest method testRemoveCredentialAppUidCache.
@Test
public void testRemoveCredentialAppUidCache() throws ClientException {
configureMocksForAppUid();
mBrokerOAuth2TokenCache.save(mockStrategy, mockRequest, mockResponse);
final ICacheRecord cacheRecord = mBrokerOAuth2TokenCache.load(CLIENT_ID, TARGET, mDefaultAppUidTestBundle.mGeneratedAccount, BEARER_AUTHENTICATION_SCHEME);
assertTrue(mBrokerOAuth2TokenCache.removeCredential(mDefaultAppUidTestBundle.mGeneratedAccessToken));
}
use of com.microsoft.identity.common.internal.cache.ICacheRecord in project microsoft-authentication-library-common-for-android by AzureAD.
the class BrokerOAuth2TokenCacheTest method testGetAccountsAdal.
@Test
public void testGetAccountsAdal() 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());
}
Aggregations