use of com.microsoft.identity.common.internal.dto.AccountRecord in project microsoft-authentication-library-common-for-android by AzureAD.
the class SharedPreferencesAccountCredentialCacheTest method getAccountsWithMatchingHomeAccountIdEnvironment.
@Test
public void getAccountsWithMatchingHomeAccountIdEnvironment() {
final AccountRecord account1 = new AccountRecord();
account1.setLocalAccountId(LOCAL_ACCOUNT_ID);
account1.setUsername(USERNAME);
account1.setAuthorityType(AUTHORITY_TYPE);
account1.setHomeAccountId(HOME_ACCOUNT_ID);
account1.setEnvironment(ENVIRONMENT);
account1.setRealm(REALM);
final AccountRecord account2 = new AccountRecord();
account2.setLocalAccountId(LOCAL_ACCOUNT_ID);
account2.setUsername(USERNAME);
account2.setAuthorityType(AUTHORITY_TYPE);
account2.setHomeAccountId(HOME_ACCOUNT_ID);
account2.setEnvironment(ENVIRONMENT);
account2.setRealm(REALM2);
final AccountRecord account3 = new AccountRecord();
account3.setLocalAccountId(LOCAL_ACCOUNT_ID);
account3.setUsername(USERNAME);
account3.setAuthorityType(AUTHORITY_TYPE);
account3.setHomeAccountId(HOME_ACCOUNT_ID);
account3.setEnvironment(ENVIRONMENT);
account3.setRealm(REALM3);
final AccountRecord account4 = new AccountRecord();
account4.setLocalAccountId(LOCAL_ACCOUNT_ID);
account4.setUsername(USERNAME);
account4.setAuthorityType(AUTHORITY_TYPE);
account4.setHomeAccountId(HOME_ACCOUNT_ID);
account4.setEnvironment("Foo");
account4.setRealm(REALM);
// Save the Accounts
mSharedPreferencesAccountCredentialCache.saveAccount(account1);
mSharedPreferencesAccountCredentialCache.saveAccount(account2);
mSharedPreferencesAccountCredentialCache.saveAccount(account3);
mSharedPreferencesAccountCredentialCache.saveAccount(account4);
final List<AccountRecord> accounts = mSharedPreferencesAccountCredentialCache.getAccountsFilteredBy(HOME_ACCOUNT_ID, ENVIRONMENT, null);
assertEquals(3, accounts.size());
}
use of com.microsoft.identity.common.internal.dto.AccountRecord in project microsoft-authentication-library-common-for-android by AzureAD.
the class SharedPreferencesAccountCredentialCacheTest method clearAccounts.
@Test
public void clearAccounts() {
// 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(REALM);
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 clearAccounts()
mSharedPreferencesAccountCredentialCache.removeAccount(account);
// Verify getAccounts() returns zero items
assertTrue(mSharedPreferencesAccountCredentialCache.getAccounts().isEmpty());
// Verify getCredentials() returns two items
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 getAccountsComplete.
@Test
public void getAccountsComplete() {
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);
// Save the Account
mSharedPreferencesAccountCredentialCache.saveAccount(account);
// Test retrieval
final List<AccountRecord> accounts = mSharedPreferencesAccountCredentialCache.getAccountsFilteredBy(HOME_ACCOUNT_ID, ENVIRONMENT, REALM);
assertEquals(1, accounts.size());
final AccountRecord retrievedAccount = accounts.get(0);
assertEquals(HOME_ACCOUNT_ID, retrievedAccount.getHomeAccountId());
assertEquals(ENVIRONMENT, retrievedAccount.getEnvironment());
assertEquals(REALM, retrievedAccount.getRealm());
}
use of com.microsoft.identity.common.internal.dto.AccountRecord in project microsoft-authentication-library-common-for-android by AzureAD.
the class SharedPreferencesAccountCredentialCacheTest method malformedJsonCacheValueForAccount.
@Test
public void malformedJsonCacheValueForAccount() {
final AccountRecord account = new AccountRecord();
account.setHomeAccountId(HOME_ACCOUNT_ID);
account.setEnvironment(ENVIRONMENT);
account.setRealm(REALM);
// Generate a cache key
final String cacheKey = mDelegate.generateCacheKey(account);
mSharedPreferencesFileManager.putString(cacheKey, "{\"thing\" \"not an account\"}");
final AccountRecord malformedAccount = mSharedPreferencesAccountCredentialCache.getAccount(cacheKey);
assertNull(malformedAccount);
assertNotNull(mSharedPreferencesFileManager.getString(cacheKey));
}
use of com.microsoft.identity.common.internal.dto.AccountRecord in project microsoft-authentication-library-common-for-android by AzureAD.
the class SharedPreferencesAccountCredentialCacheTest method getAccounts.
@Test
public void getAccounts() {
// 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 getAccountsFilteredBy() returns one matching element
final List<AccountRecord> accounts = mSharedPreferencesAccountCredentialCache.getAccounts();
assertTrue(accounts.size() == 1);
assertEquals(account, accounts.get(0));
}
Aggregations