use of com.okta.oidc.util.MockRequestCallback in project okta-oidc-android by okta.
the class SessionClientImplTest method refreshTokenInParallel.
@Test
public void refreshTokenInParallel() throws InterruptedException {
final CountDownLatch latch = new CountDownLatch(2);
String nonce = CodeVerifierUtil.generateRandomState();
String jws = TestValues.getJwt(mEndPoint.getUrl(), nonce, mConfig.getClientId());
mEndPoint.enqueueTokenSuccess(jws);
MockRequestCallback<Tokens, AuthorizationException> cb = new MockRequestCallback<>(latch);
MockRequestCallback<Tokens, AuthorizationException> cb2 = new MockRequestCallback<>(latch);
new Thread(() -> mSessionClient.refreshToken(cb)).start();
new Thread(() -> mSessionClient.refreshToken(cb2)).start();
latch.await();
Tokens result = cb.getResult();
Tokens result2 = cb2.getResult();
TokenResponse original = mGson.fromJson(String.format(TOKEN_SUCCESS, jws), TokenResponse.class);
assertEquals(original.getIdToken(), result.getIdToken());
assertEquals(original.getRefreshToken(), result.getRefreshToken());
assertEquals(original.getIdToken(), result.getIdToken());
assertEquals(result, result2);
}
use of com.okta.oidc.util.MockRequestCallback in project okta-oidc-android by okta.
the class SessionClientImplTest method refreshTokenFailure.
@Test
public void refreshTokenFailure() throws InterruptedException {
final CountDownLatch latch = new CountDownLatch(1);
mEndPoint.enqueueReturnInvalidClient();
MockRequestCallback<Tokens, AuthorizationException> cb = new MockRequestCallback<>(latch);
mSessionClient.refreshToken(cb);
latch.await();
assertNull(cb.getResult());
assertNotNull(cb.getException());
assertEquals(cb.getException().getMessage(), "No client credentials found.");
assertEquals(cb.getException().type, TYPE_OAUTH_TOKEN_ERROR);
}
use of com.okta.oidc.util.MockRequestCallback in project okta-oidc-android by okta.
the class SessionClientImplTest method authorizedRequest.
@Test
public void authorizedRequest() throws InterruptedException, JSONException {
mEndPoint.enqueueUserInfoSuccess();
Uri uri = Uri.parse(mProviderConfig.userinfo_endpoint);
HashMap<String, String> properties = new HashMap<>();
properties.put("state", CUSTOM_STATE);
final CountDownLatch latch = new CountDownLatch(1);
MockRequestCallback<JSONObject, AuthorizationException> cb = new MockRequestCallback<>(latch);
mSessionClient.authorizedRequest(uri, properties, null, ConnectionParameters.RequestMethod.GET, cb);
latch.await();
RecordedRequest recordedRequest = mEndPoint.takeRequest();
assertNotNull(cb.getResult());
JSONObject result = cb.getResult();
assertThat(recordedRequest.getHeader("state"), is(CUSTOM_STATE));
assertNull(cb.getException());
assertEquals("John Doe", result.getString("name"));
assertEquals("Jimmy", result.getString("nickname"));
}
use of com.okta.oidc.util.MockRequestCallback in project okta-oidc-android by okta.
the class SessionClientImplTest method introspectTokenFailure.
@Test
public void introspectTokenFailure() throws InterruptedException {
mEndPoint.enqueueReturnInvalidClient();
final CountDownLatch latch = new CountDownLatch(1);
MockRequestCallback<IntrospectInfo, AuthorizationException> cb = new MockRequestCallback<>(latch);
mSessionClient.introspectToken(ACCESS_TOKEN, TokenTypeHint.ACCESS_TOKEN, cb);
latch.await();
assertNull(cb.getResult());
assertNotNull(cb.getException());
}
use of com.okta.oidc.util.MockRequestCallback in project okta-oidc-android by okta.
the class SessionClientImplTest method requestsAreRunInSerial.
@Test
public void requestsAreRunInSerial() throws InterruptedException {
final CountDownLatch latch = new CountDownLatch(2);
MockRequestCallback<UserInfo, AuthorizationException> userProfileCallback = new MockRequestCallback<>(latch);
mEndPoint.enqueueUserInfoSuccess();
mSessionClient.getUserProfile(userProfileCallback);
String nonce = CodeVerifierUtil.generateRandomState();
String jws = TestValues.getJwt(mEndPoint.getUrl(), nonce, mConfig.getClientId());
mEndPoint.enqueueTokenSuccess(jws);
MockRequestCallback<Tokens, AuthorizationException> refreshCallback = new MockRequestCallback<>(latch);
mSessionClient.refreshToken(refreshCallback);
latch.await();
UserInfo userInfoResult = userProfileCallback.getResult();
assertNotNull(userInfoResult);
assertEquals("John Doe", userInfoResult.get("name"));
assertEquals("Jimmy", userInfoResult.get("nickname"));
Tokens result = refreshCallback.getResult();
TokenResponse original = mGson.fromJson(String.format(TOKEN_SUCCESS, jws), TokenResponse.class);
assertEquals(original.getIdToken(), result.getIdToken());
assertEquals(original.getRefreshToken(), result.getRefreshToken());
assertEquals(original.getIdToken(), result.getIdToken());
}
Aggregations