Search in sources :

Example 56 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 accessTokenCreateCacheValue.

@Test
public void accessTokenCreateCacheValue() 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);
    final String serializedValue = mDelegate.generateCacheValue(accessToken);
    // Turn the serialized value into a JSONObject and start testing field equality.
    final JSONObject jsonObject = new JSONObject(serializedValue);
    assertEquals(HOME_ACCOUNT_ID, jsonObject.getString(Credential.SerializedNames.HOME_ACCOUNT_ID));
    assertEquals(ENVIRONMENT, jsonObject.getString(Credential.SerializedNames.ENVIRONMENT));
    assertEquals(CredentialType.AccessToken.name().toLowerCase(Locale.US), jsonObject.getString("credential_type"));
    assertEquals(CLIENT_ID, jsonObject.getString(Credential.SerializedNames.CLIENT_ID));
    assertEquals(REALM, jsonObject.getString(AccessTokenRecord.SerializedNames.REALM));
    assertEquals(TARGET, jsonObject.getString(AccessTokenRecord.SerializedNames.TARGET));
}
Also used : JSONObject(org.json.JSONObject) AccessTokenRecord(com.microsoft.identity.common.internal.dto.AccessTokenRecord) Test(org.junit.Test)

Example 57 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 testAccessTokenTypeProperty.

@Test
public void testAccessTokenTypeProperty() {
    // Test to verify that "token_type" is correctly serialized into token_type property
    final String authScheme = "Bearer";
    final String jsonStr = "{\"token_type\": \"" + authScheme + "\"}";
    final AccessTokenRecord record = mDelegate.fromCacheValue(jsonStr, AccessTokenRecord.class);
    assertEquals(authScheme, record.getAccessTokenType());
}
Also used : AccessTokenRecord(com.microsoft.identity.common.internal.dto.AccessTokenRecord) Test(org.junit.Test)

Example 58 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 accessTokenCreateCacheKeyNoTarget.

@Test
public void accessTokenCreateCacheKeyNoTarget() {
    final AccessTokenRecord accessToken = new AccessTokenRecord();
    accessToken.setHomeAccountId(HOME_ACCOUNT_ID);
    accessToken.setEnvironment(ENVIRONMENT);
    accessToken.setCredentialType(CredentialType.AccessToken.name());
    accessToken.setClientId(CLIENT_ID);
    accessToken.setRealm(REALM);
    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 + REALM + CACHE_VALUE_SEPARATOR;
    assertEquals(expectedKey, mDelegate.generateCacheKey(accessToken));
}
Also used : AccessTokenRecord(com.microsoft.identity.common.internal.dto.AccessTokenRecord) Test(org.junit.Test)

Example 59 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 accessTokenCreateCacheKeyNoRealm.

@Test
public void accessTokenCreateCacheKeyNoRealm() {
    final AccessTokenRecord accessToken = new AccessTokenRecord();
    accessToken.setHomeAccountId(HOME_ACCOUNT_ID);
    accessToken.setEnvironment(ENVIRONMENT);
    accessToken.setCredentialType(CredentialType.AccessToken.name());
    accessToken.setClientId(CLIENT_ID);
    accessToken.setTarget(TARGET);
    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 + TARGET;
    assertEquals(expectedKey, mDelegate.generateCacheKey(accessToken));
}
Also used : AccessTokenRecord(com.microsoft.identity.common.internal.dto.AccessTokenRecord) Test(org.junit.Test)

Example 60 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 testAccessTokenTypePropertyRename.

@Test
public void testAccessTokenTypePropertyRename() {
    // Test to verify that "access_token_type" is correctly serialized into token_type property
    final String authScheme = "Bearer";
    final String jsonStr = "{\"access_token_type\": \"" + authScheme + "\"}";
    final AccessTokenRecord record = mDelegate.fromCacheValue(jsonStr, AccessTokenRecord.class);
    assertEquals(authScheme, record.getAccessTokenType());
}
Also used : 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