use of io.crate.auth.Authentication in project crate by crate.
the class PostgresWireProtocolTest method testPasswordMessageAuthenticationProcess.
@Test
public void testPasswordMessageAuthenticationProcess() throws Exception {
PostgresWireProtocol ctx = new PostgresWireProtocol(mock(SQLOperations.class), sessionContext -> AccessControl.DISABLED, new Authentication() {
@Override
public AuthenticationMethod resolveAuthenticationType(String user, ConnectionProperties connectionProperties) {
return new AuthenticationMethod() {
@Nullable
@Override
public User authenticate(String userName, @Nullable SecureString passwd, ConnectionProperties connProperties) {
return null;
}
@Override
public String name() {
return "password";
}
};
}
}, null);
channel = new EmbeddedChannel(ctx.decoder, ctx.handler);
ByteBuf respBuf;
ByteBuf buffer = Unpooled.buffer();
ClientMessages.sendStartupMessage(buffer, "doc");
channel.writeInbound(buffer);
respBuf = channel.readOutbound();
try {
// AuthenticationCleartextPassword
assertThat((char) respBuf.readByte(), is('R'));
} finally {
respBuf.release();
}
buffer = Unpooled.buffer();
ClientMessages.sendPasswordMessage(buffer, "pw");
channel.writeInbound(buffer);
respBuf = channel.readOutbound();
try {
// Auth OK
assertThat((char) respBuf.readByte(), is('R'));
} finally {
respBuf.release();
}
}
Aggregations