use of org.forgerock.openam.rest.resource.SSOTokenContext in project OpenAM by OpenRock.
the class SessionResourceTest method actionCollectionShouldFailToValidateSessionWhenSSOTokenIdNotSet.
@Test
public void actionCollectionShouldFailToValidateSessionWhenSSOTokenIdNotSet() {
//Given
final SSOTokenContext tokenContext = mock(SSOTokenContext.class);
final Context context = ClientContext.newInternalClientContext(tokenContext);
final ActionRequest request = mock(ActionRequest.class);
given(request.getAction()).willReturn(VALIDATE_ACTION_ID);
//When
Promise<ActionResponse, ResourceException> promise = sessionResource.actionCollection(context, request);
//Then
assertThat(promise).failedWithException().isInstanceOf(BadRequestException.class);
}
use of org.forgerock.openam.rest.resource.SSOTokenContext in project OpenAM by OpenRock.
the class SessionResourceTest method actionCollectionShouldLogoutSessionAndReturnEmptyJsonObjectWhenSSOTokenValid.
@Test
public void actionCollectionShouldLogoutSessionAndReturnEmptyJsonObjectWhenSSOTokenValid() throws SSOException {
//Given
cookieResponse = "SSO_TOKEN_ID";
final AttributesContext attrContext = new AttributesContext(new SessionContext(new RootContext(), mock(Session.class)));
final AdviceContext adviceContext = new AdviceContext(attrContext, Collections.<String>emptySet());
final SecurityContext securityContext = new SecurityContext(adviceContext, null, null);
final Context context = ClientContext.newInternalClientContext(new SSOTokenContext(mock(Debug.class), null, securityContext));
final ActionRequest request = mock(ActionRequest.class);
final SSOTokenID ssoTokenId = mock(SSOTokenID.class);
given(request.getAction()).willReturn(LOGOUT_ACTION_ID);
given(authUtilsWrapper.logout(ssoTokenId.toString(), null, null)).willReturn(true);
//When
Promise<ActionResponse, ResourceException> promise = sessionResource.actionCollection(context, request);
//Then
assertThat(promise).succeeded().withContent().stringAt("result").isEqualTo("Successfully logged out");
}
use of org.forgerock.openam.rest.resource.SSOTokenContext in project OpenAM by OpenRock.
the class TokenOwnerAuthzModuleTest method setupUser.
private Context setupUser(String finalId) throws SSOException {
Principal mockPrincipal = mock(Principal.class);
SSOTokenContext tc = mock(SSOTokenContext.class);
Context mockContext = mock(Context.class);
given(mockContext.asContext(SSOTokenContext.class)).willReturn(tc);
SSOToken mockToken = mock(SSOToken.class);
given(tc.getCallerSSOToken()).willReturn(mockToken);
given(mockToken.getProperty(eq(Constants.UNIVERSAL_IDENTIFIER))).willReturn("uid" + finalId);
given(mockTokenManager.createSSOToken(eq("token"))).willReturn(mockToken);
given(mockToken.getPrincipal()).willReturn(mockPrincipal);
given(mockPrincipal.getName()).willReturn(finalId);
return mockContext;
}
use of org.forgerock.openam.rest.resource.SSOTokenContext in project OpenAM by OpenRock.
the class ApplicationTypesResourceTest method undefinedSubjectShouldFail.
@Test(expectedExceptions = InternalServerErrorException.class)
public void undefinedSubjectShouldFail() throws ResourceException {
//given
SSOTokenContext mockSubjectContext = mock(SSOTokenContext.class);
RealmContext realmContext = new RealmContext(mockSubjectContext);
Context mockServerContext = ClientContext.newInternalClientContext(realmContext);
Subject subject = null;
given(mockSubjectContext.getCallerSubject()).willReturn(subject);
ReadRequest request = mock(ReadRequest.class);
//when
Promise<ResourceResponse, ResourceException> result = testResource.readInstance(mockServerContext, "test", request);
result.getOrThrowUninterruptibly();
}
use of org.forgerock.openam.rest.resource.SSOTokenContext in project OpenAM by OpenRock.
the class ApplicationTypesResourceTest method readShouldFailOnInvalidApplicationType.
@Test(expectedExceptions = NotFoundException.class)
public void readShouldFailOnInvalidApplicationType() throws ResourceException {
//given
SSOTokenContext mockSubjectContext = mock(SSOTokenContext.class);
RealmContext realmContext = new RealmContext(mockSubjectContext);
Context mockServerContext = ClientContext.newInternalClientContext(realmContext);
Subject subject = new Subject();
given(mockSubjectContext.getCallerSubject()).willReturn(subject);
ReadRequest request = mock(ReadRequest.class);
//when
Promise<ResourceResponse, ResourceException> result = testResource.readInstance(mockServerContext, "test", request);
//then
result.getOrThrowUninterruptibly();
}
Aggregations