use of org.forgerock.http.protocol.Request in project OpenAM by OpenRock.
the class RealmContextFilterTest method filterShouldConsumeRealmFromRequestWithInvalidDnsAlias.
@Test
public void filterShouldConsumeRealmFromRequestWithInvalidDnsAlias() throws Exception {
//Given
Context context = mockContext(ENDPOINT_PATH_ELEMENT);
Request request = createRequest(INVALID_DNS_ALIAS_HOSTNAME, ENDPOINT_PATH_ELEMENT);
mockInvalidDnsAlias(INVALID_DNS_ALIAS_HOSTNAME);
//When
Response response = filter.filter(context, request, handler).getOrThrowUninterruptibly();
//Then
assertThat(response.getStatus()).isSameAs(Status.BAD_REQUEST);
}
use of org.forgerock.http.protocol.Request in project OpenAM by OpenRock.
the class RealmContextFilterTest method filterShouldConsumeRealmFromRequestWithInvalidOverrideRealm.
@Test
public void filterShouldConsumeRealmFromRequestWithInvalidOverrideRealm() throws Exception {
//Given
Context context = mockContext(ENDPOINT_PATH_ELEMENT);
Request request = createRequest(HOSTNAME, ENDPOINT_PATH_ELEMENT + "?realm=" + INVALID_OVERRIDE_REALM);
mockDnsAlias(HOSTNAME, "/");
mockInvalidRealmAlias(INVALID_OVERRIDE_REALM);
//When
Response response = filter.filter(context, request, handler).getOrThrowUninterruptibly();
//Then
verifyInvalidRealmResponse(response, INVALID_OVERRIDE_REALM);
}
use of org.forgerock.http.protocol.Request in project OpenAM by OpenRock.
the class RealmContextFilterTest method filterShouldConsumeRealmFromCRUDPAQRequestWithInvalidSubrealm.
@Test(dataProvider = "CRUDPAQ")
public void filterShouldConsumeRealmFromCRUDPAQRequestWithInvalidSubrealm(Request request, String postURIString) throws Exception {
//Given
RequestHandler requestHandler = mock(RequestHandler.class);
String path = INVALID_SUB_REALM + "/" + ENDPOINT_PATH_ELEMENT;
Context context = mockContext(path);
request.setUri(createRequestURI(HOSTNAME, path, postURIString));
mockDnsAlias(HOSTNAME, "/");
mockInvalidRealmAlias(INVALID_SUB_REALM);
//When
Handler httpHandler = getHttpHandler(requestHandler);
httpHandler.handle(context, request).getOrThrowUninterruptibly();
//Then
ArgumentCaptor<Context> contextCaptor = ArgumentCaptor.forClass(Context.class);
ArgumentCaptor<org.forgerock.json.resource.Request> requestCaptor = ArgumentCaptor.forClass(org.forgerock.json.resource.Request.class);
collectCRUDPAQArguments(requestHandler, contextCaptor, requestCaptor);
verifyRealmContext(contextCaptor.getValue(), "", "/", null);
verifyUriRouterContextForInvalidRealm(contextCaptor.getValue());
verifyResolvedResourcePath(requestCaptor.getValue(), INVALID_SUB_REALM + "/" + ENDPOINT_PATH_ELEMENT);
}
use of org.forgerock.http.protocol.Request in project OpenAM by OpenRock.
the class RealmContextFilterTest method newJsonHttpRequest.
private Request newJsonHttpRequest(String method) {
Request request = new Request().setMethod(method);
request.getHeaders().put("Content-Type", "application/json");
return request;
}
use of org.forgerock.http.protocol.Request in project OpenAM by OpenRock.
the class RealmContextFilterTest method filterShouldFailToConsumeRealmFromRequestOnExceptionWhenResolvingServerName.
@Test
public void filterShouldFailToConsumeRealmFromRequestOnExceptionWhenResolvingServerName() throws Exception {
//Given
Context context = mockContext(ENDPOINT_PATH_ELEMENT);
Request request = createRequest(HOSTNAME, ENDPOINT_PATH_ELEMENT);
IdRepoException exception = mock(IdRepoException.class);
given(exception.getMessage()).willReturn("EXCEPTION_MESSAGE");
doThrow(exception).when(coreWrapper).getOrganization(any(SSOToken.class), eq(HOSTNAME));
//When
Response response = filter.filter(context, request, handler).getOrThrowUninterruptibly();
//Then
assertThat(response.getStatus()).isSameAs(Status.BAD_REQUEST);
assertThat(response.getEntity().getJson()).isEqualTo(new BadRequestException("FQDN \"HOSTNAME\" is not valid.").toJsonValue().getObject());
}
Aggregations