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));
}
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));
}
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());
}
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));
}
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());
}
Aggregations