use of com.okta.oidc.util.MockRequestCallback in project okta-oidc-android by okta.
the class SyncAuthClientTest method signInNativeCancel.
@Test
public void signInNativeCancel() throws AuthorizationException, InterruptedException {
String nonce = CodeVerifierUtil.generateRandomState();
String state = CodeVerifierUtil.generateRandomState();
String jws = TestValues.getJwt(mEndPoint.getUrl(), nonce, mConfig.getClientId());
AuthenticationPayload payload = new AuthenticationPayload.Builder().addParameter("nonce", nonce).setState(state).build();
mEndPoint.enqueueNativeRequestSuccess(state, 5);
mEndPoint.enqueueTokenSuccess(jws);
CountDownLatch latch = new CountDownLatch(1);
MockRequestCallback<Result, AuthorizationException> mockCallback = new MockRequestCallback<>(latch);
mAuthClient.signIn(SESSION_TOKEN, payload, mockCallback);
// wait for request to be created
Thread.sleep(200);
mAuthClient.cancel();
latch.await();
assertNull(mockCallback.getResult());
assertNotNull(mockCallback.getException());
String errorMessage = mockCallback.getException().getMessage();
// Socket closed or canceled or stream is closed or network error.
if (errorMessage == null) {
assertTrue(mockCallback.getException().getCause() instanceof InterruptedException);
} else {
assertTrue("Socket closed".equals(errorMessage) || "Canceled".equals(errorMessage) || "stream is closed".equals(errorMessage) || "Network error".equals(errorMessage) || "interrupted".equals(errorMessage));
}
}
use of com.okta.oidc.util.MockRequestCallback in project okta-oidc-android by okta.
the class SessionClientImplTest method authorizedRequestCancel.
@Test
public void authorizedRequestCancel() throws InterruptedException, JSONException {
mEndPoint.enqueueUserInfoSuccess(5);
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);
// wait for request to be created
Thread.sleep(200);
mSessionClient.cancel();
latch.await();
assertNull(cb.getResult());
assertNotNull(cb.getException());
String errorMessage = cb.getException().getMessage();
// Socket closed or canceled or stream is closed or network error.
if (errorMessage == null) {
assertTrue(cb.getException().getCause() instanceof InterruptedException);
} else {
assertTrue("Socket closed".equals(errorMessage) || "Canceled".equals(errorMessage) || "stream is closed".equals(errorMessage) || "Network error".equals(errorMessage) || "interrupted".equals(errorMessage));
}
}
use of com.okta.oidc.util.MockRequestCallback in project okta-oidc-android by okta.
the class SessionClientImplTest method refreshToken.
@Test
public void refreshToken() 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> cb = new MockRequestCallback<>(latch);
mSessionClient.refreshToken(cb);
latch.await();
Tokens result = cb.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());
}
use of com.okta.oidc.util.MockRequestCallback in project okta-oidc-android by okta.
the class SessionClientImplTest method getUserProfileFailure.
@Test
public void getUserProfileFailure() throws InterruptedException, JSONException {
mEndPoint.enqueueReturnUnauthorizedRevoked();
final CountDownLatch latch = new CountDownLatch(1);
MockRequestCallback<UserInfo, AuthorizationException> cb = new MockRequestCallback<>(latch);
mSessionClient.getUserProfile(cb);
RecordedRequest recordedRequest = mEndPoint.takeRequest();
latch.await();
assertNull(cb.getResult());
assertNotNull(cb.getException());
assertThat(recordedRequest.getPath(), equalTo("/userinfo"));
assertEquals(TYPE_GENERAL_ERROR, cb.getException().type);
}
use of com.okta.oidc.util.MockRequestCallback in project okta-oidc-android by okta.
the class SessionClientImplTest method introspectToken.
@Test
public void introspectToken() throws InterruptedException {
mEndPoint.enqueueIntrospectSuccess();
final CountDownLatch latch = new CountDownLatch(1);
MockRequestCallback<IntrospectInfo, AuthorizationException> cb = new MockRequestCallback<>(latch);
mSessionClient.introspectToken(ACCESS_TOKEN, TokenTypeHint.ACCESS_TOKEN, cb);
latch.await();
assertNotNull(cb.getResult());
assertTrue(cb.getResult().isActive());
}
Aggregations