use of org.elasticsearch.common.settings.SecureString 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();
}
}
use of org.elasticsearch.common.settings.SecureString in project crate by crate.
the class UserAuthenticationMethodTest method testPasswordAuthenticationForNonExistingUser.
@Test
public void testPasswordAuthenticationForNonExistingUser() throws Exception {
PasswordAuthenticationMethod pwAuth = new PasswordAuthenticationMethod(this::userLookup);
expectedException.expectMessage("password authentication failed for user \"cr8\"");
pwAuth.authenticate("cr8", new SecureString("pw".toCharArray()), null);
}
use of org.elasticsearch.common.settings.SecureString in project crate by crate.
the class UserAuthenticationMethodTest method testPasswordAuthentication.
public void testPasswordAuthentication() throws Exception {
PasswordAuthenticationMethod pwAuth = new PasswordAuthenticationMethod(this::userLookup);
assertThat(pwAuth.name(), is("password"));
assertThat(pwAuth.authenticate("crate", new SecureString("pw".toCharArray()), null).name(), is("crate"));
}
Aggregations