use of com.microsoft.identity.common.internal.dto.AccountRecord in project microsoft-authentication-library-common-for-android by AzureAD.
the class SharedPreferencesAccountCredentialCacheTest method saveAccountNoHomeAccountIdNoRealm.
@Test
public void saveAccountNoHomeAccountIdNoRealm() {
final AccountRecord account = new AccountRecord();
account.setEnvironment(ENVIRONMENT);
account.setLocalAccountId(LOCAL_ACCOUNT_ID);
account.setUsername(USERNAME);
account.setAuthorityType(AUTHORITY_TYPE);
// Save the Account
mSharedPreferencesAccountCredentialCache.saveAccount(account);
// Synthesize a cache key for it
final String accountCacheKey = mDelegate.generateCacheKey(account);
// Resurrect the Account
final AccountRecord restoredAccount = mSharedPreferencesAccountCredentialCache.getAccount(accountCacheKey);
assertTrue(account.equals(restoredAccount));
}
use of com.microsoft.identity.common.internal.dto.AccountRecord in project microsoft-authentication-library-common-for-android by AzureAD.
the class SharedPreferencesAccountCredentialCacheTest method getCredentials.
@Test
public void getCredentials() {
// Save an Account into the cache
final AccountRecord account = new AccountRecord();
account.setHomeAccountId(HOME_ACCOUNT_ID);
account.setEnvironment(ENVIRONMENT);
account.setRealm(REALM);
account.setLocalAccountId(LOCAL_ACCOUNT_ID);
account.setUsername(USERNAME);
account.setAuthorityType(AUTHORITY_TYPE);
mSharedPreferencesAccountCredentialCache.saveAccount(account);
// Save an AccessToken into the cache
final AccessTokenRecord accessToken = new AccessTokenRecord();
accessToken.setCredentialType(CredentialType.AccessToken.name());
accessToken.setHomeAccountId(HOME_ACCOUNT_ID);
accessToken.setRealm("Foo");
accessToken.setEnvironment(ENVIRONMENT);
accessToken.setClientId(CLIENT_ID);
accessToken.setTarget(TARGET);
accessToken.setCachedAt(CACHED_AT);
accessToken.setExpiresOn(EXPIRES_ON);
accessToken.setSecret(SECRET);
mSharedPreferencesAccountCredentialCache.saveCredential(accessToken);
// Save a RefreshToken into the cache
final RefreshTokenRecord refreshToken = new RefreshTokenRecord();
refreshToken.setCredentialType(CredentialType.RefreshToken.name());
refreshToken.setEnvironment(ENVIRONMENT);
refreshToken.setHomeAccountId(HOME_ACCOUNT_ID);
refreshToken.setClientId(CLIENT_ID);
refreshToken.setSecret(SECRET);
refreshToken.setTarget(TARGET);
mSharedPreferencesAccountCredentialCache.saveCredential(refreshToken);
// Verify getCredentials() returns two matching elements
final List<Credential> credentials = mSharedPreferencesAccountCredentialCache.getCredentials();
assertTrue(credentials.size() == 2);
}
use of com.microsoft.identity.common.internal.dto.AccountRecord in project microsoft-authentication-library-common-for-android by AzureAD.
the class SharedPreferencesAccountCredentialCacheTest method testAccountMerge.
@Test
public void testAccountMerge() {
final AccountRecord accountFirst = new AccountRecord();
accountFirst.setHomeAccountId(HOME_ACCOUNT_ID);
accountFirst.setEnvironment(ENVIRONMENT);
accountFirst.setRealm(REALM);
accountFirst.setLocalAccountId(LOCAL_ACCOUNT_ID);
accountFirst.setUsername(USERNAME);
accountFirst.setAuthorityType(AUTHORITY_TYPE);
accountFirst.setMiddleName(MIDDLE_NAME);
accountFirst.setName(NAME);
// Create and set some additional field data...
final String additionalKey = "extra-prop-1";
final String additionalValue = "extra-value-1";
final JsonElement additionalValueElement = new JsonPrimitive(additionalValue);
final Map<String, JsonElement> additionalFields = new HashMap<>();
additionalFields.put(additionalKey, additionalValueElement);
accountFirst.setAdditionalFields(additionalFields);
// Save the Credential
mSharedPreferencesAccountCredentialCache.saveAccount(accountFirst);
// Save the second Account, with fields to merge...
final AccountRecord accountSecond = new AccountRecord();
accountSecond.setHomeAccountId(HOME_ACCOUNT_ID);
accountSecond.setEnvironment(ENVIRONMENT);
accountSecond.setRealm(REALM);
accountSecond.setLocalAccountId(LOCAL_ACCOUNT_ID);
accountSecond.setUsername(USERNAME);
accountSecond.setAuthorityType(AUTHORITY_TYPE);
accountSecond.setMiddleName(MIDDLE_NAME);
accountSecond.setName(NAME);
// Create and set some additional field data...
final String additionalKey2 = "extra-prop-2";
final String additionalValue2 = "extra-value-2";
final JsonElement additionalValueElement2 = new JsonPrimitive(additionalValue2);
final Map<String, JsonElement> additionalFields2 = new HashMap<>();
additionalFields2.put(additionalKey2, additionalValueElement2);
accountSecond.setAdditionalFields(additionalFields2);
// Save the Credential
mSharedPreferencesAccountCredentialCache.saveAccount(accountSecond);
// Synthesize a cache key for it - either is fine.
final String credentialCacheKey = mDelegate.generateCacheKey(accountFirst);
// Resurrect the Credential
final AccountRecord restoredAccount = mSharedPreferencesAccountCredentialCache.getAccount(credentialCacheKey);
assertTrue(accountFirst.equals(restoredAccount));
// Assert the presence of both additionalFields
assertEquals(additionalValue, restoredAccount.getAdditionalFields().get(additionalKey).getAsString());
assertEquals(additionalValue2, restoredAccount.getAdditionalFields().get(additionalKey2).getAsString());
}
use of com.microsoft.identity.common.internal.dto.AccountRecord in project microsoft-authentication-library-common-for-android by AzureAD.
the class SharedPreferencesAccountCredentialCacheTest method clearAll.
@Test
public void clearAll() {
// Save an Account into the cache
final AccountRecord account = new AccountRecord();
account.setHomeAccountId(HOME_ACCOUNT_ID);
account.setEnvironment(ENVIRONMENT);
account.setRealm(REALM);
account.setLocalAccountId(LOCAL_ACCOUNT_ID);
account.setUsername(USERNAME);
account.setAuthorityType(AUTHORITY_TYPE);
mSharedPreferencesAccountCredentialCache.saveAccount(account);
// Save an AccessToken into the cache
final AccessTokenRecord accessToken = new AccessTokenRecord();
accessToken.setCredentialType(CredentialType.AccessToken.name());
accessToken.setHomeAccountId(HOME_ACCOUNT_ID);
accessToken.setRealm("Foo");
accessToken.setEnvironment(ENVIRONMENT);
accessToken.setClientId(CLIENT_ID);
accessToken.setTarget(TARGET);
accessToken.setCachedAt(CACHED_AT);
accessToken.setExpiresOn(EXPIRES_ON);
accessToken.setSecret(SECRET);
mSharedPreferencesAccountCredentialCache.saveCredential(accessToken);
// Save a RefreshToken into the cache
final RefreshTokenRecord refreshToken = new RefreshTokenRecord();
refreshToken.setCredentialType(CredentialType.RefreshToken.name());
refreshToken.setEnvironment(ENVIRONMENT);
refreshToken.setHomeAccountId(HOME_ACCOUNT_ID);
refreshToken.setClientId(CLIENT_ID);
refreshToken.setSecret(SECRET);
refreshToken.setTarget(TARGET);
mSharedPreferencesAccountCredentialCache.saveCredential(refreshToken);
// Call clearAll()
mSharedPreferencesAccountCredentialCache.clearAll();
// Verify getAccounts() returns zero items
assertTrue(mSharedPreferencesAccountCredentialCache.getAccounts().isEmpty());
// Verify getCredentials() returns zero items
assertTrue(mSharedPreferencesAccountCredentialCache.getCredentials().isEmpty());
}
use of com.microsoft.identity.common.internal.dto.AccountRecord in project microsoft-authentication-library-common-for-android by AzureAD.
the class SharedPreferencesAccountCredentialCacheTest method saveAccountNoRealm.
@Test
public void saveAccountNoRealm() {
final AccountRecord account = new AccountRecord();
account.setLocalAccountId(LOCAL_ACCOUNT_ID);
account.setUsername(USERNAME);
account.setAuthorityType(AUTHORITY_TYPE);
account.setHomeAccountId(HOME_ACCOUNT_ID);
account.setEnvironment(ENVIRONMENT);
// Save the Account
mSharedPreferencesAccountCredentialCache.saveAccount(account);
// Synthesize a cache key for it
final String accountCacheKey = mDelegate.generateCacheKey(account);
// Resurrect the Account
final AccountRecord restoredAccount = mSharedPreferencesAccountCredentialCache.getAccount(accountCacheKey);
assertTrue(account.equals(restoredAccount));
}
Aggregations