use of com.microsoft.identity.common.internal.dto.AccountRecord in project microsoft-authentication-library-common-for-android by AzureAD.
the class BrokerOAuth2TokenCacheTest method testGetAccountWithLocalAccountIdAppUidCache.
@Test
public void testGetAccountWithLocalAccountIdAppUidCache() throws ClientException {
configureMocksForAppUid();
mBrokerOAuth2TokenCache.save(mockStrategy, mockRequest, mockResponse);
final AccountRecord account = mBrokerOAuth2TokenCache.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 BrokerOAuth2TokenCacheTest method testGetAccountWithLocalAccountIdFociCache.
@Test
public void testGetAccountWithLocalAccountIdFociCache() throws ClientException {
configureMocksForFoci();
mBrokerOAuth2TokenCache.save(mockStrategy, mockRequest, mockResponse);
final AccountRecord account = mBrokerOAuth2TokenCache.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 BrokerOAuth2TokenCacheTest method testRemoveAccountFromDevice.
@Test
public void testRemoveAccountFromDevice() 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 = mBrokerOAuth2TokenCache.getAccounts();
// Deleting one of these AccountRecords should remove all of them...
final AccountDeletionRecord deletionRecord = mBrokerOAuth2TokenCache.removeAccountFromDevice(xAppAccounts.get(0));
assertEquals(xAppAccounts.size(), deletionRecord.size());
assertEquals(0, mBrokerOAuth2TokenCache.getAccounts().size());
}
use of com.microsoft.identity.common.internal.dto.AccountRecord in project microsoft-authentication-library-common-for-android by AzureAD.
the class MicrosoftFamilyOAuth2TokenCacheTest method testOnlyOneFrtMayExistAcrossClientsForAccount.
@Test
public void testOnlyOneFrtMayExistAcrossClientsForAccount() throws ClientException {
// Save an FRT
final String randomHomeAccountId = UUID.randomUUID().toString();
final String localAccountId = UUID.randomUUID().toString();
final String realm = UUID.randomUUID().toString();
final AccountCredentialTestBundle frtTestBundle = new AccountCredentialTestBundle(MicrosoftAccount.AUTHORITY_TYPE_V1_V2, localAccountId, "test.user@tenant.onmicrosoft.com", randomHomeAccountId, ENVIRONMENT, realm, TARGET, CACHED_AT, EXPIRES_ON, SECRET, CLIENT_ID, SECRET, MicrosoftStsAccountCredentialAdapterTest.MOCK_ID_TOKEN_WITH_CLAIMS, "1", SESSION_KEY, CredentialType.IdToken);
when(mockCredentialAdapter.createAccount(mockStrategy, mockRequest, mockResponse)).thenReturn(frtTestBundle.mGeneratedAccount);
when(mockCredentialAdapter.createAccessToken(mockStrategy, mockRequest, mockResponse)).thenReturn(frtTestBundle.mGeneratedAccessToken);
when(mockCredentialAdapter.createRefreshToken(mockStrategy, mockRequest, mockResponse)).thenReturn(frtTestBundle.mGeneratedRefreshToken);
when(mockCredentialAdapter.createIdToken(mockStrategy, mockRequest, mockResponse)).thenReturn(frtTestBundle.mGeneratedIdToken);
mOauth2TokenCache.save(mockStrategy, mockRequest, mockResponse);
// Save another FRT, this time with a different client id
final AccountCredentialTestBundle frtTestBundle2 = new AccountCredentialTestBundle(MicrosoftAccount.AUTHORITY_TYPE_V1_V2, localAccountId, "test.user@tenant.onmicrosoft.com", randomHomeAccountId, ENVIRONMENT, realm, TARGET, CACHED_AT, EXPIRES_ON, SECRET, CLIENT_ID + "2", SECRET, MicrosoftStsAccountCredentialAdapterTest.MOCK_ID_TOKEN_WITH_CLAIMS, "1", SESSION_KEY, CredentialType.IdToken);
when(mockCredentialAdapter.createAccount(mockStrategy, mockRequest, mockResponse)).thenReturn(frtTestBundle2.mGeneratedAccount);
when(mockCredentialAdapter.createAccessToken(mockStrategy, mockRequest, mockResponse)).thenReturn(frtTestBundle2.mGeneratedAccessToken);
when(mockCredentialAdapter.createRefreshToken(mockStrategy, mockRequest, mockResponse)).thenReturn(frtTestBundle2.mGeneratedRefreshToken);
when(mockCredentialAdapter.createIdToken(mockStrategy, mockRequest, mockResponse)).thenReturn(frtTestBundle2.mGeneratedIdToken);
// Save the family token data
mOauth2TokenCache.save(mockStrategy, mockRequest, mockResponse);
// Test only one FRT exists and it is the second one saved...
final ICacheRecord cacheRecord = mOauth2TokenCache.loadByFamilyId(CLIENT_ID, TARGET, frtTestBundle2.mGeneratedAccount, BEARER_SCHEME);
assertNotNull(cacheRecord);
assertNotNull(cacheRecord.getRefreshToken());
assertNotNull(cacheRecord.getAccessToken());
assertNotNull(cacheRecord.getIdToken());
assertEquals(CLIENT_ID + "2", cacheRecord.getRefreshToken().getClientId());
// Check querying for the FRT in the second app yields the same FRT
final ICacheRecord cacheRecord2 = mOauth2TokenCache.loadByFamilyId(CLIENT_ID + "2", TARGET, frtTestBundle2.mGeneratedAccount, BEARER_SCHEME);
assertNotNull(cacheRecord2);
assertNotNull(cacheRecord2.getRefreshToken());
assertNotNull(cacheRecord2.getAccessToken());
assertNotNull(cacheRecord2.getIdToken());
assertEquals(CLIENT_ID + "2", cacheRecord2.getRefreshToken().getClientId());
// Test querying with a different account yields nothing at all....
final AccountRecord randomAcct = new AccountRecord();
randomAcct.setAuthorityType(AUTHORITY_TYPE);
randomAcct.setLocalAccountId(UUID.randomUUID().toString());
randomAcct.setUsername("foo@bar.com");
randomAcct.setHomeAccountId(UUID.randomUUID().toString());
randomAcct.setEnvironment(ENVIRONMENT);
randomAcct.setRealm(REALM);
final ICacheRecord cacheRecord3 = mOauth2TokenCache.loadByFamilyId(CLIENT_ID + "2", TARGET, randomAcct, BEARER_SCHEME);
assertNotNull(cacheRecord3);
assertNotNull(cacheRecord3.getAccount());
assertNull(cacheRecord3.getRefreshToken());
assertNull(cacheRecord3.getAccessToken());
assertNull(cacheRecord3.getIdToken());
}
use of com.microsoft.identity.common.internal.dto.AccountRecord in project microsoft-authentication-library-common-for-android by AzureAD.
the class MsalCppOAuth2TokenCacheTest method forceRemoveAccountWithHomeAccountIdTest.
@Test
public void forceRemoveAccountWithHomeAccountIdTest() 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(), "", "");
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);
}
Aggregations