use of com.microsoft.identity.common.internal.dto.AccountRecord in project azure-activedirectory-library-for-android by AzureAD.
the class AuthenticationContextTest method testClearAdalCacheRemovesReplicaCache.
@Test
public void testClearAdalCacheRemovesReplicaCache() {
// Init a Context
final Context context = getInstrumentation().getContext();
// Create an instance of the MSAL cache, populate it with some data
final IAccountCredentialCache accountCredentialCache = new SharedPreferencesAccountCredentialCache(new CacheKeyValueDelegate(), new SharedPreferencesFileManager(context, DEFAULT_ACCOUNT_CREDENTIAL_SHARED_PREFERENCES, new StorageHelper(context)));
// Create a dummy account
final AccountRecord dummyAccount = new AccountRecord();
dummyAccount.setHomeAccountId("23bfff3f-2664-495d-8196-79e28eaf400b");
dummyAccount.setEnvironment("login.windows.net");
dummyAccount.setRealm("0b96cce5-7aef-4ecb-bb27-2e50e3ed69de");
dummyAccount.setName("Garth Fort");
// Save it
accountCredentialCache.saveAccount(dummyAccount);
// Assert that the dummy account exists
assertEquals(dummyAccount, accountCredentialCache.getAccounts().get(0));
// Create an instance of the Authentication Context
final AuthenticationContext authContext = new AuthenticationContext(getInstrumentation().getContext(), "https://github.com/MSOpenTech/some/some", false);
// Clear the ADAL cache
authContext.getCache().removeAll();
// Assert that the replica is empty
assertTrue(accountCredentialCache.getAccounts().isEmpty());
}
use of com.microsoft.identity.common.internal.dto.AccountRecord in project microsoft-authentication-library-common-for-android by AzureAD.
the class MsalOAuth2TokenCacheTest method assertAccountLoaded.
private void assertAccountLoaded() {
final AccountRecord account = mOauth2TokenCache.getAccount(ENVIRONMENT, CLIENT_ID, HOME_ACCOUNT_ID, REALM);
assertNotNull(account);
assertEquals(MicrosoftAccount.AUTHORITY_TYPE_V1_V2, account.getAuthorityType());
assertEquals(LOCAL_ACCOUNT_ID, account.getLocalAccountId());
assertEquals(USERNAME, account.getUsername());
assertEquals(HOME_ACCOUNT_ID, account.getHomeAccountId());
assertEquals(ENVIRONMENT, account.getEnvironment());
assertEquals(REALM, account.getRealm());
}
use of com.microsoft.identity.common.internal.dto.AccountRecord in project microsoft-authentication-library-common-for-android by AzureAD.
the class MsalOAuth2TokenCacheTest method testGetFamilyRefreshTokenForHomeAccountIdNoAccountWithHomeAccountId.
@Test
public void testGetFamilyRefreshTokenForHomeAccountIdNoAccountWithHomeAccountId() {
// Save an Account into the cache
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);
accountCredentialCache.saveAccount(account);
// Save an AccessToken into the cache
final AccessTokenRecord accessToken = new AccessTokenRecord();
accessToken.setCredentialType(AccessToken.name());
accessToken.setHomeAccountId(HOME_ACCOUNT_ID);
accessToken.setRealm("Foo");
accessToken.setEnvironment(ENVIRONMENT);
accessToken.setClientId(CLIENT_ID);
accessToken.setTarget(TARGET);
accessToken.setCachedAt(CACHED_AT);
accessToken.setExpiresOn(EXPIRES_ON);
accessToken.setSecret(SECRET);
accountCredentialCache.saveCredential(accessToken);
// Save a Family RefreshToken into the cache
final RefreshTokenRecord refreshToken = new RefreshTokenRecord();
refreshToken.setCredentialType(RefreshToken.name());
refreshToken.setEnvironment(ENVIRONMENT);
refreshToken.setHomeAccountId(HOME_ACCOUNT_ID);
refreshToken.setClientId(CLIENT_ID);
refreshToken.setFamilyId("1");
refreshToken.setSecret(SECRET);
refreshToken.setTarget(TARGET);
accountCredentialCache.saveCredential(refreshToken);
final IdTokenRecord id = new IdTokenRecord();
id.setHomeAccountId(HOME_ACCOUNT_ID);
id.setEnvironment(ENVIRONMENT);
id.setRealm(REALM2);
id.setCredentialType(IdToken.name());
id.setClientId(CLIENT_ID);
id.setSecret(MOCK_ID_TOKEN_WITH_CLAIMS);
id.setAuthority("https://sts.windows.net/0287f963-2d72-4363-9e3a-5705c5b0f031/");
accountCredentialCache.saveCredential(id);
final RefreshTokenRecord refreshTokenRecord = mOauth2TokenCache.getFamilyRefreshTokenForHomeAccountId(// different home account id
"26685724-1f8e-4b97-a0ca-1863e33b9fb1");
assertNull(refreshTokenRecord);
}
use of com.microsoft.identity.common.internal.dto.AccountRecord in project microsoft-authentication-library-common-for-android by AzureAD.
the class MsalOAuth2TokenCacheTest method saveTokensWithAggregationMultiEntry.
@Test
public void saveTokensWithAggregationMultiEntry() throws ClientException {
// Load additional creds into the cache to simulate a guest account...
// at, id, account
final AccessTokenRecord at = new AccessTokenRecord();
at.setRealm(REALM2);
at.setCachedAt(CACHED_AT);
at.setExpiresOn(EXPIRES_ON);
at.setSecret(SECRET);
at.setHomeAccountId(HOME_ACCOUNT_ID);
at.setEnvironment(ENVIRONMENT);
at.setCredentialType(AccessToken.name());
at.setClientId(CLIENT_ID);
at.setTarget(TARGET);
final IdTokenRecord id = new IdTokenRecord();
id.setHomeAccountId(HOME_ACCOUNT_ID);
id.setEnvironment(ENVIRONMENT);
id.setRealm(REALM2);
id.setCredentialType(IdToken.name());
id.setClientId(CLIENT_ID);
id.setSecret(MOCK_ID_TOKEN_WITH_CLAIMS);
id.setAuthority("https://sts.windows.net/0287f963-2d72-4363-9e3a-5705c5b0f031/");
final AccountRecord acct = new AccountRecord();
acct.setAuthorityType(AUTHORITY_TYPE);
acct.setLocalAccountId(UUID.randomUUID().toString());
acct.setUsername(USERNAME);
acct.setHomeAccountId(HOME_ACCOUNT_ID);
acct.setEnvironment(ENVIRONMENT);
acct.setRealm(REALM2);
accountCredentialCache.saveAccount(acct);
accountCredentialCache.saveCredential(at);
accountCredentialCache.saveCredential(id);
final List<ICacheRecord> result = loadTestBundleIntoCacheWithAggregation(defaultTestBundleV2);
assertEquals(2, result.size());
final ICacheRecord entry1 = result.get(0);
assertNotNull(entry1.getAccount());
assertNotNull(entry1.getIdToken());
assertNotNull(entry1.getAccessToken());
assertNotNull(entry1.getRefreshToken());
final ICacheRecord entry2 = result.get(1);
assertNotNull(entry2.getAccount());
assertNotNull(entry2.getIdToken());
assertNull(entry2.getAccessToken());
assertNull(entry2.getRefreshToken());
}
use of com.microsoft.identity.common.internal.dto.AccountRecord in project microsoft-authentication-library-common-for-android by AzureAD.
the class MsalOAuth2TokenCacheTest method testGetFamilyRefreshTokenForHomeAccountIdValidCase.
@Test
public void testGetFamilyRefreshTokenForHomeAccountIdValidCase() {
// Save an Account into the cache
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);
accountCredentialCache.saveAccount(account);
// Save an AccessToken into the cache
final AccessTokenRecord accessToken = new AccessTokenRecord();
accessToken.setCredentialType(AccessToken.name());
accessToken.setHomeAccountId(HOME_ACCOUNT_ID);
accessToken.setRealm("Foo");
accessToken.setEnvironment(ENVIRONMENT);
accessToken.setClientId(CLIENT_ID);
accessToken.setTarget(TARGET);
accessToken.setCachedAt(CACHED_AT);
accessToken.setExpiresOn(EXPIRES_ON);
accessToken.setSecret(SECRET);
accountCredentialCache.saveCredential(accessToken);
// Save a Family RefreshToken into the cache
final RefreshTokenRecord refreshToken = new RefreshTokenRecord();
refreshToken.setCredentialType(RefreshToken.name());
refreshToken.setEnvironment(ENVIRONMENT);
refreshToken.setHomeAccountId(HOME_ACCOUNT_ID);
refreshToken.setClientId(CLIENT_ID);
refreshToken.setFamilyId("1");
refreshToken.setSecret(SECRET);
refreshToken.setTarget(TARGET);
accountCredentialCache.saveCredential(refreshToken);
final IdTokenRecord id = new IdTokenRecord();
id.setHomeAccountId(HOME_ACCOUNT_ID);
id.setEnvironment(ENVIRONMENT);
id.setRealm(REALM2);
id.setCredentialType(IdToken.name());
id.setClientId(CLIENT_ID);
id.setSecret(MOCK_ID_TOKEN_WITH_CLAIMS);
id.setAuthority("https://sts.windows.net/0287f963-2d72-4363-9e3a-5705c5b0f031/");
accountCredentialCache.saveCredential(id);
final RefreshTokenRecord refreshTokenRecord = mOauth2TokenCache.getFamilyRefreshTokenForHomeAccountId(HOME_ACCOUNT_ID);
assertNotNull(refreshTokenRecord);
assertEquals(refreshTokenRecord.getSecret(), SECRET);
}
Aggregations