コード例 #1
0
  @Test
  public void adaptedAsyncServerAuthContextShouldAdaptSuccessfulCleanSubjectCall()
      throws AuthException {

    // Given
    ServerAuthContext authContext = mock(ServerAuthContext.class);
    MessageContext messageContext = mock(MessageContext.class);
    Subject clientSubject = new Subject();

    // When
    AsyncServerAuthContext asyncAuthContext = JaspiAdapters.adapt(authContext);
    Promise<Void, AuthenticationException> promise =
        asyncAuthContext.cleanSubject(messageContext, clientSubject);

    // Then
    assertThat(promise).succeeded().withObject().isNull();
    verify(authContext).cleanSubject(any(MessageInfo.class), eq(clientSubject));
  }
コード例 #2
0
  @Test
  public void adaptedAsyncServerAuthContextShouldAdaptSuccessfulSecureResponseCall()
      throws AuthException {

    // Given
    ServerAuthContext authContext = mock(ServerAuthContext.class);
    MessageContext messageContext = mock(MessageContext.class);
    Subject serviceSubject = new Subject();

    given(authContext.secureResponse(any(MessageInfo.class), eq(serviceSubject)))
        .willReturn(AuthStatus.SEND_SUCCESS);

    // When
    AsyncServerAuthContext asyncAuthContext = JaspiAdapters.adapt(authContext);
    Promise<AuthStatus, AuthenticationException> promise =
        asyncAuthContext.secureResponse(messageContext, serviceSubject);

    // Then
    assertThat(promise).succeeded().withObject().isEqualTo(AuthStatus.SEND_SUCCESS);
  }
コード例 #3
0
  @Test
  public void adaptedAsyncServerAuthContextShouldAdaptFailedCleanSubjectCall()
      throws AuthException {

    // Given
    ServerAuthContext authContext = mock(ServerAuthContext.class);
    MessageContext messageContext = mock(MessageContext.class);
    Subject clientSubject = new Subject();

    doThrow(AuthException.class)
        .when(authContext)
        .cleanSubject(any(MessageInfo.class), eq(clientSubject));

    // When
    AsyncServerAuthContext asyncAuthContext = JaspiAdapters.adapt(authContext);
    Promise<Void, AuthenticationException> promise =
        asyncAuthContext.cleanSubject(messageContext, clientSubject);

    // Then
    assertThat(promise).failedWithException().isInstanceOf(AuthenticationException.class);
  }
コード例 #4
0
  @Test
  public void adaptedAsyncServerAuthContextShouldAdaptFailedSecureResponseCall()
      throws AuthException {

    // Given
    ServerAuthContext authContext = mock(ServerAuthContext.class);
    MessageContext messageContext = mock(MessageContext.class);
    Subject serviceSubject = new Subject();

    doThrow(AuthException.class)
        .when(authContext)
        .secureResponse(any(MessageInfo.class), eq(serviceSubject));

    // When
    AsyncServerAuthContext asyncAuthContext = JaspiAdapters.adapt(authContext);
    Promise<AuthStatus, AuthenticationException> promise =
        asyncAuthContext.secureResponse(messageContext, serviceSubject);

    // Then
    assertThat(promise).failedWithException().isInstanceOf(AuthenticationException.class);
  }