Search in sources :

Example 11 with StateResult

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);
}
Also used : StateResult(com.okta.oidc.AuthenticationResultHandler.StateResult) Intent(android.content.Intent) ResultType(com.okta.oidc.AuthenticationResultHandler.ResultType) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test)

Example 12 with StateResult

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);
}
Also used : StateResult(com.okta.oidc.AuthenticationResultHandler.StateResult) Intent(android.content.Intent) ResultType(com.okta.oidc.AuthenticationResultHandler.ResultType) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test)

Example 13 with StateResult

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);
}
Also used : StateResult(com.okta.oidc.AuthenticationResultHandler.StateResult) Intent(android.content.Intent) ResultType(com.okta.oidc.AuthenticationResultHandler.ResultType) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test)

Example 14 with StateResult

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);
}
Also used : AuthorizeResponse(com.okta.oidc.net.response.web.AuthorizeResponse) StateResult(com.okta.oidc.AuthenticationResultHandler.StateResult) Intent(android.content.Intent) ResultType(com.okta.oidc.AuthenticationResultHandler.ResultType) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test)

Example 15 with StateResult

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);
}
Also used : StateResult(com.okta.oidc.AuthenticationResultHandler.StateResult) Intent(android.content.Intent) ResultType(com.okta.oidc.AuthenticationResultHandler.ResultType) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test)

Aggregations

StateResult (com.okta.oidc.AuthenticationResultHandler.StateResult)15 Intent (android.content.Intent)13 CountDownLatch (java.util.concurrent.CountDownLatch)13 Test (org.junit.Test)11 ResultType (com.okta.oidc.AuthenticationResultHandler.ResultType)10 AuthorizeResponse (com.okta.oidc.net.response.web.AuthorizeResponse)3 AuthorizationException (com.okta.oidc.util.AuthorizationException)3 FragmentActivity (androidx.fragment.app.FragmentActivity)2 OktaResultFragment.createAuthIntent (com.okta.oidc.OktaResultFragment.createAuthIntent)2 WebRequest (com.okta.oidc.net.request.web.WebRequest)2 LogoutResponse (com.okta.oidc.net.response.web.LogoutResponse)2 OktaRepository (com.okta.oidc.storage.OktaRepository)2 AtomicReference (java.util.concurrent.atomic.AtomicReference)2 RESULT_CANCELED (android.app.Activity.RESULT_CANCELED)1 RESULT_OK (android.app.Activity.RESULT_OK)1 Uri (android.net.Uri)1 AnyThread (androidx.annotation.AnyThread)1 WorkerThread (androidx.annotation.WorkerThread)1 AuthResultListener (com.okta.oidc.AuthenticationResultHandler.AuthResultListener)1 Status (com.okta.oidc.AuthenticationResultHandler.Status)1