PostgreSQLAuthenticationEngine implements AuthenticationEngine { @Override public AuthenticationResult auth(final ChannelHandlerContext context, final PacketPayload payload) { if (SSL_REQUEST_PAYLOAD_LENGTH == payload.getByteBuf().markReaderIndex().readInt() && SSL_REQUEST_CODE == payload.getByteBuf().readInt()) { context.writeAndFlush(new PostgreSQLSSLNegativePacket()); return AuthenticationResultBuilder.continued(); } payload.getByteBuf().resetReaderIndex(); if (!startupMessageReceived.get()) { return beforeStartupMessage(context, (PostgreSQLPacketPayload) payload); } else { return afterStartupMessage(context, (PostgreSQLPacketPayload) payload); } }  @Override int handshake(final ChannelHandlerContext context); @Override AuthenticationResult auth(final ChannelHandlerContext context, final PacketPayload payload);  }
@Test public void assertSSLNegative() { ByteBuf byteBuf = createByteBuf(8, 8); byteBuf.writeInt(8); byteBuf.writeInt(80877103); PacketPayload payload = new PostgreSQLPacketPayload(byteBuf); AuthenticationResult actual = new PostgreSQLAuthenticationEngine().auth(mock(ChannelHandlerContext.class), payload); assertThat(actual.isFinished(), is(false)); }
@Test public void assertDatabaseNotExist() { PostgreSQLPacketPayload payload = new PostgreSQLPacketPayload(createByteBuf(32, 512)); payload.writeInt4(64); payload.writeInt4(196608); payload.writeStringNul("user"); payload.writeStringNul(username); payload.writeStringNul("database"); payload.writeStringNul("sharding_db"); AuthenticationResult actual = new PostgreSQLAuthenticationEngine().auth(mock(ChannelHandlerContext.class), payload); assertThat(actual.isFinished(), is(false)); }
@Test public void assertUserNotSet() { PostgreSQLPacketPayload payload = new PostgreSQLPacketPayload(createByteBuf(8, 512)); payload.writeInt4(64); payload.writeInt4(196608); AuthenticationResult actual = new PostgreSQLAuthenticationEngine().auth(mock(ChannelHandlerContext.class), payload); assertThat(actual.isFinished(), is(false)); }