use of io.netty.channel.embedded.EmbeddedChannel in project jackrabbit-oak by apache.
the class GetSegmentRequestEncoderTest method encodeRequest.
@Test
public void encodeRequest() throws Exception {
EmbeddedChannel channel = new EmbeddedChannel(new GetSegmentRequestEncoder());
channel.writeOutbound(new GetSegmentRequest("clientId", "segmentId"));
String message = (String) channel.readOutbound();
assertEquals(newGetSegmentRequest("clientId", "segmentId"), message);
}
use of io.netty.channel.embedded.EmbeddedChannel in project jackrabbit-oak by apache.
the class ClientFilterHandlerTest method disallowedClientsShouldNotBeServed.
@Test
public void disallowedClientsShouldNotBeServed() {
EmbeddedChannel channel = new EmbeddedChannel(new ClientFilterHandler(new ClientFilter() {
@Override
public boolean isAllowed(SocketAddress address) {
return false;
}
}));
channel.connect(new InetSocketAddress("127.0.0.2", 8080));
assertFalse(channel.isOpen());
}
use of io.netty.channel.embedded.EmbeddedChannel in project netty by netty.
the class SniHandlerTest method testFallbackToDefaultContext.
@Test
public void testFallbackToDefaultContext() throws Exception {
SslContext nettyContext = makeSslContext(provider, false);
SslContext leanContext = makeSslContext(provider, false);
SslContext leanContext2 = makeSslContext(provider, false);
try {
DomainNameMapping<SslContext> mapping = new DomainNameMappingBuilder<SslContext>(nettyContext).add("*.netty.io", nettyContext).add("*.LEANCLOUD.CN", leanContext).add("chat4.leancloud.cn", leanContext2).build();
SniHandler handler = new SniHandler(mapping);
EmbeddedChannel ch = new EmbeddedChannel(handler);
// invalid
byte[] message = { 22, 3, 1, 0, 0 };
try {
// Push the handshake message.
ch.writeInbound(Unpooled.wrappedBuffer(message));
} catch (Exception e) {
// expected
}
assertThat(ch.finish(), is(false));
assertThat(handler.hostname(), nullValue());
assertThat(handler.sslContext(), is(nettyContext));
} finally {
releaseAll(leanContext, leanContext2, nettyContext);
}
}
use of io.netty.channel.embedded.EmbeddedChannel in project netty by netty.
the class SniHandlerTest method testServerNameParsing.
@Test
public void testServerNameParsing() throws Exception {
SslContext nettyContext = makeSslContext(provider, false);
SslContext leanContext = makeSslContext(provider, false);
SslContext leanContext2 = makeSslContext(provider, false);
try {
DomainNameMapping<SslContext> mapping = new DomainNameMappingBuilder<SslContext>(nettyContext).add("*.netty.io", nettyContext).add("*.LEANCLOUD.CN", leanContext).add("chat4.leancloud.cn", leanContext2).build();
SniHandler handler = new SniHandler(mapping);
EmbeddedChannel ch = new EmbeddedChannel(handler);
// hex dump of a client hello packet, which contains hostname "CHAT4。LEANCLOUD。CN"
String tlsHandshakeMessageHex1 = "16030100";
// part 2
String tlsHandshakeMessageHex = "bd010000b90303a74225676d1814ba57faff3b366" + "3656ed05ee9dbb2a4dbb1bb1c32d2ea5fc39e0000000100008c0000001700150000164348" + "415434E380824C45414E434C4F5544E38082434E000b000403000102000a00340032000e0" + "00d0019000b000c00180009000a0016001700080006000700140015000400050012001300" + "0100020003000f0010001100230000000d0020001e0601060206030501050205030401040" + "20403030103020303020102020203000f00010133740000";
try {
// Push the handshake message.
// Decode should fail because SNI error
ch.writeInbound(Unpooled.wrappedBuffer(DatatypeConverter.parseHexBinary(tlsHandshakeMessageHex1)));
ch.writeInbound(Unpooled.wrappedBuffer(DatatypeConverter.parseHexBinary(tlsHandshakeMessageHex)));
fail();
} catch (DecoderException e) {
// expected
}
// This should produce an alert
assertTrue(ch.finish());
assertThat(handler.hostname(), is("chat4.leancloud.cn"));
assertThat(handler.sslContext(), is(leanContext));
for (; ; ) {
Object msg = ch.readOutbound();
if (msg == null) {
break;
}
ReferenceCountUtil.release(msg);
}
} finally {
releaseAll(leanContext, leanContext2, nettyContext);
}
}
use of io.netty.channel.embedded.EmbeddedChannel in project grpc-java by grpc.
the class NettyHandlerTestBase method initChannel.
/**
* Must be called by subclasses to initialize the handler and channel.
*/
protected final void initChannel(GrpcHttp2HeadersDecoder headersDecoder) throws Exception {
content = Unpooled.copiedBuffer("hello world", UTF_8);
frameWriter = spy(new DefaultHttp2FrameWriter());
frameReader = new DefaultHttp2FrameReader(headersDecoder);
handler = newHandler();
channel = new EmbeddedChannel(handler);
ctx = channel.pipeline().context(handler);
writeQueue = initWriteQueue();
}
Aggregations