use of org.forgerock.services.context.Context in project OpenAM by OpenRock.
the class SessionResourceTest method actionInstanceShouldReturnNotSupportedForUnknownAction.
@Test
public void actionInstanceShouldReturnNotSupportedForUnknownAction() throws SSOException {
//Given
final Context context = mock(Context.class);
final String resourceId = "SSO_TOKEN_ID";
final ActionRequest request = mock(ActionRequest.class);
given(request.getAction()).willReturn("unknown-action");
//When
Promise<ActionResponse, ResourceException> promise = sessionResource.actionInstance(context, resourceId, request);
//Then
assertThat(promise).failedWithException().isExactlyInstanceOf(NotSupportedException.class);
}
use of org.forgerock.services.context.Context in project OpenAM by OpenRock.
the class SessionResourceTest method actionCollectionShouldValidateSessionAndReturnTrueWhenSSOTokenValid.
@Test
public void actionCollectionShouldValidateSessionAndReturnTrueWhenSSOTokenValid() throws SSOException {
//Given
cookieResponse = "SSO_TOKEN_ID";
final SSOTokenContext tokenContext = mock(SSOTokenContext.class);
final Context context = ClientContext.newInternalClientContext(tokenContext);
final ActionRequest request = mock(ActionRequest.class);
final SSOToken ssoToken = mock(SSOToken.class);
final SSOTokenID ssoTokenId = mock(SSOTokenID.class);
given(request.getAction()).willReturn(VALIDATE_ACTION_ID);
given(tokenContext.getCallerSSOToken()).willReturn(ssoToken);
given(ssoTokenManager.isValidToken(ssoToken)).willReturn(true);
given(ssoToken.getTokenID()).willReturn(ssoTokenId);
given(ssoTokenId.toString()).willReturn("SSO_TOKEN_ID");
given(ssoTokenManager.createSSOToken(ssoTokenId.toString())).willReturn(ssoToken);
//When
Promise<ActionResponse, ResourceException> promise = sessionResource.actionCollection(context, request);
//Then
assertThat(promise).succeeded().withContent().booleanAt("valid").isTrue();
assertThat(promise).succeeded().withContent().stringAt("uid").isEqualTo("demo");
assertThat(promise).succeeded().withContent().stringAt("realm").isEqualTo("/");
}
use of org.forgerock.services.context.Context in project OpenAM by OpenRock.
the class SessionResourceTest method actionInstanceShouldBeInactiveWhenSSOTokenInvalid.
@Test
public void actionInstanceShouldBeInactiveWhenSSOTokenInvalid() throws SSOException {
//Given
final Context context = mock(Context.class);
final String resourceId = "SSO_TOKEN_ID";
final ActionRequest request = mock(ActionRequest.class);
final SSOToken ssoToken = mock(SSOToken.class);
given(request.getAction()).willReturn(IS_ACTIVE_ACTION_ID);
given(ssoTokenManager.retrieveValidTokenWithoutResettingIdleTime("SSO_TOKEN_ID")).willReturn(ssoToken);
given(ssoTokenManager.isValidToken(ssoToken, false)).willReturn(false);
//When
Promise<ActionResponse, ResourceException> promise = sessionResource.actionInstance(context, resourceId, request);
//Then
assertThat(promise).succeeded().withContent().booleanAt("active").isFalse();
}
use of org.forgerock.services.context.Context in project OpenAM by OpenRock.
the class SessionResourceTest method actionInstanceShouldGiveMinusOneForIdleTimeWhenSSOTokenInvalid.
@Test
public void actionInstanceShouldGiveMinusOneForIdleTimeWhenSSOTokenInvalid() throws SSOException {
//Given
final Context context = mock(Context.class);
final String resourceId = "SSO_TOKEN_ID";
final ActionRequest request = mock(ActionRequest.class);
final SSOToken ssoToken = mock(SSOToken.class);
given(request.getAction()).willReturn(GET_IDLE_ACTION_ID);
given(ssoTokenManager.retrieveValidTokenWithoutResettingIdleTime("SSO_TOKEN_ID")).willReturn(ssoToken);
given(ssoTokenManager.isValidToken(ssoToken, false)).willReturn(false);
//When
Promise<ActionResponse, ResourceException> promise = sessionResource.actionInstance(context, resourceId, request);
//Then
assertThat(promise).succeeded().withContent().integerAt("idletime").isEqualTo(-1);
}
use of org.forgerock.services.context.Context in project OpenAM by OpenRock.
the class SessionResourceTest method actionInstanceShouldValidateSessionAndReturnTrueWhenSSOTokenValid.
@Test
public void actionInstanceShouldValidateSessionAndReturnTrueWhenSSOTokenValid() throws SSOException {
//Given
final Context context = mock(Context.class);
final String resourceId = "SSO_TOKEN_ID";
final ActionRequest request = mock(ActionRequest.class);
final SSOToken ssoToken = mock(SSOToken.class);
final Principal principal = mock(Principal.class);
given(request.getAction()).willReturn(VALIDATE_ACTION_ID);
given(ssoTokenManager.createSSOToken("SSO_TOKEN_ID")).willReturn(ssoToken);
given(ssoTokenManager.isValidToken(ssoToken)).willReturn(true);
given(ssoToken.getPrincipal()).willReturn(principal);
given(principal.getName()).willReturn("PRINCIPAL");
//When
Promise<ActionResponse, ResourceException> promise = sessionResource.actionInstance(context, resourceId, request);
//Then
assertThat(promise).succeeded().withContent().booleanAt("valid").isTrue();
assertThat(promise).succeeded().withContent().stringAt("uid").isEqualTo("demo");
assertThat(promise).succeeded().withContent().stringAt("realm").isEqualTo("/");
}
Aggregations