use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.DefaultFullHttpRequest in project crate by crate.
the class HttpAuthUpstreamHandlerTest method testNotNoHbaConfig.
@Test
public void testNotNoHbaConfig() throws Exception {
HttpAuthUpstreamHandler handler = new HttpAuthUpstreamHandler(Settings.EMPTY, authService);
EmbeddedChannel ch = new EmbeddedChannel(handler);
DefaultHttpRequest request = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.POST, "/_sql");
request.headers().add(HttpHeaderNames.AUTHORIZATION.toString(), "Basic QWxhZGRpbjpPcGVuU2VzYW1l");
request.headers().add("X-Real-Ip", "10.1.0.100");
ch.writeInbound(request);
ch.releaseInbound();
assertFalse(handler.authorized());
assertUnauthorized(ch.readOutbound(), "No valid auth.host_based.config entry found for host \"10.1.0.100\", user \"Aladdin\", protocol \"http\". Did you enable TLS in your client?\n");
}
use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.DefaultFullHttpRequest in project crate by crate.
the class HttpAuthUpstreamHandlerTest method testAuthorized.
@Test
public void testAuthorized() throws Exception {
HttpAuthUpstreamHandler handler = new HttpAuthUpstreamHandler(Settings.EMPTY, new AlwaysOKAuthentication(userName -> User.CRATE_USER));
EmbeddedChannel ch = new EmbeddedChannel(handler);
DefaultHttpRequest request = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.POST, "/_sql");
ch.writeInbound(request);
ch.releaseInbound();
assertThat(handler.authorized(), is(true));
}
use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.DefaultFullHttpRequest in project crate by crate.
the class HttpAuthUpstreamHandlerTest method testUnauthorizedUser.
@Test
public void testUnauthorizedUser() throws Exception {
HttpAuthUpstreamHandler handler = new HttpAuthUpstreamHandler(Settings.EMPTY, authService);
EmbeddedChannel ch = new EmbeddedChannel(handler);
HttpRequest request = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.POST, "/_sql");
ch.writeInbound(request);
ch.releaseInbound();
assertFalse(handler.authorized());
assertUnauthorized(ch.readOutbound(), "trust authentication failed for user \"crate\"\n");
}
use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.DefaultFullHttpRequest in project crate by crate.
the class HttpAuthUpstreamHandlerTest method testClientCertUserHasPreferenceOverTrustAuthDefault.
@Test
public void testClientCertUserHasPreferenceOverTrustAuthDefault() throws Exception {
SelfSignedCertificate ssc = new SelfSignedCertificate();
SSLSession session = mock(SSLSession.class);
when(session.getPeerCertificates()).thenReturn(new Certificate[] { ssc.cert() });
HttpRequest request = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.POST, "/_sql");
String userName = HttpAuthUpstreamHandler.credentialsFromRequest(request, session, Settings.EMPTY).v1();
assertThat(userName, is("localhost"));
}
use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.DefaultFullHttpRequest in project graylog2-server by Graylog2.
the class HttpHandlerTest method withCustomContentType.
@Test
public void withCustomContentType() {
final FullHttpRequest httpRequest = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.POST, "/gelf");
httpRequest.headers().add(HttpHeaderNames.HOST, "localhost");
httpRequest.headers().add(HttpHeaderNames.CONTENT_TYPE, "foo/bar");
httpRequest.headers().add(HttpHeaderNames.CONNECTION, HttpHeaderValues.CLOSE);
httpRequest.content().writeBytes(GELF_MESSAGE);
channel.writeInbound(httpRequest);
channel.finish();
final HttpResponse httpResponse = channel.readOutbound();
assertThat(httpResponse.status()).isEqualTo(HttpResponseStatus.ACCEPTED);
final HttpHeaders headers = httpResponse.headers();
assertThat(headers.get(HttpHeaderNames.CONTENT_LENGTH)).isEqualTo("0");
assertThat(headers.get(HttpHeaderNames.CONNECTION)).isEqualTo(HttpHeaderValues.CLOSE.toString());
}
Aggregations