Search in sources :

Example 6 with ContainerRequestContext

use of jakarta.ws.rs.container.ContainerRequestContext in project OpenGrok by OpenGrok.

the class IncomingFilterTest method localhostTestWithForwardedHeader.

@Test
public void localhostTestWithForwardedHeader() throws Exception {
    Map<String, String> headers = new TreeMap<>();
    headers.put("X-Forwarded-For", "192.0.2.43, 2001:db8:cafe::17");
    IncomingFilter filter = mockWithRemoteAddress("127.0.0.1", headers, true);
    ContainerRequestContext context = mockContainerRequestContext("test");
    ArgumentCaptor<Response> captor = ArgumentCaptor.forClass(Response.class);
    filter.filter(context);
    verify(context).abortWith(captor.capture());
    assertEquals(Response.Status.UNAUTHORIZED.getStatusCode(), captor.getValue().getStatus());
}
Also used : Response(jakarta.ws.rs.core.Response) ContainerRequestContext(jakarta.ws.rs.container.ContainerRequestContext) TreeMap(java.util.TreeMap) Test(org.junit.jupiter.api.Test)

Example 7 with ContainerRequestContext

use of jakarta.ws.rs.container.ContainerRequestContext in project OpenGrok by OpenGrok.

the class IncomingFilterTest method assertFilterDoesNotBlockAddress.

private void assertFilterDoesNotBlockAddress(final String remoteAddr) throws Exception {
    IncomingFilter filter = mockWithRemoteAddress(remoteAddr);
    ContainerRequestContext context = mockContainerRequestContext("test");
    ArgumentCaptor<Response> captor = ArgumentCaptor.forClass(Response.class);
    filter.filter(context);
    verify(context, never()).abortWith(captor.capture());
}
Also used : Response(jakarta.ws.rs.core.Response) ContainerRequestContext(jakarta.ws.rs.container.ContainerRequestContext)

Example 8 with ContainerRequestContext

use of jakarta.ws.rs.container.ContainerRequestContext in project OpenGrok by OpenGrok.

the class IncomingFilterTest method searchTest.

@Test
public void searchTest() throws Exception {
    IncomingFilter filter = mockWithRemoteAddress("10.0.0.1");
    ContainerRequestContext context = mockContainerRequestContext("search");
    ArgumentCaptor<Response> captor = ArgumentCaptor.forClass(Response.class);
    filter.filter(context);
    verify(context, never()).abortWith(captor.capture());
}
Also used : Response(jakarta.ws.rs.core.Response) ContainerRequestContext(jakarta.ws.rs.container.ContainerRequestContext) Test(org.junit.jupiter.api.Test)

Aggregations

ContainerRequestContext (jakarta.ws.rs.container.ContainerRequestContext)8 Response (jakarta.ws.rs.core.Response)6 Test (org.junit.jupiter.api.Test)4 TreeMap (java.util.TreeMap)3 ContainerResponseContext (jakarta.ws.rs.container.ContainerResponseContext)1 MultivaluedHashMap (jakarta.ws.rs.core.MultivaluedHashMap)1 UriInfo (jakarta.ws.rs.core.UriInfo)1 HashSet (java.util.HashSet)1 RuntimeEnvironment (org.opengrok.indexer.configuration.RuntimeEnvironment)1 CorsFilter (org.opengrok.web.api.v1.filter.CorsFilter)1