use of com.microsoft.identity.common.internal.dto.AccountRecord in project microsoft-authentication-library-common-for-android by AzureAD.
the class SharedPreferencesAccountCredentialCacheTest method getAccountsNoHomeAccountIdNoRealm.
@Test
public void getAccountsNoHomeAccountIdNoRealm() {
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(null, ENVIRONMENT, null);
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 getAccountsWithMatchingEnvironmentRealm.
@Test
public void getAccountsWithMatchingEnvironmentRealm() {
final AccountRecord account1 = new AccountRecord();
account1.setLocalAccountId(LOCAL_ACCOUNT_ID);
account1.setUsername(USERNAME);
account1.setAuthorityType(AUTHORITY_TYPE);
account1.setHomeAccountId("Foo");
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("Bar");
account2.setEnvironment(ENVIRONMENT);
account2.setRealm(REALM);
final AccountRecord account3 = new AccountRecord();
account3.setLocalAccountId(LOCAL_ACCOUNT_ID);
account3.setUsername(USERNAME);
account3.setAuthorityType(AUTHORITY_TYPE);
account3.setHomeAccountId("Baz");
account3.setEnvironment(ENVIRONMENT);
account3.setRealm(REALM);
final AccountRecord account4 = new AccountRecord();
account4.setLocalAccountId(LOCAL_ACCOUNT_ID);
account4.setUsername(USERNAME);
account4.setAuthorityType(AUTHORITY_TYPE);
account4.setHomeAccountId("qux");
account4.setEnvironment(ENVIRONMENT);
account4.setRealm("quz");
// Save the Accounts
mSharedPreferencesAccountCredentialCache.saveAccount(account1);
mSharedPreferencesAccountCredentialCache.saveAccount(account2);
mSharedPreferencesAccountCredentialCache.saveAccount(account3);
mSharedPreferencesAccountCredentialCache.saveAccount(account4);
final List<AccountRecord> accounts = mSharedPreferencesAccountCredentialCache.getAccountsFilteredBy(null, ENVIRONMENT, REALM);
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 persistAndRestoreExtraClaimsAccount.
@Test
public void persistAndRestoreExtraClaimsAccount() {
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);
account.setMiddleName(MIDDLE_NAME);
account.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 String secondAdditionalKey = "extra-prop-2";
final String secondAdditionalValue = "extra-value-2";
final JsonElement secondAdditionalValueElement = new JsonPrimitive(secondAdditionalValue);
final Map<String, JsonElement> additionalFields = new HashMap<>();
additionalFields.put(additionalKey, additionalValueElement);
additionalFields.put(secondAdditionalKey, secondAdditionalValueElement);
account.setAdditionalFields(additionalFields);
// Save the Credential
mSharedPreferencesAccountCredentialCache.saveAccount(account);
// Synthesize a cache key for it
final String credentialCacheKey = mDelegate.generateCacheKey(account);
// Resurrect the Credential
final AccountRecord restoredAccount = mSharedPreferencesAccountCredentialCache.getAccount(credentialCacheKey);
assertTrue(account.equals(restoredAccount));
assertEquals(additionalValue, restoredAccount.getAdditionalFields().get(additionalKey).getAsString());
assertEquals(secondAdditionalValue, restoredAccount.getAdditionalFields().get(secondAdditionalKey).getAsString());
}
use of com.microsoft.identity.common.internal.dto.AccountRecord in project microsoft-authentication-library-common-for-android by AzureAD.
the class MsalOAuth2TokenCacheTest method getAccountByLocalAccountId.
@Test
public void getAccountByLocalAccountId() throws ClientException {
// Save an Account into the cache
mOauth2TokenCache.save(mockStrategy, mockRequest, mockResponse);
// Find it by the local_account_id
final AccountRecord account = mOauth2TokenCache.getAccountByLocalAccountId(ENVIRONMENT, CLIENT_ID, LOCAL_ACCOUNT_ID);
assertNotNull(account);
}
use of com.microsoft.identity.common.internal.dto.AccountRecord in project microsoft-authentication-library-common-for-android by AzureAD.
the class MsalOAuth2TokenCacheTest method saveTokensWithIntersect.
@Test
public void saveTokensWithIntersect() throws Exception {
// Manually insert an AT with a ltd scope into the cache
final String extendedScopes = "calendar.modify user.read user.write https://graph.windows.net";
AccessTokenRecord accessTokenToClear = new AccessTokenRecord();
accessTokenToClear.setRealm(REALM);
accessTokenToClear.setCachedAt(CACHED_AT);
accessTokenToClear.setExpiresOn(EXPIRES_ON);
accessTokenToClear.setSecret(SECRET);
accessTokenToClear.setHomeAccountId(HOME_ACCOUNT_ID);
accessTokenToClear.setEnvironment(ENVIRONMENT);
accessTokenToClear.setCredentialType(AccessToken.name());
accessTokenToClear.setClientId(CLIENT_ID);
accessTokenToClear.setTarget(TARGET);
// Save this dummy AT
accountCredentialCache.saveCredential(accessTokenToClear);
// Set the wider target on the new AT to write...
defaultTestBundleV2.mGeneratedAccessToken.setTarget(extendedScopes);
mOauth2TokenCache.save(mockStrategy, mockRequest, mockResponse);
final List<AccountRecord> accounts = accountCredentialCache.getAccounts();
assertEquals(1, accounts.size());
assertEquals(defaultTestBundleV2.mGeneratedAccount, accounts.get(0));
final List<Credential> credentials = accountCredentialCache.getCredentials();
assertEquals(3, credentials.size());
final List<Credential> rts = new ArrayList<>();
final List<Credential> ats = new ArrayList<>();
final List<Credential> ids = new ArrayList<>();
sortResultToLists(credentials, rts, ats, ids);
assertEquals(defaultTestBundleV2.mGeneratedAccessToken, ats.get(0));
assertEquals(defaultTestBundleV2.mGeneratedRefreshToken, rts.get(0));
assertEquals(defaultTestBundleV2.mGeneratedIdToken, ids.get(0));
}
Aggregations