use of com.microsoft.identity.common.internal.dto.AccessTokenRecord in project microsoft-authentication-library-common-for-android by AzureAD.
the class SharedPreferencesAccountCredentialCacheTest method malformedCacheValueForAccessToken.
@Test
public void malformedCacheValueForAccessToken() {
final AccessTokenRecord accessToken = new AccessTokenRecord();
accessToken.setHomeAccountId(HOME_ACCOUNT_ID);
accessToken.setEnvironment(ENVIRONMENT);
accessToken.setCredentialType(CredentialType.AccessToken.name());
accessToken.setClientId(CLIENT_ID);
// Generate a cache key
final String cacheKey = mDelegate.generateCacheKey(accessToken);
mSharedPreferencesFileManager.putString(cacheKey, "{\"thing\" : \"not an accessToken\"}");
final AccessTokenRecord malformedAccessToken = (AccessTokenRecord) mSharedPreferencesAccountCredentialCache.getCredential(cacheKey);
assertNull(malformedAccessToken);
assertNull(mSharedPreferencesFileManager.getString(cacheKey));
}
use of com.microsoft.identity.common.internal.dto.AccessTokenRecord in project microsoft-authentication-library-common-for-android by AzureAD.
the class SharedPreferencesAccountCredentialCacheTest method getAccounts.
@Test
public void getAccounts() {
// 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);
mSharedPreferencesAccountCredentialCache.saveAccount(account);
// Save an AccessToken into the cache
final AccessTokenRecord accessToken = new AccessTokenRecord();
accessToken.setCredentialType(CredentialType.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);
mSharedPreferencesAccountCredentialCache.saveCredential(accessToken);
// Save a RefreshToken into the cache
final RefreshTokenRecord refreshToken = new RefreshTokenRecord();
refreshToken.setCredentialType(CredentialType.RefreshToken.name());
refreshToken.setEnvironment(ENVIRONMENT);
refreshToken.setHomeAccountId(HOME_ACCOUNT_ID);
refreshToken.setClientId(CLIENT_ID);
refreshToken.setSecret(SECRET);
refreshToken.setTarget(TARGET);
mSharedPreferencesAccountCredentialCache.saveCredential(refreshToken);
// Verify getAccountsFilteredBy() returns one matching element
final List<AccountRecord> accounts = mSharedPreferencesAccountCredentialCache.getAccounts();
assertTrue(accounts.size() == 1);
assertEquals(account, accounts.get(0));
}
use of com.microsoft.identity.common.internal.dto.AccessTokenRecord in project microsoft-authentication-library-common-for-android by AzureAD.
the class SharedPreferencesAccountCredentialCacheTest method noValueForCacheKeyAccessToken.
@Test
public void noValueForCacheKeyAccessToken() {
assertEquals(0, mSharedPreferencesAccountCredentialCache.getCredentials().size());
final AccessTokenRecord accessToken = (AccessTokenRecord) mSharedPreferencesAccountCredentialCache.getCredential(CACHE_VALUE_SEPARATOR + CredentialType.AccessToken.name().toLowerCase() + CACHE_VALUE_SEPARATOR);
assertNull(accessToken);
}
use of com.microsoft.identity.common.internal.dto.AccessTokenRecord in project microsoft-authentication-library-common-for-android by AzureAD.
the class SharedPreferencesAccountCredentialCacheTest method getCredentials.
@Test
public void getCredentials() {
// 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);
mSharedPreferencesAccountCredentialCache.saveAccount(account);
// Save an AccessToken into the cache
final AccessTokenRecord accessToken = new AccessTokenRecord();
accessToken.setCredentialType(CredentialType.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);
mSharedPreferencesAccountCredentialCache.saveCredential(accessToken);
// Save a RefreshToken into the cache
final RefreshTokenRecord refreshToken = new RefreshTokenRecord();
refreshToken.setCredentialType(CredentialType.RefreshToken.name());
refreshToken.setEnvironment(ENVIRONMENT);
refreshToken.setHomeAccountId(HOME_ACCOUNT_ID);
refreshToken.setClientId(CLIENT_ID);
refreshToken.setSecret(SECRET);
refreshToken.setTarget(TARGET);
mSharedPreferencesAccountCredentialCache.saveCredential(refreshToken);
// Verify getCredentials() returns two matching elements
final List<Credential> credentials = mSharedPreferencesAccountCredentialCache.getCredentials();
assertTrue(credentials.size() == 2);
}
use of com.microsoft.identity.common.internal.dto.AccessTokenRecord in project microsoft-authentication-library-common-for-android by AzureAD.
the class SharedPreferencesAccountCredentialCacheTest method malformedJsonCacheValueForAccessToken.
@Test
public void malformedJsonCacheValueForAccessToken() {
final AccessTokenRecord accessToken = new AccessTokenRecord();
accessToken.setHomeAccountId(HOME_ACCOUNT_ID);
accessToken.setEnvironment(ENVIRONMENT);
accessToken.setCredentialType(CredentialType.AccessToken.name());
accessToken.setClientId(CLIENT_ID);
// Generate a cache key
final String cacheKey = mDelegate.generateCacheKey(accessToken);
mSharedPreferencesFileManager.putString(cacheKey, "{\"thing\" \"not an accessToken\"}");
final AccessTokenRecord malformedAccessToken = (AccessTokenRecord) mSharedPreferencesAccountCredentialCache.getCredential(cacheKey);
assertNull(malformedAccessToken);
assertNotNull(mSharedPreferencesFileManager.getString(cacheKey));
}
Aggregations