Search in sources :

Example 1 with RefreshTokenRecord

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

the class CacheKeyValueDelegateTest method refreshTokenCreateCacheKeyNoRealm.

@Test
public void refreshTokenCreateCacheKeyNoRealm() {
    final RefreshTokenRecord refreshToken = new RefreshTokenRecord();
    refreshToken.setHomeAccountId(HOME_ACCOUNT_ID);
    refreshToken.setEnvironment(ENVIRONMENT);
    refreshToken.setCredentialType(CredentialType.RefreshToken.name());
    refreshToken.setClientId(CLIENT_ID);
    refreshToken.setTarget(TARGET);
    final String expectedKey = // just for formatting
    "" + HOME_ACCOUNT_ID + CACHE_VALUE_SEPARATOR + ENVIRONMENT + CACHE_VALUE_SEPARATOR + CREDENTIAL_TYPE_REFRESH_TOKEN + CACHE_VALUE_SEPARATOR + CLIENT_ID + CACHE_VALUE_SEPARATOR + CACHE_VALUE_SEPARATOR + TARGET;
    assertEquals(expectedKey, mDelegate.generateCacheKey(refreshToken));
}
Also used : PrimaryRefreshTokenRecord(com.microsoft.identity.common.internal.dto.PrimaryRefreshTokenRecord) RefreshTokenRecord(com.microsoft.identity.common.internal.dto.RefreshTokenRecord) Test(org.junit.Test)

Example 2 with RefreshTokenRecord

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

the class CacheKeyValueDelegateTest method refreshTokenCreateCacheValue.

@Test
public void refreshTokenCreateCacheValue() throws JSONException {
    final RefreshTokenRecord refreshToken = new RefreshTokenRecord();
    refreshToken.setHomeAccountId(HOME_ACCOUNT_ID);
    refreshToken.setEnvironment(ENVIRONMENT);
    refreshToken.setCredentialType(CredentialType.RefreshToken.name().toLowerCase(Locale.US));
    refreshToken.setClientId(CLIENT_ID);
    refreshToken.setTarget(TARGET);
    final String serializedValue = mDelegate.generateCacheValue(refreshToken);
    // Turn the serialized value into a JSONObject and start testing field equality.
    final JSONObject jsonObject = new JSONObject(serializedValue);
    assertEquals(HOME_ACCOUNT_ID, jsonObject.getString(RefreshTokenRecord.SerializedNames.HOME_ACCOUNT_ID));
    assertEquals(ENVIRONMENT, jsonObject.getString(RefreshTokenRecord.SerializedNames.ENVIRONMENT));
    assertEquals(CredentialType.RefreshToken.name().toLowerCase(Locale.US), jsonObject.getString("credential_type"));
    assertEquals(CLIENT_ID, jsonObject.getString(RefreshTokenRecord.SerializedNames.CLIENT_ID));
    assertEquals(TARGET, jsonObject.getString(RefreshTokenRecord.SerializedNames.TARGET));
}
Also used : JSONObject(org.json.JSONObject) PrimaryRefreshTokenRecord(com.microsoft.identity.common.internal.dto.PrimaryRefreshTokenRecord) RefreshTokenRecord(com.microsoft.identity.common.internal.dto.RefreshTokenRecord) Test(org.junit.Test)

Example 3 with RefreshTokenRecord

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

the class CacheKeyValueDelegateTest method refreshTokenCreateCacheKeyCompleteWithFociPrefixedAlternate.

@Test
public void refreshTokenCreateCacheKeyCompleteWithFociPrefixedAlternate() {
    final RefreshTokenRecord refreshToken = new RefreshTokenRecord();
    refreshToken.setHomeAccountId(HOME_ACCOUNT_ID);
    refreshToken.setEnvironment(ENVIRONMENT);
    refreshToken.setCredentialType(CredentialType.RefreshToken.name());
    refreshToken.setClientId(CLIENT_ID);
    refreshToken.setFamilyId("foci-2");
    refreshToken.setTarget(TARGET);
    final String expectedKey = // just for formatting
    "" + HOME_ACCOUNT_ID + CACHE_VALUE_SEPARATOR + ENVIRONMENT + CACHE_VALUE_SEPARATOR + CREDENTIAL_TYPE_REFRESH_TOKEN + CACHE_VALUE_SEPARATOR + "2" + CACHE_VALUE_SEPARATOR + CACHE_VALUE_SEPARATOR + TARGET;
    assertEquals(expectedKey, mDelegate.generateCacheKey(refreshToken));
}
Also used : PrimaryRefreshTokenRecord(com.microsoft.identity.common.internal.dto.PrimaryRefreshTokenRecord) RefreshTokenRecord(com.microsoft.identity.common.internal.dto.RefreshTokenRecord) Test(org.junit.Test)

Example 4 with RefreshTokenRecord

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

the class CacheKeyValueDelegateTest method refreshTokenCreateCacheKeyCompleteWithFociPrefixed.

@Test
public void refreshTokenCreateCacheKeyCompleteWithFociPrefixed() {
    final RefreshTokenRecord refreshToken = new RefreshTokenRecord();
    refreshToken.setHomeAccountId(HOME_ACCOUNT_ID);
    refreshToken.setEnvironment(ENVIRONMENT);
    refreshToken.setCredentialType(CredentialType.RefreshToken.name());
    refreshToken.setClientId(CLIENT_ID);
    refreshToken.setFamilyId("foci-1");
    refreshToken.setTarget(TARGET);
    final String expectedKey = // just for formatting
    "" + HOME_ACCOUNT_ID + CACHE_VALUE_SEPARATOR + ENVIRONMENT + CACHE_VALUE_SEPARATOR + CREDENTIAL_TYPE_REFRESH_TOKEN + CACHE_VALUE_SEPARATOR + "1" + CACHE_VALUE_SEPARATOR + CACHE_VALUE_SEPARATOR + TARGET;
    assertEquals(expectedKey, mDelegate.generateCacheKey(refreshToken));
}
Also used : PrimaryRefreshTokenRecord(com.microsoft.identity.common.internal.dto.PrimaryRefreshTokenRecord) RefreshTokenRecord(com.microsoft.identity.common.internal.dto.RefreshTokenRecord) Test(org.junit.Test)

Example 5 with RefreshTokenRecord

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

the class CacheKeyValueDelegateTest method refreshTokenCreateCacheKeyNoTarget.

@Test
public void refreshTokenCreateCacheKeyNoTarget() {
    final RefreshTokenRecord refreshToken = new RefreshTokenRecord();
    refreshToken.setHomeAccountId(HOME_ACCOUNT_ID);
    refreshToken.setEnvironment(ENVIRONMENT);
    refreshToken.setCredentialType(CredentialType.RefreshToken.name());
    refreshToken.setClientId(CLIENT_ID);
    final String expectedKey = // just for formatting
    "" + HOME_ACCOUNT_ID + CACHE_VALUE_SEPARATOR + ENVIRONMENT + CACHE_VALUE_SEPARATOR + CREDENTIAL_TYPE_REFRESH_TOKEN + CACHE_VALUE_SEPARATOR + CLIENT_ID + CACHE_VALUE_SEPARATOR + CACHE_VALUE_SEPARATOR;
    assertEquals(expectedKey, mDelegate.generateCacheKey(refreshToken));
}
Also used : PrimaryRefreshTokenRecord(com.microsoft.identity.common.internal.dto.PrimaryRefreshTokenRecord) RefreshTokenRecord(com.microsoft.identity.common.internal.dto.RefreshTokenRecord) 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