use of com.microsoft.identity.common.internal.cache.ICacheRecord in project microsoft-authentication-library-common-for-android by AzureAD.
the class BrokerOAuth2TokenCacheTest method testGetFociCacheRecordsEmpty.
@Test
public void testGetFociCacheRecordsEmpty() throws ClientException {
configureMocksForAppUid();
final ICacheRecord result = mBrokerOAuth2TokenCache.save(mockStrategy, mockRequest, mockResponse);
final List<ICacheRecord> fociCacheRecords = mBrokerOAuth2TokenCache.getFociCacheRecords();
assertNotNull(fociCacheRecords);
assertTrue(fociCacheRecords.isEmpty());
}
use of com.microsoft.identity.common.internal.cache.ICacheRecord in project microsoft-authentication-library-common-for-android by AzureAD.
the class BrokerOAuth2TokenCacheTest method testGetFociCacheRecords.
@Test
public void testGetFociCacheRecords() throws ClientException {
configureMocksForFoci();
final ICacheRecord result = mBrokerOAuth2TokenCache.save(mockStrategy, mockRequest, mockResponse);
final List<ICacheRecord> fociCacheRecords = mBrokerOAuth2TokenCache.getFociCacheRecords();
assertNotNull(fociCacheRecords);
assertFalse(fociCacheRecords.isEmpty());
assertEquals(result.getRefreshToken(), fociCacheRecords.get(0).getRefreshToken());
assertEquals(result.getIdToken(), fociCacheRecords.get(0).getIdToken());
}
use of com.microsoft.identity.common.internal.cache.ICacheRecord 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.cache.ICacheRecord 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.cache.ICacheRecord in project microsoft-authentication-library-common-for-android by AzureAD.
the class MicrosoftFamilyOAuth2TokenCacheTest method testRetrieveFrt.
@Test
public void testRetrieveFrt() throws ClientException {
final String randomHomeAccountId = UUID.randomUUID().toString();
final AccountCredentialTestBundle frtTestBundle = new AccountCredentialTestBundle(MicrosoftAccount.AUTHORITY_TYPE_V1_V2, UUID.randomUUID().toString(), "test.user@tenant.onmicrosoft.com", randomHomeAccountId, ENVIRONMENT, UUID.randomUUID().toString(), 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);
// Save the family token data
mOauth2TokenCache.save(mockStrategy, mockRequest, mockResponse);
final ICacheRecord familyCacheRecord = mOauth2TokenCache.loadByFamilyId(null, TARGET, frtTestBundle.mGeneratedAccount, BEARER_SCHEME);
assertNotNull(familyCacheRecord);
assertNotNull(familyCacheRecord.getAccount());
assertNotNull(familyCacheRecord.getRefreshToken());
assertNull(familyCacheRecord.getIdToken());
assertNull(familyCacheRecord.getAccessToken());
final ICacheRecord familyCacheRecordWithClientId = mOauth2TokenCache.loadByFamilyId(CLIENT_ID, TARGET, frtTestBundle.mGeneratedAccount, BEARER_SCHEME);
assertNotNull(familyCacheRecordWithClientId);
assertNotNull(familyCacheRecordWithClientId.getAccount());
assertNotNull(familyCacheRecordWithClientId.getRefreshToken());
assertNotNull(familyCacheRecordWithClientId.getIdToken());
assertNotNull(familyCacheRecordWithClientId.getAccessToken());
final ICacheRecord familyCacheRecordWithClientIdButNonMatchingTarget = mOauth2TokenCache.loadByFamilyId(CLIENT_ID, TARGET, frtTestBundle.mGeneratedAccount, BEARER_SCHEME);
assertNotNull(familyCacheRecordWithClientIdButNonMatchingTarget);
assertNotNull(familyCacheRecordWithClientIdButNonMatchingTarget.getAccount());
assertNotNull(familyCacheRecordWithClientIdButNonMatchingTarget.getRefreshToken());
assertNotNull(familyCacheRecordWithClientIdButNonMatchingTarget.getIdToken());
assertNotNull(familyCacheRecordWithClientIdButNonMatchingTarget.getAccessToken());
final ICacheRecord wrongClientIdResult = mOauth2TokenCache.loadByFamilyId("12345", TARGET, frtTestBundle.mGeneratedAccount, BEARER_SCHEME);
assertNotNull(wrongClientIdResult);
assertNotNull(wrongClientIdResult.getAccount());
assertNotNull(wrongClientIdResult.getRefreshToken());
assertNull(wrongClientIdResult.getIdToken());
assertNull(wrongClientIdResult.getAccessToken());
}
Aggregations