Search in sources :

Example 1 with SaslAndHMACAuthenticator

use of org.janusgraph.graphdb.tinkerpop.gremlin.server.auth.SaslAndHMACAuthenticator in project janusgraph by JanusGraph.

the class SaslAndHMACAuthenticationHandlerTest method testHttpChannelReadWhenAuthenticatorHasBeenAdded.

@Test
public void testHttpChannelReadWhenAuthenticatorHasBeenAdded() throws Exception {
    final SaslAndHMACAuthenticator authenticator = createMock(SaslAndHMACAuthenticator.class);
    final HMACAuthenticator hmacAuth = createMock(HMACAuthenticator.class);
    final ChannelHandlerContext ctx = createMock(ChannelHandlerContext.class);
    final ChannelHandler mockHandler = createMock(ChannelHandler.class);
    final ChannelPipeline pipeline = createMock(ChannelPipeline.class);
    final HttpMessage msg = createMock(HttpMessage.class);
    final HttpHeaders headers = createMock(HttpHeaders.class);
    expect(authenticator.getHMACAuthenticator()).andReturn(hmacAuth);
    expect(authenticator.getSimpleAuthenticator()).andReturn(createMock(JanusGraphSimpleAuthenticator.class));
    expect(ctx.pipeline()).andReturn(pipeline);
    expect(pipeline.get("hmac_authenticator")).andReturn(mockHandler);
    expect(msg.headers()).andReturn(headers).times(2);
    expect(headers.get(isA(String.class))).andReturn(null).times(2);
    expect(ctx.fireChannelRead(eq(msg))).andReturn(ctx);
    replayAll();
    final SaslAndHMACAuthenticationHandler handler = new SaslAndHMACAuthenticationHandler(authenticator, null);
    handler.channelRead(ctx, msg);
}
Also used : HttpHeaders(io.netty.handler.codec.http.HttpHeaders) JanusGraphSimpleAuthenticator(org.janusgraph.graphdb.tinkerpop.gremlin.server.auth.JanusGraphSimpleAuthenticator) SaslAndHMACAuthenticator(org.janusgraph.graphdb.tinkerpop.gremlin.server.auth.SaslAndHMACAuthenticator) HMACAuthenticator(org.janusgraph.graphdb.tinkerpop.gremlin.server.auth.HMACAuthenticator) SaslAndHMACAuthenticator(org.janusgraph.graphdb.tinkerpop.gremlin.server.auth.SaslAndHMACAuthenticator) ChannelHandlerContext(io.netty.channel.ChannelHandlerContext) ChannelHandler(io.netty.channel.ChannelHandler) HttpMessage(io.netty.handler.codec.http.HttpMessage) ChannelPipeline(io.netty.channel.ChannelPipeline) Test(org.junit.jupiter.api.Test)

Example 2 with SaslAndHMACAuthenticator

use of org.janusgraph.graphdb.tinkerpop.gremlin.server.auth.SaslAndHMACAuthenticator in project janusgraph by JanusGraph.

the class SaslAndHMACAuthenticationHandlerTest method testHttpChannelReadWhenAuthenticatorHasNotBeenAdded.

@Test
public void testHttpChannelReadWhenAuthenticatorHasNotBeenAdded() throws Exception {
    final HMACAuthenticator hmacAuth = createMock(HMACAuthenticator.class);
    final SaslAndHMACAuthenticator authenticator = createMock(SaslAndHMACAuthenticator.class);
    final ChannelHandlerContext ctx = createMock(ChannelHandlerContext.class);
    final ChannelPipeline pipeline = createMock(ChannelPipeline.class);
    final HttpMessage msg = createMock(HttpMessage.class);
    final HttpHeaders headers = createMock(HttpHeaders.class);
    expect(authenticator.getHMACAuthenticator()).andReturn(hmacAuth);
    expect(authenticator.getSimpleAuthenticator()).andReturn(createMock(JanusGraphSimpleAuthenticator.class));
    expect(ctx.pipeline()).andReturn(pipeline).times(2);
    expect(pipeline.get("hmac_authenticator")).andReturn(null);
    expect(pipeline.addAfter(eq(PIPELINE_AUTHENTICATOR), eq("hmac_authenticator"), isA(ChannelHandler.class))).andReturn(null);
    expect(msg.headers()).andReturn(headers).times(2);
    expect(headers.get(isA(String.class))).andReturn(null).times(2);
    expect(ctx.fireChannelRead(eq(msg))).andReturn(ctx);
    replayAll();
    final SaslAndHMACAuthenticationHandler handler = new SaslAndHMACAuthenticationHandler(authenticator, null);
    handler.channelRead(ctx, msg);
}
Also used : HttpHeaders(io.netty.handler.codec.http.HttpHeaders) JanusGraphSimpleAuthenticator(org.janusgraph.graphdb.tinkerpop.gremlin.server.auth.JanusGraphSimpleAuthenticator) SaslAndHMACAuthenticator(org.janusgraph.graphdb.tinkerpop.gremlin.server.auth.SaslAndHMACAuthenticator) HMACAuthenticator(org.janusgraph.graphdb.tinkerpop.gremlin.server.auth.HMACAuthenticator) SaslAndHMACAuthenticator(org.janusgraph.graphdb.tinkerpop.gremlin.server.auth.SaslAndHMACAuthenticator) ChannelHandlerContext(io.netty.channel.ChannelHandlerContext) ChannelHandler(io.netty.channel.ChannelHandler) HttpMessage(io.netty.handler.codec.http.HttpMessage) ChannelPipeline(io.netty.channel.ChannelPipeline) Test(org.junit.jupiter.api.Test)

Aggregations

ChannelHandler (io.netty.channel.ChannelHandler)2 ChannelHandlerContext (io.netty.channel.ChannelHandlerContext)2 ChannelPipeline (io.netty.channel.ChannelPipeline)2 HttpHeaders (io.netty.handler.codec.http.HttpHeaders)2 HttpMessage (io.netty.handler.codec.http.HttpMessage)2 HMACAuthenticator (org.janusgraph.graphdb.tinkerpop.gremlin.server.auth.HMACAuthenticator)2 JanusGraphSimpleAuthenticator (org.janusgraph.graphdb.tinkerpop.gremlin.server.auth.JanusGraphSimpleAuthenticator)2 SaslAndHMACAuthenticator (org.janusgraph.graphdb.tinkerpop.gremlin.server.auth.SaslAndHMACAuthenticator)2 Test (org.junit.jupiter.api.Test)2