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");
}
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");
}
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");
}
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");
}
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());
}
Aggregations