use of com.microsoft.identity.common.internal.dto.AccountRecord in project microsoft-authentication-library-common-for-android by AzureAD.
the class MsalCppOAuth2TokenCacheTest method removeAccountNoRTTest.
@Test
public void removeAccountNoRTTest() throws ClientException {
// Get the generated account
final AccountRecord generatedAccount = mTestBundle.mGeneratedAccount;
// Save it to the cache
mCppCache.saveAccountRecord(generatedAccount);
// Call remove
final AccountDeletionRecord deletionRecord = mCppCache.removeAccount(generatedAccount.getHomeAccountId(), generatedAccount.getEnvironment(), generatedAccount.getRealm());
// 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);
}
use of com.microsoft.identity.common.internal.dto.AccountRecord in project microsoft-authentication-library-common-for-android by AzureAD.
the class MsalCppOAuth2TokenCacheTest method saveCredentialsWithAccountTest.
@Test
public void saveCredentialsWithAccountTest() throws ClientException {
final AccountRecord generatedAccount = mTestBundle.mGeneratedAccount;
mCppCache.saveAccountRecord(generatedAccount);
mCppCache.saveCredentials(generatedAccount, mTestBundle.mGeneratedAccessToken, mTestBundle.mGeneratedIdToken, mTestBundle.mGeneratedRefreshToken);
// Restore it
final AccountRecord restoredAccount = mCppCache.getAccount(generatedAccount.getHomeAccountId(), generatedAccount.getEnvironment(), generatedAccount.getRealm());
Assert.assertNotNull(restoredAccount);
Assert.assertEquals(generatedAccount, restoredAccount);
final ICacheRecord cacheRecord = mCppCache.load(mTestBundle.mGeneratedIdToken.getClientId(), mTestBundle.mGeneratedAccessToken.getTarget(), generatedAccount, new BearerAuthenticationSchemeInternal());
Assert.assertEquals(mTestBundle.mGeneratedAccessToken, cacheRecord.getAccessToken());
}
use of com.microsoft.identity.common.internal.dto.AccountRecord in project microsoft-authentication-library-common-for-android by AzureAD.
the class MsalCppOAuth2TokenCacheTest method removeTwoAccountsWithDifferentRealmsAndEnvironmentsTest.
@Test
public void removeTwoAccountsWithDifferentRealmsAndEnvironmentsTest() throws ClientException {
// Get the generated account
final AccountRecord generatedAccount = mTestBundle.mGeneratedAccount;
// Save it to the cache
mCppCache.saveAccountRecord(generatedAccount);
mCppCache.saveCredentials(null, mTestBundle.mGeneratedRefreshToken);
// Save the second account with a different realm and environment
generatedAccount.setEnvironment("login.chinacloudapi.cn");
generatedAccount.setRealm(REALM2);
mCppCache.saveAccountRecord(generatedAccount);
// Call remove
final AccountDeletionRecord deletionRecord = mCppCache.removeAccount(generatedAccount.getHomeAccountId(), "", "");
// Check the receipt, should delete both
Assert.assertEquals(2, deletionRecord.size());
// Try to restore them
final AccountRecord restoredAccount = mCppCache.getAccount(generatedAccount.getHomeAccountId(), generatedAccount.getEnvironment(), REALM);
final AccountRecord restoredAccount2 = mCppCache.getAccount(generatedAccount.getHomeAccountId(), "login.chinacloudapi.cn", REALM2);
// Make sure they don't exist....
Assert.assertNull(restoredAccount);
Assert.assertNull(restoredAccount2);
}
use of com.microsoft.identity.common.internal.dto.AccountRecord in project microsoft-authentication-library-common-for-android by AzureAD.
the class MsalCppOAuth2TokenCacheTest method saveAndGetAccountTest.
@Test
public void saveAndGetAccountTest() throws ClientException {
final AccountRecord generatedAccount = mTestBundle.mGeneratedAccount;
// Save the the cache
mCppCache.saveAccountRecord(generatedAccount);
// Restore it
final AccountRecord restoredAccount = mCppCache.getAccount(generatedAccount.getHomeAccountId(), generatedAccount.getEnvironment(), generatedAccount.getRealm());
Assert.assertNotNull(restoredAccount);
Assert.assertEquals(generatedAccount, restoredAccount);
}
use of com.microsoft.identity.common.internal.dto.AccountRecord in project microsoft-authentication-library-common-for-android by AzureAD.
the class MsalCppOAuth2TokenCacheTest method saveCredentialsWithoutAccountTest.
@Test
public void saveCredentialsWithoutAccountTest() throws ClientException {
final AccountRecord generatedAccount = mTestBundle.mGeneratedAccount;
mCppCache.saveCredentials(null, mTestBundle.mGeneratedAccessToken, mTestBundle.mGeneratedIdToken, mTestBundle.mGeneratedRefreshToken);
// Restore it
final AccountRecord restoredAccount = mCppCache.getAccount(generatedAccount.getHomeAccountId(), generatedAccount.getEnvironment(), generatedAccount.getRealm());
// Account doesn't exist
Assert.assertNull(restoredAccount);
// Inspect the contents of the cache
final List<Credential> credentials = mCppCache.getCredentials();
Assert.assertTrue(credentials.contains(mTestBundle.mGeneratedAccessToken));
Assert.assertTrue(credentials.contains(mTestBundle.mGeneratedIdToken));
Assert.assertTrue(credentials.contains(mTestBundle.mGeneratedRefreshToken));
}
Aggregations