use of com.okta.oidc.AuthenticationResultHandler.StateResult in project okta-oidc-android by okta.
the class AuthenticationResultHandlerTest method onActivityResultException.
@Test
public void onActivityResultException() throws InterruptedException {
Intent intent = new Intent();
intent.putExtra(EXTRA_EXCEPTION, TestValues.getAuthorizationExceptionError());
CountDownLatch latch = new CountDownLatch(1);
final StateResult[] stateResult = new StateResult[1];
final ResultType[] stateType = new ResultType[1];
AuthenticationResultHandler.handler().setAuthenticationListener((result, type) -> {
stateResult[0] = result;
stateType[0] = type;
latch.countDown();
});
AuthenticationResultHandler.handler().onActivityResult(REQUEST_CODE_SIGN_IN, RESULT_OK, intent);
latch.await();
assertNotNull(stateResult[0]);
assertEquals(stateResult[0].getStatus(), Status.ERROR);
assertEquals(stateResult[0].getException().type, AuthorizationException.TYPE_GENERAL_ERROR);
assertEquals(stateType[0], ResultType.SIGN_IN);
assertNull(AuthenticationResultHandler.handler().mCachedResult);
assertNull(AuthenticationResultHandler.handler().mCachedResultType);
}
use of com.okta.oidc.AuthenticationResultHandler.StateResult in project okta-oidc-android by okta.
the class AuthenticationResultHandlerTest method onActivityResultEmptyIntent.
@Test
public void onActivityResultEmptyIntent() throws InterruptedException {
Intent intent = new Intent();
CountDownLatch latch = new CountDownLatch(1);
final StateResult[] stateResult = new StateResult[1];
final ResultType[] stateType = new ResultType[1];
AuthenticationResultHandler.handler().setAuthenticationListener((result, type) -> {
stateResult[0] = result;
stateType[0] = type;
latch.countDown();
});
AuthenticationResultHandler.handler().onActivityResult(REQUEST_CODE_SIGN_IN, RESULT_OK, intent);
latch.await();
assertNotNull(stateResult[0]);
assertEquals(stateResult[0].getStatus(), Status.ERROR);
assertEquals(stateResult[0].getException().code, AuthorizationRequestErrors.OTHER.code);
assertNotNull(stateResult[0].getException().getCause());
assertTrue(stateResult[0].getException().getCause() instanceof NullPointerException);
assertEquals(stateType[0], ResultType.SIGN_IN);
assertNull(AuthenticationResultHandler.handler().mCachedResult);
assertNull(AuthenticationResultHandler.handler().mCachedResultType);
}
use of com.okta.oidc.AuthenticationResultHandler.StateResult in project okta-oidc-android by okta.
the class AuthenticationResultHandlerTest method onActivityResultSignInFailed.
@Test
public void onActivityResultSignInFailed() throws InterruptedException {
Intent intent = new Intent();
intent.setData(Uri.parse("com.okta.test:/authorize?error=" + TestValues.ERROR));
CountDownLatch latch = new CountDownLatch(1);
final StateResult[] stateResult = new StateResult[1];
final ResultType[] stateType = new ResultType[1];
AuthenticationResultHandler.handler().setAuthenticationListener((result, type) -> {
stateResult[0] = result;
stateType[0] = type;
latch.countDown();
});
AuthenticationResultHandler.handler().onActivityResult(REQUEST_CODE_SIGN_IN, RESULT_OK, intent);
latch.await();
assertNotNull(stateResult[0]);
assertEquals(stateResult[0].getStatus(), Status.ERROR);
assertEquals(stateResult[0].getException().error, TestValues.ERROR);
assertEquals(stateType[0], ResultType.SIGN_IN);
assertNull(AuthenticationResultHandler.handler().mCachedResult);
assertNull(AuthenticationResultHandler.handler().mCachedResultType);
}
use of com.okta.oidc.AuthenticationResultHandler.StateResult in project okta-oidc-android by okta.
the class AuthenticationResultHandlerTest method onActivityResultSignInSuccess.
@Test
public void onActivityResultSignInSuccess() throws InterruptedException {
Intent intent = new Intent();
intent.setData(Uri.parse("com.okta.test:/callback?code=" + CUSTOM_CODE + "&state=" + CUSTOM_STATE));
CountDownLatch latch = new CountDownLatch(1);
final StateResult[] stateResult = new StateResult[1];
final ResultType[] stateType = new ResultType[1];
AuthenticationResultHandler.handler().setAuthenticationListener((result, type) -> {
stateResult[0] = result;
stateType[0] = type;
latch.countDown();
});
AuthenticationResultHandler.handler().onActivityResult(REQUEST_CODE_SIGN_IN, RESULT_OK, intent);
latch.await();
assertNotNull(stateResult[0]);
AuthorizeResponse response = (AuthorizeResponse) stateResult[0].getAuthorizationResponse();
assertNotNull(response);
assertEquals(stateResult[0].getStatus(), Status.AUTHORIZED);
assertEquals(response.getState(), CUSTOM_STATE);
assertEquals(response.getCode(), CUSTOM_CODE);
assertEquals(stateType[0], ResultType.SIGN_IN);
assertNull(AuthenticationResultHandler.handler().mCachedResult);
assertNull(AuthenticationResultHandler.handler().mCachedResultType);
}
use of com.okta.oidc.AuthenticationResultHandler.StateResult in project okta-oidc-android by okta.
the class AuthenticationResultHandlerTest method onActivityResultInvalidJson.
@Test
public void onActivityResultInvalidJson() throws InterruptedException {
Intent intent = new Intent();
intent.putExtra(EXTRA_EXCEPTION, "invalid json");
CountDownLatch latch = new CountDownLatch(1);
final StateResult[] stateResult = new StateResult[1];
final ResultType[] stateType = new ResultType[1];
AuthenticationResultHandler.handler().setAuthenticationListener((result, type) -> {
stateResult[0] = result;
stateType[0] = type;
latch.countDown();
});
AuthenticationResultHandler.handler().onActivityResult(REQUEST_CODE_SIGN_IN, RESULT_OK, intent);
latch.await();
assertNotNull(stateResult[0]);
assertEquals(stateResult[0].getStatus(), Status.ERROR);
assertEquals(stateResult[0].getException().code, JSON_DESERIALIZATION_ERROR.code);
assertEquals(stateType[0], ResultType.SIGN_IN);
assertNull(AuthenticationResultHandler.handler().mCachedResult);
assertNull(AuthenticationResultHandler.handler().mCachedResultType);
}
Aggregations