use of com.okta.oidc.util.MockRequestCallback in project okta-oidc-android by okta.
the class SessionClientImplTest method authorizedRequestFailure.
@Test
public void authorizedRequestFailure() throws InterruptedException, JSONException {
mEndPoint.enqueueReturnInvalidClient();
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();
assertNull(cb.getResult());
assertNotNull(cb.getException());
}
use of com.okta.oidc.util.MockRequestCallback in project okta-oidc-android by okta.
the class SessionClientImplTest method getUserProfile.
@Test
public void getUserProfile() throws InterruptedException, JSONException {
mEndPoint.enqueueUserInfoSuccess();
final CountDownLatch latch = new CountDownLatch(1);
MockRequestCallback<UserInfo, AuthorizationException> cb = new MockRequestCallback<>(latch);
mSessionClient.getUserProfile(cb);
RecordedRequest recordedRequest = mEndPoint.takeRequest();
latch.await();
UserInfo result = cb.getResult();
assertThat(recordedRequest.getHeader("Authorization"), is("Bearer " + ACCESS_TOKEN));
assertThat(recordedRequest.getHeader("Accept"), is(ConnectionParameters.JSON_CONTENT_TYPE));
assertThat(recordedRequest.getPath(), equalTo("/userinfo"));
assertNotNull(result);
assertEquals("John Doe", result.get("name"));
assertEquals("Jimmy", result.get("nickname"));
}
use of com.okta.oidc.util.MockRequestCallback in project okta-oidc-android by okta.
the class SessionClientImplTest method revokeToken.
@Test
public void revokeToken() throws InterruptedException {
mEndPoint.enqueueReturnSuccessEmptyBody();
final CountDownLatch latch = new CountDownLatch(1);
MockRequestCallback<Boolean, AuthorizationException> cb = new MockRequestCallback<>(latch);
mSessionClient.revokeToken("access_token", cb);
RecordedRequest recordedRequest = mEndPoint.takeRequest();
latch.await();
assertNotNull(cb.getResult());
assertTrue(cb.getResult());
assertThat(recordedRequest.getPath(), equalTo("/revoke?client_id=CLIENT_ID&token=access_token"));
}
use of com.okta.oidc.util.MockRequestCallback in project okta-oidc-android by okta.
the class SessionClientImplTest method revokeTokenFailure.
@Test
public void revokeTokenFailure() throws InterruptedException {
mEndPoint.enqueueReturnInvalidClient();
final CountDownLatch latch = new CountDownLatch(1);
MockRequestCallback<Boolean, AuthorizationException> cb = new MockRequestCallback<>(latch);
mSessionClient.revokeToken("access_token", cb);
RecordedRequest recordedRequest = mEndPoint.takeRequest();
latch.await();
assertNull(cb.getResult());
assertNotNull(cb.getException());
assertEquals(TYPE_OAUTH_TOKEN_ERROR, cb.getException().type);
assertThat(recordedRequest.getPath(), equalTo("/revoke?client_id=CLIENT_ID&token=access_token"));
}
use of com.okta.oidc.util.MockRequestCallback in project okta-oidc-android by okta.
the class SessionClientImplTest method refreshTokenFailureInParallelCallbackCycle.
@Test
public void refreshTokenFailureInParallelCallbackCycle() throws InterruptedException {
final CountDownLatch latch = new CountDownLatch(1);
String nonce = CodeVerifierUtil.generateRandomState();
String jws = TestValues.getJwt(mEndPoint.getUrl(), nonce, mConfig.getClientId());
mEndPoint.enqueueTokenSuccess(jws);
MockRequestCallback<Tokens, AuthorizationException> errorCb = new MockRequestCallback<>(latch);
RequestCallback<Tokens, AuthorizationException> cb = new RequestCallback<Tokens, AuthorizationException>() {
@Override
public void onSuccess(@NonNull Tokens result) {
try {
mSessionClient.refreshToken(errorCb);
} catch (RuntimeException runtimeException) {
assertEquals(runtimeException.getMessage(), "refreshToken can't be called from callback.");
latch.countDown();
}
}
@Override
public void onError(String error, AuthorizationException exception) {
fail();
}
};
mSessionClient.refreshToken(cb);
latch.await();
}
Aggregations