use of com.couchbase.client.core.cnc.events.io.InvalidPacketDetectedEvent in project couchbase-jvm-clients by couchbase.
the class MemcacheProtocolVerificationHandler method handleEventAndCloseChannel.
/**
* Helper method to send the event into the event bus and then close the
* channel.
*
* @param ctx the context to use.
* @param msg the msg to export.
*/
private void handleEventAndCloseChannel(final ChannelHandlerContext ctx, final ByteBuf msg) {
final IoContext ioContext = new IoContext(endpointContext, ctx.channel().localAddress(), ctx.channel().remoteAddress(), endpointContext.bucket());
byte[] packet = ByteBufUtil.getBytes(msg);
ReferenceCountUtil.release(msg);
endpointContext.environment().eventBus().publish(new InvalidPacketDetectedEvent(ioContext, packet));
ctx.close();
}
use of com.couchbase.client.core.cnc.events.io.InvalidPacketDetectedEvent in project couchbase-jvm-clients by couchbase.
the class MemcacheProtocolVerificationHandlerTest method shouldCloseOnInvalidResponses.
/**
* Verifies that invalid responses are not let through.
*
* @param inputHolder the bad input packets.
*/
@ParameterizedTest(name = "{0}")
@MethodSource
void shouldCloseOnInvalidResponses(final InputHolder inputHolder) {
SimpleEventBus eventBus = new SimpleEventBus(true);
CoreEnvironment env = mock(CoreEnvironment.class);
EndpointContext ctx = mock(EndpointContext.class);
when(ctx.environment()).thenReturn(env);
when(env.eventBus()).thenReturn(eventBus);
final EmbeddedChannel channel = new EmbeddedChannel(new MemcacheProtocolVerificationHandler(ctx));
try {
channel.writeInbound(inputHolder.input);
assertFalse(channel.isOpen());
InvalidPacketDetectedEvent event = (InvalidPacketDetectedEvent) eventBus.publishedEvents().get(0);
assertEquals(Event.Severity.ERROR, event.severity());
assertEquals(Event.Category.IO.path(), event.category());
assertTrue(event.description().contains("Invalid Packet detected:"));
} finally {
channel.finishAndReleaseAll();
}
}
Aggregations