Search in sources :

Example 61 with HttpHeaders

use of io.netty.handler.codec.http.HttpHeaders in project janusgraph by JanusGraph.

the class HttpHMACAuthenticationHandlerTest method testChannelReadBasicAuth.

@Test
public void testChannelReadBasicAuth() throws Exception {
    final ChannelHandlerContext ctx = createMock(ChannelHandlerContext.class);
    final FullHttpRequest msg = createMock(FullHttpRequest.class);
    final HttpHeaders headers = createMock(HttpHeaders.class);
    final Authenticator authenticator = createMock(Authenticator.class);
    final String encodedUserNameAndPass = Base64.getEncoder().encodeToString("user:pass".getBytes());
    expect(msg.getMethod()).andReturn(HttpMethod.POST);
    expect(msg.headers()).andReturn(headers).anyTimes();
    expect(msg.getUri()).andReturn("/");
    expect(headers.get(eq("Authorization"))).andReturn("Basic " + encodedUserNameAndPass);
    expect(ctx.fireChannelRead(isA(FullHttpRequest.class))).andReturn(ctx);
    expect(authenticator.authenticate(isA(Map.class))).andReturn(new AuthenticatedUser("foo"));
    final HttpHMACAuthenticationHandler handler = new HttpHMACAuthenticationHandler(authenticator);
    replayAll();
    handler.channelRead(ctx, (Object) msg);
    verifyAll();
}
Also used : HttpHeaders(io.netty.handler.codec.http.HttpHeaders) FullHttpRequest(io.netty.handler.codec.http.FullHttpRequest) ChannelHandlerContext(io.netty.channel.ChannelHandlerContext) Map(java.util.Map) AuthenticatedUser(org.apache.tinkerpop.gremlin.server.auth.AuthenticatedUser) Authenticator(org.apache.tinkerpop.gremlin.server.auth.Authenticator) Test(org.junit.Test)

Example 62 with HttpHeaders

use of io.netty.handler.codec.http.HttpHeaders in project janusgraph by JanusGraph.

the class HttpHMACAuthenticationHandlerTest method testChannelReadTokenAuth.

@Test
public void testChannelReadTokenAuth() throws Exception {
    final ChannelHandlerContext ctx = createMock(ChannelHandlerContext.class);
    final FullHttpRequest msg = createMock(FullHttpRequest.class);
    final HttpHeaders headers = createMock(HttpHeaders.class);
    final Authenticator authenticator = createMock(Authenticator.class);
    final String encodedToken = Base64.getEncoder().encodeToString("askdjhf823asdlkfsasd".getBytes());
    expect(msg.getMethod()).andReturn(HttpMethod.GET);
    expect(msg.headers()).andReturn(headers).anyTimes();
    expect(msg.getUri()).andReturn("/");
    expect(headers.get(eq("Authorization"))).andReturn("Token " + encodedToken);
    expect(ctx.fireChannelRead(isA(FullHttpRequest.class))).andReturn(ctx);
    expect(authenticator.authenticate(isA(Map.class))).andReturn(new AuthenticatedUser("foo"));
    final HttpHMACAuthenticationHandler handler = new HttpHMACAuthenticationHandler(authenticator);
    replayAll();
    handler.channelRead(ctx, (Object) msg);
    verifyAll();
}
Also used : HttpHeaders(io.netty.handler.codec.http.HttpHeaders) FullHttpRequest(io.netty.handler.codec.http.FullHttpRequest) ChannelHandlerContext(io.netty.channel.ChannelHandlerContext) Map(java.util.Map) AuthenticatedUser(org.apache.tinkerpop.gremlin.server.auth.AuthenticatedUser) Authenticator(org.apache.tinkerpop.gremlin.server.auth.Authenticator) Test(org.junit.Test)

Example 63 with HttpHeaders

use of io.netty.handler.codec.http.HttpHeaders in project janusgraph by JanusGraph.

the class HttpHMACAuthenticationHandlerTest method testChannelReadGetAuthToken.

@Test
public void testChannelReadGetAuthToken() throws Exception {
    final ChannelHandlerContext ctx = createMock(ChannelHandlerContext.class);
    final FullHttpRequest msg = createMock(FullHttpRequest.class);
    final HttpHeaders headers = createMock(HttpHeaders.class);
    final Authenticator authenticator = createMock(Authenticator.class);
    final ChannelFuture cf = createMock(ChannelFuture.class);
    final String encodedUserNameAndPass = Base64.getEncoder().encodeToString("user:pass".getBytes());
    final Capture<Map<String, String>> credMap = EasyMock.newCapture(CaptureType.ALL);
    expect(msg.getMethod()).andReturn(HttpMethod.GET);
    expect(msg.headers()).andReturn(headers).anyTimes();
    expect(msg.getUri()).andReturn("/session");
    expect(headers.get(eq("Authorization"))).andReturn("Basic " + encodedUserNameAndPass);
    expect(authenticator.authenticate(and(isA(Map.class), capture(credMap)))).andReturn(new AuthenticatedUser("foo"));
    expect(ctx.writeAndFlush(eqHttpStatus(OK))).andReturn(cf);
    expect(cf.addListener(ChannelFutureListener.CLOSE)).andReturn(null);
    expect(msg.release()).andReturn(false);
    final HttpHMACAuthenticationHandler handler = new HttpHMACAuthenticationHandler(authenticator);
    replayAll();
    handler.channelRead(ctx, (Object) msg);
    verifyAll();
    assertNotNull(credMap.getValue().get(HttpHMACAuthenticationHandler.PROPERTY_GENERATE_TOKEN));
}
Also used : ChannelFuture(io.netty.channel.ChannelFuture) HttpHeaders(io.netty.handler.codec.http.HttpHeaders) FullHttpRequest(io.netty.handler.codec.http.FullHttpRequest) ChannelHandlerContext(io.netty.channel.ChannelHandlerContext) Map(java.util.Map) AuthenticatedUser(org.apache.tinkerpop.gremlin.server.auth.AuthenticatedUser) Authenticator(org.apache.tinkerpop.gremlin.server.auth.Authenticator) Test(org.junit.Test)

Example 64 with HttpHeaders

use of io.netty.handler.codec.http.HttpHeaders in project riposte by Nike-Inc.

the class HttpUtils method extractCookies.

public static Set<Cookie> extractCookies(HttpRequest request) {
    Set<Cookie> cookies = new HashSet<>();
    HttpHeaders trailingHeaders = extractTrailingHeadersIfPossible(request);
    String cookieString = request.headers().get(COOKIE);
    if (cookieString == null && trailingHeaders != null)
        cookieString = trailingHeaders.get(COOKIE);
    if (cookieString != null)
        cookies.addAll(ServerCookieDecoder.LAX.decode(cookieString));
    return cookies;
}
Also used : Cookie(io.netty.handler.codec.http.cookie.Cookie) HttpHeaders(io.netty.handler.codec.http.HttpHeaders) HashSet(java.util.HashSet)

Example 65 with HttpHeaders

use of io.netty.handler.codec.http.HttpHeaders in project riposte by Nike-Inc.

the class RequestInfoForLoggingRiposteAdapterTest method getHeaderDelegatesToRequestInfo.

@Test
public void getHeaderDelegatesToRequestInfo() {
    String headerName = "someheader";
    String expectedValue = UUID.randomUUID().toString();
    HttpHeaders headersMock = mock(HttpHeaders.class);
    doReturn(expectedValue).when(headersMock).get(headerName);
    setFieldOnRequestInfo("headers", headersMock);
    assertThat(adapter.getHeader(headerName), is(expectedValue));
}
Also used : HttpHeaders(io.netty.handler.codec.http.HttpHeaders) DefaultHttpHeaders(io.netty.handler.codec.http.DefaultHttpHeaders) Test(org.junit.Test)

Aggregations

HttpHeaders (io.netty.handler.codec.http.HttpHeaders)128 Test (org.junit.Test)61 DefaultHttpHeaders (io.netty.handler.codec.http.DefaultHttpHeaders)49 FullHttpRequest (io.netty.handler.codec.http.FullHttpRequest)42 DefaultFullHttpRequest (io.netty.handler.codec.http.DefaultFullHttpRequest)34 AsciiString (io.netty.util.AsciiString)27 Test (org.testng.annotations.Test)25 ByteBuf (io.netty.buffer.ByteBuf)22 HttpServletResponse (javax.servlet.http.HttpServletResponse)17 ChannelPromise (io.netty.channel.ChannelPromise)15 FullHttpMessage (io.netty.handler.codec.http.FullHttpMessage)12 HttpRequest (io.netty.handler.codec.http.HttpRequest)12 Cookie (io.netty.handler.codec.http.cookie.Cookie)12 DefaultCookie (io.netty.handler.codec.http.cookie.DefaultCookie)12 Map (java.util.Map)12 HttpTest (org.asynchttpclient.testserver.HttpTest)12 Http2CodecUtil.getEmbeddedHttp2Exception (io.netty.handler.codec.http2.Http2CodecUtil.getEmbeddedHttp2Exception)11 Http2Runnable (io.netty.handler.codec.http2.Http2TestUtil.Http2Runnable)11 ChannelHandlerContext (io.netty.channel.ChannelHandlerContext)10 DefaultFullHttpResponse (io.netty.handler.codec.http.DefaultFullHttpResponse)10