use of org.forgerock.http.protocol.Request in project OpenAM by OpenRock.
the class CrestProtocolEnforcementFilterTest method requestWithNoProtocolVersionShouldBeDefaultedAndThenCallHandler.
@Test
public void requestWithNoProtocolVersionShouldBeDefaultedAndThenCallHandler() {
//Given
Context context = mock(Context.class);
Request request = new Request();
Handler next = mock(Handler.class);
//When
filter.filter(context, request, next);
//Then
assertThat(AcceptApiVersionHeader.valueOf(request).getProtocolVersion()).isEqualTo(version(1));
verify(next).handle(context, request);
}
use of org.forgerock.http.protocol.Request in project OpenAM by OpenRock.
the class CrestProtocolEnforcementFilterTest method requestWithIncorrectProtocolMinorVersionShouldReturnBadRequestResponse.
@Test
public void requestWithIncorrectProtocolMinorVersionShouldReturnBadRequestResponse() throws IOException {
//Given
Context context = mock(Context.class);
Request request = new Request();
Handler next = mock(Handler.class);
request.getHeaders().put(AcceptApiVersionHeader.valueOf("protocol=1.1"));
//When
Response response = filter.filter(context, request, next).getOrThrowUninterruptibly();
//Then
assertThat(getUnsupportedMinorVersionExceptionJson(version(1, 1))).isEqualTo(response.getEntity().getJson());
assertThat(AcceptApiVersionHeader.valueOf(request).getProtocolVersion()).isEqualTo(version(1, 1));
verify(next, never()).handle(context, request);
}
use of org.forgerock.http.protocol.Request in project OpenAM by OpenRock.
the class RealmContextFilterTest method filterShouldConsumeRealmFromRequestWithDnsAliasAndUriRealmAndOverrideRealm.
@Test
public void filterShouldConsumeRealmFromRequestWithDnsAliasAndUriRealmAndOverrideRealm() throws Exception {
//Given
Context context = mockContext(SUB_REALM + "/" + ENDPOINT_PATH_ELEMENT);
Request request = createRequest(DNS_ALIAS_HOSTNAME, SUB_REALM + "/" + ENDPOINT_PATH_ELEMENT + "?realm=" + OVERRIDE_REALM);
mockDnsAlias(DNS_ALIAS_HOSTNAME, "/" + DNS_ALIS_SUB_REALM);
mockRealmAlias("/" + DNS_ALIS_SUB_REALM + "/" + SUB_REALM, "/" + DNS_ALIS_SUB_REALM + "/" + SUB_REALM);
mockRealmAlias(OVERRIDE_REALM, OVERRIDE_REALM);
//When
filter.filter(context, request, handler);
//Then
ArgumentCaptor<Context> contextCaptor = ArgumentCaptor.forClass(Context.class);
verify(handler).handle(contextCaptor.capture(), eq(request));
verifyRealmContext(contextCaptor.getValue(), "/" + DNS_ALIS_SUB_REALM, "/" + SUB_REALM, OVERRIDE_REALM);
verifyUriRouterContext(contextCaptor.getValue(), SUB_REALM);
}
use of org.forgerock.http.protocol.Request in project OpenAM by OpenRock.
the class RealmContextFilterTest method filterShouldConsumeRealmFromRequestWithOverrideRealm.
@Test
public void filterShouldConsumeRealmFromRequestWithOverrideRealm() throws Exception {
//Given
Context context = mockContext(ENDPOINT_PATH_ELEMENT);
Request request = createRequest(HOSTNAME, ENDPOINT_PATH_ELEMENT + "?realm=" + OVERRIDE_REALM + "/");
mockDnsAlias(HOSTNAME, "/");
mockRealmAlias(OVERRIDE_REALM, OVERRIDE_REALM);
//When
filter.filter(context, request, handler);
//Then
ArgumentCaptor<Context> contextCaptor = ArgumentCaptor.forClass(Context.class);
verify(handler).handle(contextCaptor.capture(), eq(request));
verifyRealmContext(contextCaptor.getValue(), "/", "", OVERRIDE_REALM);
verifyUriRouterContext(contextCaptor.getValue(), "");
}
use of org.forgerock.http.protocol.Request in project OpenAM by OpenRock.
the class RealmContextFilterTest method filterShouldConsumeRealmFromRequestWithUriRealm.
@Test
public void filterShouldConsumeRealmFromRequestWithUriRealm() throws Exception {
//Given
Context context = mockContext(SUB_REALM + "/" + ENDPOINT_PATH_ELEMENT);
Request request = createRequest(HOSTNAME, SUB_REALM + "/" + ENDPOINT_PATH_ELEMENT);
mockDnsAlias(HOSTNAME, "/");
mockRealmAlias("/" + SUB_REALM, "/" + SUB_REALM);
//When
filter.filter(context, request, handler);
//Then
ArgumentCaptor<Context> contextCaptor = ArgumentCaptor.forClass(Context.class);
verify(handler).handle(contextCaptor.capture(), eq(request));
verifyRealmContext(contextCaptor.getValue(), "", "/" + SUB_REALM, null);
verifyUriRouterContext(contextCaptor.getValue(), SUB_REALM);
}
Aggregations