use of org.forgerock.services.context.Context in project OpenAM by OpenRock.
the class RestRouterIT method shouldReadCrestEndpointOnRootHandler.
@Test
public void shouldReadCrestEndpointOnRootHandler() throws Exception {
//Given
Context context = mockRequiredContexts();
Request request = newRequest("GET", "/json/config");
auditingOff();
//When
handler.handle(context, request);
//Then
verify(configResource).readInstance(any(Context.class), any(ReadRequest.class));
}
use of org.forgerock.services.context.Context in project OpenAM by OpenRock.
the class RestRouterIT method shouldReadCrestEndpointOnRealmHandlerWithRootRealm.
@Test
public void shouldReadCrestEndpointOnRealmHandlerWithRootRealm() throws Exception {
//Given
Context context = mockRequiredContexts();
Request request = newRequest("GET", "/json/users/demo");
auditingOff();
//When
handler.handle(context, request);
//Then
ArgumentCaptor<Context> contextCaptor = ArgumentCaptor.forClass(Context.class);
verify(usersResource).readInstance(contextCaptor.capture(), eq("demo"), any(ReadRequest.class));
assertThat(contextCaptor.getValue().asContext(RealmContext.class).getResolvedRealm()).isEqualTo("/");
}
use of org.forgerock.services.context.Context in project OpenAM by OpenRock.
the class CrestProtocolEnforcementFilterTest method requestWithCorrectProtocolVersionShouldCallHandler.
@Test
public void requestWithCorrectProtocolVersionShouldCallHandler() {
//Given
Context context = mock(Context.class);
Request request = new Request();
Handler next = mock(Handler.class);
request.getHeaders().put(AcceptApiVersionHeader.valueOf("protocol=1"));
//When
filter.filter(context, request, next);
//Then
assertThat(AcceptApiVersionHeader.valueOf(request).getProtocolVersion()).isEqualTo(version(1));
verify(next).handle(context, request);
}
use of org.forgerock.services.context.Context in project OpenAM by OpenRock.
the class CrestProtocolEnforcementFilterTest method requestWithIncorrectProtocolMajorVersionShouldReturnBadRequestResponse.
@Test
public void requestWithIncorrectProtocolMajorVersionShouldReturnBadRequestResponse() throws IOException {
//Given
Context context = mock(Context.class);
Request request = new Request();
Handler next = mock(Handler.class);
request.getHeaders().put(AcceptApiVersionHeader.valueOf("protocol=2"));
//When
Response response = filter.filter(context, request, next).getOrThrowUninterruptibly();
//Then
assertThat(getUnsupportedMajorVersionExceptionJson(version(2))).isEqualTo(response.getEntity().getJson());
assertThat(AcceptApiVersionHeader.valueOf(request).getProtocolVersion()).isEqualTo(version(2));
verify(next, never()).handle(context, request);
}
use of org.forgerock.services.context.Context in project OpenAM by OpenRock.
the class ElevatedConnectionFactoryWrapperTest method requestGetsElevatedToAdminSession.
@Test
public void requestGetsElevatedToAdminSession() throws Exception {
// Given
SSOToken ssoToken = mock(SSOToken.class);
given(ssoTokenPrivilegedAction.run()).willReturn(ssoToken);
SSOPrincipal principal = new SSOPrincipal("test");
given(ssoToken.getPrincipal()).willReturn(principal);
SSOTokenID tokenID = mock(SSOTokenID.class);
given(ssoToken.getTokenID()).willReturn(tokenID);
given(internalConnectionFactory.getConnection()).willReturn(connection);
// When
RootContext context = new RootContext();
ReadRequest readRequest = Requests.newReadRequest("/test", "abc");
try (Connection connection = connectionFactory.getConnection()) {
connection.read(context, readRequest);
}
// Then
verify(connection).read(contextCaptor.capture(), eq(readRequest));
Context capturedContext = contextCaptor.getValue();
assertThat(capturedContext.containsContext(SecurityContext.class)).isTrue();
SecurityContext securityContext = capturedContext.asContext(SecurityContext.class);
assertThat(securityContext.getAuthenticationId()).isEqualTo("test");
assertThat(securityContext.getAuthorization()).containsOnlyKeys("authLevel", "tokenId");
}
Aggregations