use of com.microsoft.identity.common.internal.dto.AccountRecord in project microsoft-authentication-library-common-for-android by AzureAD.
the class BrokerOAuth2TokenCacheTest method testCanSaveIntoFociCache.
@Test
public void testCanSaveIntoFociCache() throws ClientException {
configureMocksForFoci();
mBrokerOAuth2TokenCache.save(mockStrategy, mockRequest, mockResponse);
final List<AccountRecord> accounts = mFociCredentialCache.getAccounts();
assertEquals(1, accounts.size());
assertEquals(mDefaultFociTestBundle.mGeneratedAccount, accounts.get(0));
final List<Credential> credentials = mFociCredentialCache.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(mDefaultFociTestBundle.mGeneratedAccessToken, ats.get(0));
assertEquals(mDefaultFociTestBundle.mGeneratedRefreshToken, rts.get(0));
assertEquals(mDefaultFociTestBundle.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 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.dto.AccountRecord in project microsoft-authentication-library-common-for-android by AzureAD.
the class MicrosoftStsAccountCredentialAdapterTest method createAccount.
@Test
public void createAccount() {
// This test is now basically a copy-constructor test
final AccountRecord account = mAccountCredentialAdapter.createAccount(mockStrategy, mockRequest, mockResponse);
assertNotNull(account);
assertEquals(MOCK_UID + "." + MOCK_UTID, account.getHomeAccountId());
assertEquals(MOCK_ENVIRONMENT, account.getEnvironment());
assertEquals(MOCK_CLIENT_INFO, account.getClientInfo());
assertEquals(MOCK_TID, account.getRealm());
assertEquals(MOCK_OID, account.getLocalAccountId());
assertEquals(MOCK_PREFERRED_USERNAME, account.getUsername());
assertEquals("MSSTS", account.getAuthorityType());
assertEquals(MOCK_GIVEN_NAME, account.getFirstName());
assertEquals(MOCK_FAMILY_NAME, account.getFamilyName());
assertEquals(MOCK_MIDDLE_NAME, account.getMiddleName());
assertEquals(MOCK_NAME, account.getName());
}
use of com.microsoft.identity.common.internal.dto.AccountRecord in project microsoft-authentication-library-common-for-android by AzureAD.
the class MsalCppOAuth2TokenCacheTest method forceRemoveAccountTest.
@Test
public void forceRemoveAccountTest() throws ClientException {
// Get the generated account
final AccountRecord generatedAccount = mTestBundle.mGeneratedAccount;
// Save it to the cache
mCppCache.saveAccountRecord(generatedAccount);
// Do not save any credentials for this account...
final AccountDeletionRecord deletionRecord = mCppCache.forceRemoveAccount(generatedAccount.getHomeAccountId(), generatedAccount.getEnvironment(), generatedAccount.getRealm());
Assert.assertEquals(1, deletionRecord.size());
// Try to restore it
final AccountRecord restoredAccount = mCppCache.getAccount(generatedAccount.getHomeAccountId(), generatedAccount.getEnvironment(), generatedAccount.getRealm());
// Make sure it doesn't exist....
Assert.assertNull(restoredAccount);
}
use of com.microsoft.identity.common.internal.dto.AccountRecord in project microsoft-authentication-library-common-for-android by AzureAD.
the class MsalCppOAuth2TokenCacheTest method removeAccountWithHomeAccountIdTest.
@Test
public void removeAccountWithHomeAccountIdTest() throws ClientException {
// Get the generated account
final AccountRecord generatedAccount = mTestBundle.mGeneratedAccount;
// Save it to the cache
mCppCache.saveAccountRecord(generatedAccount);
mCppCache.saveCredentials(null, mTestBundle.mGeneratedRefreshToken);
// Call remove
final AccountDeletionRecord deletionRecord = mCppCache.removeAccount(generatedAccount.getHomeAccountId(), "", "");
// Check the receipt
Assert.assertEquals(generatedAccount, deletionRecord.get(0));
// Try to restore it
final AccountRecord restoredAccount = mCppCache.getAccount(generatedAccount.getHomeAccountId(), generatedAccount.getEnvironment(), generatedAccount.getRealm());
// Make sure it doesn't exist....
Assert.assertNull(restoredAccount);
}
Aggregations