use of com.microsoft.identity.common.internal.dto.AccountRecord in project microsoft-authentication-library-common-for-android by AzureAD.
the class CacheKeyValueDelegateTest method accountExtraValueDeserialization.
@Test
public void accountExtraValueDeserialization() throws JSONException {
final AccountRecord account = new AccountRecord();
account.setHomeAccountId(HOME_ACCOUNT_ID);
account.setEnvironment(ENVIRONMENT);
account.setRealm(REALM);
account.setLocalAccountId(LOCAL_ACCOUNT_ID);
account.setAuthorityType(AUTHORITY_TYPE);
account.setAlternativeAccountId(ALTERNATIVE_ACCOUNT_ID);
account.setFirstName(FIRST_NAME);
account.setFamilyName(FAMILY_NAME);
account.setAvatarUrl(AVATAR_URL);
String serializedValue = mDelegate.generateCacheValue(account);
// Turn the serialized value into a JSONObject and start testing field equality.
final JSONObject jsonObject = new JSONObject(serializedValue);
// Add more non-standard data to this object...
final JSONArray numbers = new JSONArray("[1, 2, 3]");
final JSONArray objects = new JSONArray("[{\"hello\" : \"hallo\"}, {\"goodbye\" : \"auf wiedersehen\"}]");
jsonObject.put("foo", "bar");
jsonObject.put("numbers", numbers);
jsonObject.put("objects", objects);
serializedValue = jsonObject.toString();
final AccountRecord deserializedValue = mDelegate.fromCacheValue(serializedValue, AccountRecord.class);
assertNotNull(deserializedValue);
assertNull(deserializedValue.getAdditionalFields().get(AccountRecord.SerializedNames.ENVIRONMENT));
assertEquals(HOME_ACCOUNT_ID, deserializedValue.getHomeAccountId());
assertEquals(ENVIRONMENT, deserializedValue.getEnvironment());
assertEquals(REALM, deserializedValue.getRealm());
assertEquals(LOCAL_ACCOUNT_ID, deserializedValue.getLocalAccountId());
assertEquals(AUTHORITY_TYPE, deserializedValue.getAuthorityType());
assertEquals(ALTERNATIVE_ACCOUNT_ID, deserializedValue.getAlternativeAccountId());
assertEquals(FIRST_NAME, deserializedValue.getFirstName());
assertEquals(FAMILY_NAME, deserializedValue.getFamilyName());
assertEquals(AVATAR_URL, deserializedValue.getAvatarUrl());
assertEquals(3, deserializedValue.getAdditionalFields().size());
assertEquals("bar", deserializedValue.getAdditionalFields().get("foo").getAsString());
assertEquals(numbers.toString(), deserializedValue.getAdditionalFields().get("numbers").toString());
}
use of com.microsoft.identity.common.internal.dto.AccountRecord in project microsoft-authentication-library-common-for-android by AzureAD.
the class CacheKeyValueDelegateTest method accountCreateCacheKeyCompleteNoRealm.
@Test
public void accountCreateCacheKeyCompleteNoRealm() {
final AccountRecord account = new AccountRecord();
account.setHomeAccountId(HOME_ACCOUNT_ID);
account.setEnvironment(ENVIRONMENT);
final String expectedKey = "" + HOME_ACCOUNT_ID + CACHE_VALUE_SEPARATOR + ENVIRONMENT + CACHE_VALUE_SEPARATOR;
assertEquals(expectedKey, mDelegate.generateCacheKey(account));
}
use of com.microsoft.identity.common.internal.dto.AccountRecord in project microsoft-authentication-library-common-for-android by AzureAD.
the class CacheKeyValueDelegateTest method accountCreateCacheValue.
@Test
public void accountCreateCacheValue() throws JSONException {
final AccountRecord account = new AccountRecord();
account.setHomeAccountId(HOME_ACCOUNT_ID);
account.setEnvironment(ENVIRONMENT);
account.setRealm(REALM);
account.setLocalAccountId(LOCAL_ACCOUNT_ID);
account.setAuthorityType(AUTHORITY_TYPE);
account.setAlternativeAccountId(ALTERNATIVE_ACCOUNT_ID);
account.setFirstName(FIRST_NAME);
account.setFamilyName(FAMILY_NAME);
account.setAvatarUrl(AVATAR_URL);
final String serializedValue = mDelegate.generateCacheValue(account);
final JSONObject jsonObject = new JSONObject(serializedValue);
assertEquals(HOME_ACCOUNT_ID, jsonObject.getString(AccountRecord.SerializedNames.HOME_ACCOUNT_ID));
assertEquals(ENVIRONMENT, jsonObject.getString(AccountRecord.SerializedNames.ENVIRONMENT));
assertEquals(REALM, jsonObject.getString(AccountRecord.SerializedNames.REALM));
assertEquals(LOCAL_ACCOUNT_ID, jsonObject.getString("local_account_id"));
assertEquals(AUTHORITY_TYPE, jsonObject.getString("authority_type"));
assertEquals(ALTERNATIVE_ACCOUNT_ID, jsonObject.getString("alternative_account_id"));
assertEquals(FIRST_NAME, jsonObject.getString("first_name"));
assertEquals(FAMILY_NAME, jsonObject.getString("family_name"));
assertEquals(AVATAR_URL, jsonObject.getString("avatar_url"));
}
use of com.microsoft.identity.common.internal.dto.AccountRecord in project microsoft-authentication-library-common-for-android by AzureAD.
the class BrokerOAuth2TokenCacheTest method testCanSaveIntoAppUidCache.
@Test
@SuppressWarnings("unchecked")
public void testCanSaveIntoAppUidCache() throws ClientException {
configureMocksForAppUid();
mBrokerOAuth2TokenCache.save(mockStrategy, mockRequest, mockResponse);
final List<AccountRecord> accounts = mAppUidCredentialCache.getAccounts();
assertEquals(1, accounts.size());
assertEquals(mDefaultAppUidTestBundle.mGeneratedAccount, accounts.get(0));
final List<Credential> credentials = mAppUidCredentialCache.getCredentials();
assertEquals(3, credentials.size());
final List<Credential> rts = new ArrayList<>();
final List<Credential> ats = new ArrayList<>();
final List<Credential> ids = new ArrayList<>();
for (final Credential credential : credentials) {
if (credential.getCredentialType().equalsIgnoreCase(CredentialType.AccessToken.name())) {
ats.add(credential);
} else if (credential.getCredentialType().equalsIgnoreCase(CredentialType.RefreshToken.name())) {
rts.add(credential);
} else if (credential.getCredentialType().equalsIgnoreCase(CredentialType.IdToken.name())) {
ids.add(credential);
} else {
fail();
}
}
assertEquals(mDefaultAppUidTestBundle.mGeneratedAccessToken, ats.get(0));
assertEquals(mDefaultAppUidTestBundle.mGeneratedRefreshToken, rts.get(0));
assertEquals(mDefaultAppUidTestBundle.mGeneratedIdToken, ids.get(0));
}
use of com.microsoft.identity.common.internal.dto.AccountRecord 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