use of com.microsoft.identity.common.internal.cache.BrokerApplicationMetadata in project microsoft-authentication-library-common-for-android by AzureAD.
the class SharedPreferencesBrokerApplicationMetadataCacheTest method testInsertMultiple.
@Test
public void testInsertMultiple() {
final int expected = 10;
final List<BrokerApplicationMetadata> metadataList = new ArrayList<>();
for (int ii = 0; ii < expected; ii++) {
metadataList.add(generateRandomMetadata());
}
for (final BrokerApplicationMetadata metadata : metadataList) {
mMetadataCache.insert(metadata);
}
final List<BrokerApplicationMetadata> cacheContents = mMetadataCache.getAll();
for (final BrokerApplicationMetadata metadata : cacheContents) {
assertTrue(metadataList.contains(metadata));
}
}
use of com.microsoft.identity.common.internal.cache.BrokerApplicationMetadata in project microsoft-authentication-library-common-for-android by AzureAD.
the class SharedPreferencesBrokerApplicationMetadataCacheTest method testRemove.
@Test
public void testRemove() {
final BrokerApplicationMetadata randomMetadata = generateRandomMetadata();
mMetadataCache.insert(randomMetadata);
assertEquals(1, mMetadataCache.getAll().size());
assertEquals(randomMetadata, mMetadataCache.getAll().get(0));
assertTrue(mMetadataCache.remove(randomMetadata));
}
use of com.microsoft.identity.common.internal.cache.BrokerApplicationMetadata 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.BrokerApplicationMetadata in project microsoft-authentication-library-common-for-android by AzureAD.
the class SharedPreferencesBrokerApplicationMetadataCacheTest method generateRandomMetadata.
private static BrokerApplicationMetadata generateRandomMetadata() {
final BrokerApplicationMetadata randomMetadata = new BrokerApplicationMetadata();
randomMetadata.setClientId(UUID.randomUUID().toString());
randomMetadata.setEnvironment(UUID.randomUUID().toString());
randomMetadata.setFoci(UUID.randomUUID().toString());
randomMetadata.setUid(new Random().nextInt());
return randomMetadata;
}
Aggregations