Search in sources :

Example 11 with Request

use of org.glassfish.grizzly.http.server.Request in project graylog2-server by Graylog2.

the class RestToolsTest method getRemoteAddrFromRequestReturnsHeaderContentWithXForwardedForHeaderFromTrustedNetwork.

@Test
public void getRemoteAddrFromRequestReturnsHeaderContentWithXForwardedForHeaderFromTrustedNetwork() throws Exception {
    final Request request = mock(Request.class);
    when(request.getRemoteAddr()).thenReturn("127.0.0.1");
    when(request.getHeader("X-Forwarded-For")).thenReturn("192.168.100.42");
    final String s = RestTools.getRemoteAddrFromRequest(request, Collections.singleton(new IpSubnet("127.0.0.0/8")));
    assertThat(s).isEqualTo("192.168.100.42");
}
Also used : IpSubnet(org.graylog2.utilities.IpSubnet) Request(org.glassfish.grizzly.http.server.Request) Test(org.junit.Test)

Example 12 with Request

use of org.glassfish.grizzly.http.server.Request in project graylog2-server by Graylog2.

the class RestToolsTest method getRemoteAddrFromRequestReturnsClientAddressWithXForwardedForHeaderFromUntrustedNetwork.

@Test
public void getRemoteAddrFromRequestReturnsClientAddressWithXForwardedForHeaderFromUntrustedNetwork() throws Exception {
    final Request request = mock(Request.class);
    when(request.getRemoteAddr()).thenReturn("192.168.0.1");
    when(request.getHeader("X-Forwarded-For")).thenReturn("192.168.100.42");
    final String s = RestTools.getRemoteAddrFromRequest(request, Collections.singleton(new IpSubnet("127.0.0.0/8")));
    assertThat(s).isEqualTo("192.168.0.1");
}
Also used : IpSubnet(org.graylog2.utilities.IpSubnet) Request(org.glassfish.grizzly.http.server.Request) Test(org.junit.Test)

Example 13 with Request

use of org.glassfish.grizzly.http.server.Request in project graylog2-server by Graylog2.

the class RestToolsTest method getRemoteAddrFromRequestReturnsClientAddressWithNoXForwardedForHeader.

@Test
public void getRemoteAddrFromRequestReturnsClientAddressWithNoXForwardedForHeader() throws Exception {
    final Request request = mock(Request.class);
    when(request.getRemoteAddr()).thenReturn("192.168.0.1");
    when(request.getHeader("X-Forwarded-For")).thenReturn(null);
    final String s = RestTools.getRemoteAddrFromRequest(request, Collections.emptySet());
    assertThat(s).isEqualTo("192.168.0.1");
}
Also used : Request(org.glassfish.grizzly.http.server.Request) Test(org.junit.Test)

Example 14 with Request

use of org.glassfish.grizzly.http.server.Request in project graylog2-server by Graylog2.

the class RestToolsTest method getRemoteAddrFromRequestWorksWithIPv6IfSubnetsContainsOnlyIPv6.

@Test
public void getRemoteAddrFromRequestWorksWithIPv6IfSubnetsContainsOnlyIPv6() throws Exception {
    final Request request = mock(Request.class);
    when(request.getRemoteAddr()).thenReturn("2001:DB8::42");
    when(request.getHeader("X-Forwarded-For")).thenReturn("2001:DB8::1:2:3:4:5:6");
    final String s = RestTools.getRemoteAddrFromRequest(request, Collections.singleton(new IpSubnet("2001:DB8::/32")));
    assertThat(s).isEqualTo("2001:DB8::1:2:3:4:5:6");
}
Also used : IpSubnet(org.graylog2.utilities.IpSubnet) Request(org.glassfish.grizzly.http.server.Request) Test(org.junit.Test)

Example 15 with Request

use of org.glassfish.grizzly.http.server.Request in project graylog2-server by Graylog2.

the class ShiroSecurityContextFilterTest method setUp.

@Before
public void setUp() throws Exception {
    when(securityContext.isSecure()).thenReturn(false);
    when(requestContext.getSecurityContext()).thenReturn(securityContext);
    final DefaultSecurityManager securityManager = new DefaultSecurityManager();
    final Provider<Request> grizzlyRequestProvider = () -> mock(Request.class);
    filter = new ShiroSecurityContextFilter(securityManager, grizzlyRequestProvider, Collections.emptySet());
}
Also used : Request(org.glassfish.grizzly.http.server.Request) DefaultSecurityManager(org.apache.shiro.mgt.DefaultSecurityManager) Before(org.junit.Before)

Aggregations

Request (org.glassfish.grizzly.http.server.Request)16 Test (org.junit.Test)6 IOException (java.io.IOException)5 Response (org.glassfish.grizzly.http.server.Response)5 HttpHandler (org.glassfish.grizzly.http.server.HttpHandler)4 IpSubnet (org.graylog2.utilities.IpSubnet)4 URI (java.net.URI)3 URISyntaxException (java.net.URISyntaxException)3 ParseException (java.text.ParseException)3 List (java.util.List)3 Collectors (java.util.stream.Collectors)3 Consumes (javax.ws.rs.Consumes)3 POST (javax.ws.rs.POST)3 Produces (javax.ws.rs.Produces)3 Response (javax.ws.rs.core.Response)3 Idf (org.edamontology.edammap.core.idf.Idf)3 PreProcessor (org.edamontology.edammap.core.preprocessing.PreProcessor)3 Files (java.nio.file.Files)2 Paths (java.nio.file.Paths)2 Instant (java.time.Instant)2