Search in sources :

Example 21 with RefreshTokenRecord

use of com.microsoft.identity.common.internal.dto.RefreshTokenRecord 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());
}
Also used : Credential(com.microsoft.identity.common.internal.dto.Credential) PrimaryRefreshTokenRecord(com.microsoft.identity.common.internal.dto.PrimaryRefreshTokenRecord) RefreshTokenRecord(com.microsoft.identity.common.internal.dto.RefreshTokenRecord) AccessTokenRecord(com.microsoft.identity.common.internal.dto.AccessTokenRecord) Test(org.junit.Test)

Example 22 with RefreshTokenRecord

use of com.microsoft.identity.common.internal.dto.RefreshTokenRecord in project microsoft-authentication-library-common-for-android by AzureAD.

the class SharedPreferencesAccountCredentialCacheTest method saveCredentialNoTarget.

@Test
public void saveCredentialNoTarget() {
    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);
    // Save the Credential
    mSharedPreferencesAccountCredentialCache.saveCredential(refreshToken);
    // Synthesize a cache key for it
    final String credentialCacheKey = mDelegate.generateCacheKey(refreshToken);
    // Resurrect the Credential
    final Credential restoredRefreshToken = mSharedPreferencesAccountCredentialCache.getCredential(credentialCacheKey);
    assertTrue(refreshToken.equals(restoredRefreshToken));
}
Also used : Credential(com.microsoft.identity.common.internal.dto.Credential) PrimaryRefreshTokenRecord(com.microsoft.identity.common.internal.dto.PrimaryRefreshTokenRecord) RefreshTokenRecord(com.microsoft.identity.common.internal.dto.RefreshTokenRecord) Test(org.junit.Test)

Example 23 with RefreshTokenRecord

use of com.microsoft.identity.common.internal.dto.RefreshTokenRecord in project microsoft-authentication-library-common-for-android by AzureAD.

the class SharedPreferencesAccountCredentialCacheTest method saveCredentialWithEscapeChars.

@Test
public void saveCredentialWithEscapeChars() {
    final RefreshTokenRecord refreshToken = new RefreshTokenRecord();
    refreshToken.setCredentialType(wrapInEscapeSequenceChars(CredentialType.RefreshToken.name()));
    refreshToken.setEnvironment(wrapInEscapeSequenceChars(ENVIRONMENT));
    refreshToken.setHomeAccountId(wrapInEscapeSequenceChars(HOME_ACCOUNT_ID));
    refreshToken.setClientId(wrapInEscapeSequenceChars(CLIENT_ID));
    refreshToken.setSecret(wrapInEscapeSequenceChars(SECRET));
    refreshToken.setTarget(wrapInEscapeSequenceChars(TARGET));
    // Save the Credential
    mSharedPreferencesAccountCredentialCache.saveCredential(refreshToken);
    // Synthesize a cache key for it
    final String credentialCacheKey = mDelegate.generateCacheKey(refreshToken);
    // Resurrect the Credential
    final Credential restoredRefreshToken = mSharedPreferencesAccountCredentialCache.getCredential(credentialCacheKey);
    assertTrue(refreshToken.equals(restoredRefreshToken));
}
Also used : Credential(com.microsoft.identity.common.internal.dto.Credential) PrimaryRefreshTokenRecord(com.microsoft.identity.common.internal.dto.PrimaryRefreshTokenRecord) RefreshTokenRecord(com.microsoft.identity.common.internal.dto.RefreshTokenRecord) Test(org.junit.Test)

Example 24 with RefreshTokenRecord

use of com.microsoft.identity.common.internal.dto.RefreshTokenRecord in project microsoft-authentication-library-common-for-android by AzureAD.

the class SharedPreferencesAccountCredentialCacheTest method saveCredential.

@Test
public void saveCredential() {
    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);
    // Save the Credential
    mSharedPreferencesAccountCredentialCache.saveCredential(refreshToken);
    // Synthesize a cache key for it
    final String credentialCacheKey = mDelegate.generateCacheKey(refreshToken);
    // Resurrect the Credential
    final Credential restoredRefreshToken = mSharedPreferencesAccountCredentialCache.getCredential(credentialCacheKey);
    assertTrue(refreshToken.equals(restoredRefreshToken));
}
Also used : Credential(com.microsoft.identity.common.internal.dto.Credential) PrimaryRefreshTokenRecord(com.microsoft.identity.common.internal.dto.PrimaryRefreshTokenRecord) RefreshTokenRecord(com.microsoft.identity.common.internal.dto.RefreshTokenRecord) Test(org.junit.Test)

Example 25 with RefreshTokenRecord

use of com.microsoft.identity.common.internal.dto.RefreshTokenRecord in project microsoft-authentication-library-common-for-android by AzureAD.

the class SharedPreferencesAccountCredentialCacheTest method getCredentialsNoHomeAccountIdNoTarget.

@Test
public void getCredentialsNoHomeAccountIdNoTarget() {
    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.setCachedAt(CACHED_AT);
    accessToken.setExpiresOn(EXPIRES_ON);
    accessToken.setSecret(SECRET);
    accessToken.setHomeAccountId("Quz");
    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(TARGET);
    // Save the Credentials
    mSharedPreferencesAccountCredentialCache.saveCredential(refreshToken);
    mSharedPreferencesAccountCredentialCache.saveCredential(accessToken);
    mSharedPreferencesAccountCredentialCache.saveCredential(accessToken2);
    List<Credential> credentials = mSharedPreferencesAccountCredentialCache.getCredentialsFilteredBy(null, ENVIRONMENT, CredentialType.AccessToken, CLIENT_ID, REALM, null, BEARER_AUTHENTICATION_SCHEME.getName());
    assertEquals(2, credentials.size());
}
Also used : Credential(com.microsoft.identity.common.internal.dto.Credential) PrimaryRefreshTokenRecord(com.microsoft.identity.common.internal.dto.PrimaryRefreshTokenRecord) RefreshTokenRecord(com.microsoft.identity.common.internal.dto.RefreshTokenRecord) AccessTokenRecord(com.microsoft.identity.common.internal.dto.AccessTokenRecord) Test(org.junit.Test)

Aggregations

RefreshTokenRecord (com.microsoft.identity.common.internal.dto.RefreshTokenRecord)63 PrimaryRefreshTokenRecord (com.microsoft.identity.common.internal.dto.PrimaryRefreshTokenRecord)51 Test (org.junit.Test)51 Credential (com.microsoft.identity.common.internal.dto.Credential)32 AccessTokenRecord (com.microsoft.identity.common.internal.dto.AccessTokenRecord)29 AccountRecord (com.microsoft.identity.common.internal.dto.AccountRecord)10 IdTokenRecord (com.microsoft.identity.common.internal.dto.IdTokenRecord)9 JsonElement (com.google.gson.JsonElement)4 JsonPrimitive (com.google.gson.JsonPrimitive)4 HashMap (java.util.HashMap)4 ICacheRecord (com.microsoft.identity.common.internal.cache.ICacheRecord)3 JSONObject (org.json.JSONObject)3 Nullable (androidx.annotation.Nullable)2 ClientException (com.microsoft.identity.common.exception.ClientException)2 ClientInfo (com.microsoft.identity.common.internal.providers.microsoft.azureactivedirectory.ClientInfo)2 CacheEndEvent (com.microsoft.identity.common.internal.telemetry.events.CacheEndEvent)2 JSONArray (org.json.JSONArray)2 JsonArray (com.google.gson.JsonArray)1 JsonObject (com.google.gson.JsonObject)1 StorageHelper (com.microsoft.identity.common.adal.internal.cache.StorageHelper)1