Search in sources :

Example 1 with AccessTokenRecord

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

the class CacheKeyValueDelegateTest method accessTokenCreateCacheKeyNoRealmNoTarget.

@Test
public void accessTokenCreateCacheKeyNoRealmNoTarget() {
    final AccessTokenRecord accessToken = new AccessTokenRecord();
    accessToken.setHomeAccountId(HOME_ACCOUNT_ID);
    accessToken.setEnvironment(ENVIRONMENT);
    accessToken.setCredentialType(CredentialType.AccessToken.name());
    accessToken.setClientId(CLIENT_ID);
    final String expectedKey = // just for formatting
    "" + HOME_ACCOUNT_ID + CACHE_VALUE_SEPARATOR + ENVIRONMENT + CACHE_VALUE_SEPARATOR + CREDENTIAL_TYPE_ACCESS_TOKEN + CACHE_VALUE_SEPARATOR + CLIENT_ID + CACHE_VALUE_SEPARATOR + CACHE_VALUE_SEPARATOR;
    assertEquals(expectedKey, mDelegate.generateCacheKey(accessToken));
}
Also used : AccessTokenRecord(com.microsoft.identity.common.internal.dto.AccessTokenRecord) Test(org.junit.Test)

Example 2 with AccessTokenRecord

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

the class CacheKeyValueDelegateTest method accessTokenCreateCacheKeyNoHomeAccountIdNoRealmNoTarget.

@Test
public void accessTokenCreateCacheKeyNoHomeAccountIdNoRealmNoTarget() {
    final AccessTokenRecord accessToken = new AccessTokenRecord();
    accessToken.setEnvironment(ENVIRONMENT);
    accessToken.setCredentialType(CredentialType.AccessToken.name());
    accessToken.setClientId(CLIENT_ID);
    final String expectedKey = // just for formatting
    "" + CACHE_VALUE_SEPARATOR + ENVIRONMENT + CACHE_VALUE_SEPARATOR + CREDENTIAL_TYPE_ACCESS_TOKEN + CACHE_VALUE_SEPARATOR + CLIENT_ID + CACHE_VALUE_SEPARATOR + CACHE_VALUE_SEPARATOR;
    assertEquals(expectedKey, mDelegate.generateCacheKey(accessToken));
}
Also used : AccessTokenRecord(com.microsoft.identity.common.internal.dto.AccessTokenRecord) Test(org.junit.Test)

Example 3 with AccessTokenRecord

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

the class AccessTokenTest method testExpiry.

@Test
public void testExpiry() {
    final AccessTokenRecord accessToken = new AccessTokenRecord();
    accessToken.setExpiresOn(getCurrentTimeStr());
    assertTrue(accessToken.isExpired());
}
Also used : AccessTokenRecord(com.microsoft.identity.common.internal.dto.AccessTokenRecord) Test(org.junit.Test)

Example 4 with AccessTokenRecord

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

the class CacheKeyValueDelegateTest method accessTokenCreateCacheKeyNoHomeAccountId.

@Test
public void accessTokenCreateCacheKeyNoHomeAccountId() {
    final AccessTokenRecord accessToken = new AccessTokenRecord();
    accessToken.setEnvironment(ENVIRONMENT);
    accessToken.setCredentialType(CredentialType.AccessToken.name());
    accessToken.setClientId(CLIENT_ID);
    accessToken.setRealm(REALM);
    accessToken.setTarget(TARGET);
    final String expectedKey = // just for formatting
    "" + CACHE_VALUE_SEPARATOR + ENVIRONMENT + CACHE_VALUE_SEPARATOR + CREDENTIAL_TYPE_ACCESS_TOKEN + CACHE_VALUE_SEPARATOR + CLIENT_ID + CACHE_VALUE_SEPARATOR + REALM + CACHE_VALUE_SEPARATOR + TARGET;
    assertEquals(expectedKey, mDelegate.generateCacheKey(accessToken));
}
Also used : AccessTokenRecord(com.microsoft.identity.common.internal.dto.AccessTokenRecord) Test(org.junit.Test)

Example 5 with AccessTokenRecord

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

the class CacheKeyValueDelegateTest method accessTokenExtraValueDeserialization.

@Test
public void accessTokenExtraValueDeserialization() throws JSONException {
    final AccessTokenRecord accessToken = new AccessTokenRecord();
    accessToken.setHomeAccountId(HOME_ACCOUNT_ID);
    accessToken.setEnvironment(ENVIRONMENT);
    accessToken.setCredentialType(CredentialType.AccessToken.name().toLowerCase(Locale.US));
    accessToken.setClientId(CLIENT_ID);
    accessToken.setRealm(REALM);
    accessToken.setTarget(TARGET);
    String serializedValue = mDelegate.generateCacheValue(accessToken);
    // Turn the serialized value into a JSONObject and start testing field equality.
    final JSONObject jsonObject = new JSONObject(serializedValue);
    // Add more non-standard data to this object...
    final JSONArray numbers = new JSONArray("[1, 2, 3]");
    final JSONArray objects = new JSONArray("[{\"hello\" : \"hallo\"}, {\"goodbye\" : \"auf wiedersehen\"}]");
    jsonObject.put("foo", "bar");
    jsonObject.put("numbers", numbers);
    jsonObject.put("objects", objects);
    serializedValue = jsonObject.toString();
    final AccessTokenRecord deserializedValue = mDelegate.fromCacheValue(serializedValue, AccessTokenRecord.class);
    assertNotNull(deserializedValue);
    assertNull(deserializedValue.getAdditionalFields().get(Credential.SerializedNames.ENVIRONMENT));
    assertEquals(HOME_ACCOUNT_ID, deserializedValue.getHomeAccountId());
    assertEquals(ENVIRONMENT, deserializedValue.getEnvironment());
    assertEquals(CredentialType.AccessToken.name().toLowerCase(Locale.US), deserializedValue.getCredentialType());
    assertEquals(CLIENT_ID, deserializedValue.getClientId());
    assertEquals(REALM, deserializedValue.getRealm());
    assertEquals(TARGET, deserializedValue.getTarget());
    assertEquals(3, deserializedValue.getAdditionalFields().size());
    assertEquals("bar", deserializedValue.getAdditionalFields().get("foo").getAsString());
    assertEquals(numbers.toString(), deserializedValue.getAdditionalFields().get("numbers").toString());
}
Also used : JSONObject(org.json.JSONObject) JSONArray(org.json.JSONArray) AccessTokenRecord(com.microsoft.identity.common.internal.dto.AccessTokenRecord) Test(org.junit.Test)

Aggregations

AccessTokenRecord (com.microsoft.identity.common.internal.dto.AccessTokenRecord)60 Test (org.junit.Test)52 Credential (com.microsoft.identity.common.internal.dto.Credential)29 RefreshTokenRecord (com.microsoft.identity.common.internal.dto.RefreshTokenRecord)29 PrimaryRefreshTokenRecord (com.microsoft.identity.common.internal.dto.PrimaryRefreshTokenRecord)25 AccountRecord (com.microsoft.identity.common.internal.dto.AccountRecord)11 IdTokenRecord (com.microsoft.identity.common.internal.dto.IdTokenRecord)9 JsonElement (com.google.gson.JsonElement)3 JsonPrimitive (com.google.gson.JsonPrimitive)3 HashMap (java.util.HashMap)3 JSONObject (org.json.JSONObject)3 ICacheRecord (com.microsoft.identity.common.internal.cache.ICacheRecord)2 ArrayList (java.util.ArrayList)2 JSONArray (org.json.JSONArray)2 Bundle (android.os.Bundle)1 NonNull (androidx.annotation.NonNull)1 JsonArray (com.google.gson.JsonArray)1 JsonObject (com.google.gson.JsonObject)1 ClientException (com.microsoft.identity.common.exception.ClientException)1 ServiceException (com.microsoft.identity.common.exception.ServiceException)1