use of com.microsoft.identity.common.internal.dto.AccessTokenRecord in project microsoft-authentication-library-common-for-android by AzureAD.
the class SharedPreferencesAccountCredentialCacheTest method getCredentialsNoRealm.
@Test
public void getCredentialsNoRealm() {
final RefreshTokenRecord refreshToken = new RefreshTokenRecord();
refreshToken.setSecret(SECRET);
refreshToken.setHomeAccountId(HOME_ACCOUNT_ID);
refreshToken.setEnvironment(ENVIRONMENT);
refreshToken.setCredentialType(CredentialType.RefreshToken.name());
refreshToken.setClientId(CLIENT_ID);
refreshToken.setTarget(TARGET);
final AccessTokenRecord accessToken = new AccessTokenRecord();
accessToken.setCachedAt(CACHED_AT);
accessToken.setExpiresOn(EXPIRES_ON);
accessToken.setSecret(SECRET);
accessToken.setHomeAccountId(HOME_ACCOUNT_ID);
accessToken.setRealm("Foo");
accessToken.setEnvironment(ENVIRONMENT);
accessToken.setCredentialType(CredentialType.AccessToken.name());
accessToken.setClientId(CLIENT_ID);
accessToken.setTarget(TARGET);
final AccessTokenRecord accessToken2 = new AccessTokenRecord();
accessToken2.setCachedAt(CACHED_AT);
accessToken2.setExpiresOn(EXPIRES_ON);
accessToken2.setSecret(SECRET);
accessToken2.setHomeAccountId(HOME_ACCOUNT_ID);
accessToken2.setRealm("Bar");
accessToken2.setEnvironment(ENVIRONMENT);
accessToken2.setCredentialType(CredentialType.AccessToken.name());
accessToken2.setClientId(CLIENT_ID);
accessToken2.setTarget(TARGET);
// Save the Credentials
mSharedPreferencesAccountCredentialCache.saveCredential(refreshToken);
mSharedPreferencesAccountCredentialCache.saveCredential(accessToken);
mSharedPreferencesAccountCredentialCache.saveCredential(accessToken2);
List<Credential> credentials = mSharedPreferencesAccountCredentialCache.getCredentialsFilteredBy(HOME_ACCOUNT_ID, ENVIRONMENT, CredentialType.AccessToken, CLIENT_ID, null, TARGET, BEARER_AUTHENTICATION_SCHEME.getName());
assertEquals(2, credentials.size());
}
use of com.microsoft.identity.common.internal.dto.AccessTokenRecord in project microsoft-authentication-library-common-for-android by AzureAD.
the class SharedPreferencesAccountCredentialCacheTest method getCredentialsNoHomeAccountIdNoRealmNoTarget.
@Test
public void getCredentialsNoHomeAccountIdNoRealmNoTarget() {
final RefreshTokenRecord refreshToken = new RefreshTokenRecord();
refreshToken.setSecret(SECRET);
refreshToken.setHomeAccountId("Foo");
refreshToken.setEnvironment(ENVIRONMENT);
refreshToken.setCredentialType(CredentialType.RefreshToken.name());
refreshToken.setClientId(CLIENT_ID);
refreshToken.setTarget(TARGET);
final AccessTokenRecord accessToken = new AccessTokenRecord();
accessToken.setCachedAt(CACHED_AT);
accessToken.setExpiresOn(EXPIRES_ON);
accessToken.setSecret(SECRET);
accessToken.setHomeAccountId("Bar");
accessToken.setRealm(REALM);
accessToken.setEnvironment(ENVIRONMENT);
accessToken.setCredentialType(CredentialType.AccessToken.name());
accessToken.setClientId(CLIENT_ID);
accessToken.setTarget(TARGET);
final AccessTokenRecord accessToken2 = new AccessTokenRecord();
accessToken2.setCachedAt(CACHED_AT);
accessToken2.setExpiresOn(EXPIRES_ON);
accessToken2.setSecret(SECRET);
accessToken2.setHomeAccountId("Baz");
accessToken2.setRealm(REALM);
accessToken2.setEnvironment(ENVIRONMENT);
accessToken2.setCredentialType(CredentialType.AccessToken.name());
accessToken2.setClientId(CLIENT_ID);
accessToken2.setTarget("qux");
// Save the Credentials
mSharedPreferencesAccountCredentialCache.saveCredential(refreshToken);
mSharedPreferencesAccountCredentialCache.saveCredential(accessToken);
mSharedPreferencesAccountCredentialCache.saveCredential(accessToken2);
List<Credential> credentials = mSharedPreferencesAccountCredentialCache.getCredentialsFilteredBy(null, ENVIRONMENT, CredentialType.AccessToken, CLIENT_ID, null, null, BEARER_AUTHENTICATION_SCHEME.getName());
assertEquals(2, credentials.size());
}
use of com.microsoft.identity.common.internal.dto.AccessTokenRecord in project microsoft-authentication-library-common-for-android by AzureAD.
the class SharedPreferencesAccountCredentialCacheTest method getCredentialsComplete.
@Test
public void getCredentialsComplete() {
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);
final AccessTokenRecord accessToken = new AccessTokenRecord();
accessToken.setCredentialType(CredentialType.AccessToken.name());
accessToken.setHomeAccountId(HOME_ACCOUNT_ID);
accessToken.setRealm(REALM);
accessToken.setEnvironment(ENVIRONMENT);
accessToken.setClientId(CLIENT_ID);
accessToken.setTarget(TARGET);
accessToken.setCachedAt(CACHED_AT);
accessToken.setExpiresOn(EXPIRES_ON);
accessToken.setSecret(SECRET);
// Save the Credentials
mSharedPreferencesAccountCredentialCache.saveCredential(refreshToken);
mSharedPreferencesAccountCredentialCache.saveCredential(accessToken);
List<Credential> credentials = mSharedPreferencesAccountCredentialCache.getCredentialsFilteredBy(HOME_ACCOUNT_ID, ENVIRONMENT, CredentialType.RefreshToken, CLIENT_ID, REALM, TARGET, BEARER_AUTHENTICATION_SCHEME.getName());
assertEquals(1, credentials.size());
final Credential retrievedCredential = credentials.get(0);
assertEquals(CredentialType.RefreshToken.name(), retrievedCredential.getCredentialType());
}
use of com.microsoft.identity.common.internal.dto.AccessTokenRecord in project microsoft-authentication-library-common-for-android by AzureAD.
the class SharedPreferencesAccountCredentialCacheTest method getCredentialsNoTarget.
@Test
public void getCredentialsNoTarget() {
final RefreshTokenRecord refreshToken = new RefreshTokenRecord();
refreshToken.setSecret(SECRET);
refreshToken.setHomeAccountId(HOME_ACCOUNT_ID);
refreshToken.setEnvironment(ENVIRONMENT);
refreshToken.setCredentialType(CredentialType.RefreshToken.name());
refreshToken.setClientId(CLIENT_ID);
refreshToken.setTarget(TARGET);
final AccessTokenRecord accessToken = new AccessTokenRecord();
accessToken.setCachedAt(CACHED_AT);
accessToken.setExpiresOn(EXPIRES_ON);
accessToken.setSecret(SECRET);
accessToken.setHomeAccountId(HOME_ACCOUNT_ID);
accessToken.setRealm(REALM);
accessToken.setEnvironment(ENVIRONMENT);
accessToken.setCredentialType(CredentialType.AccessToken.name());
accessToken.setClientId(CLIENT_ID);
accessToken.setTarget(TARGET);
final AccessTokenRecord accessToken2 = new AccessTokenRecord();
accessToken2.setCachedAt(CACHED_AT);
accessToken2.setExpiresOn(EXPIRES_ON);
accessToken2.setSecret(SECRET);
accessToken2.setHomeAccountId(HOME_ACCOUNT_ID);
accessToken2.setRealm(REALM);
accessToken2.setEnvironment(ENVIRONMENT);
accessToken2.setCredentialType(CredentialType.AccessToken.name());
accessToken2.setClientId(CLIENT_ID);
accessToken2.setTarget("qux");
// Save the Credentials
mSharedPreferencesAccountCredentialCache.saveCredential(refreshToken);
mSharedPreferencesAccountCredentialCache.saveCredential(accessToken);
mSharedPreferencesAccountCredentialCache.saveCredential(accessToken2);
List<Credential> credentials = mSharedPreferencesAccountCredentialCache.getCredentialsFilteredBy(HOME_ACCOUNT_ID, ENVIRONMENT, CredentialType.AccessToken, CLIENT_ID, REALM, null, BEARER_AUTHENTICATION_SCHEME.getName());
assertEquals(2, credentials.size());
}
use of com.microsoft.identity.common.internal.dto.AccessTokenRecord in project microsoft-authentication-library-common-for-android by AzureAD.
the class SharedPreferencesAccountCredentialCacheTest method saveCredentialNoHomeAccountIdNoRealmNoTarget.
@Test
public void saveCredentialNoHomeAccountIdNoRealmNoTarget() {
final AccessTokenRecord accessToken = new AccessTokenRecord();
accessToken.setCredentialType(CredentialType.AccessToken.name());
accessToken.setHomeAccountId(HOME_ACCOUNT_ID);
accessToken.setEnvironment(ENVIRONMENT);
accessToken.setClientId(CLIENT_ID);
accessToken.setCachedAt(CACHED_AT);
accessToken.setExpiresOn(EXPIRES_ON);
accessToken.setSecret(SECRET);
// Save the Credential
mSharedPreferencesAccountCredentialCache.saveCredential(accessToken);
// Synthesize a cache key for it
final String credentialCacheKey = mDelegate.generateCacheKey(accessToken);
// Resurrect the Credential
final Credential restoredAccessToken = mSharedPreferencesAccountCredentialCache.getCredential(credentialCacheKey);
assertTrue(accessToken.equals(restoredAccessToken));
}
Aggregations