use of io.crate.auth.AlwaysOKAuthentication in project crate by crate.
the class PostgresNettyPublishPortTest method testPublishAddressOverride.
@Test
public void testPublishAddressOverride() {
// Check override for network.publish_host
Settings settingsWithCustomPublish = Settings.builder().put("network.publish_host", "cantbindtothis").build();
NetworkService networkService = new NetworkService(Collections.emptyList());
StubUserManager userManager = new StubUserManager();
PostgresNetty psql = new PostgresNetty(settingsWithCustomPublish, mock(SQLOperations.class), userManager, networkService, new AlwaysOKAuthentication(userName -> User.CRATE_USER), new NettyBootstrap(), mock(SslContextProvider.class));
try {
psql.doStart();
fail("Should have failed due to custom hostname");
} catch (BindTransportException e) {
// that's what we want
assertThat(e.getCause(), instanceOf(UnknownHostException.class));
} finally {
psql.doStop();
psql.close();
}
}
use of io.crate.auth.AlwaysOKAuthentication in project crate by crate.
the class PostgresNettyPublishPortTest method testBindAddressOverrideSetting.
@Test
public void testBindAddressOverrideSetting() {
// Check override for network.bind_host
Settings settingsWithCustomBind = Settings.builder().put("network.bind_host", "cantbindtothis").build();
NetworkService networkService = new NetworkService(Collections.emptyList());
StubUserManager userManager = new StubUserManager();
PostgresNetty psql = new PostgresNetty(settingsWithCustomBind, mock(SQLOperations.class), userManager, networkService, new AlwaysOKAuthentication(userManager), new NettyBootstrap(), mock(SslContextProvider.class));
try {
psql.doStart();
fail("Should have failed due to custom hostname");
} catch (BindPostgresException e) {
// that's what we want
assertThat(e.getCause(), instanceOf(UnknownHostException.class));
} finally {
psql.doStop();
psql.close();
}
}
use of io.crate.auth.AlwaysOKAuthentication in project crate by crate.
the class PostgresNettyPublishPortTest method testBindAndPublishAddressDefault.
@Test
public void testBindAndPublishAddressDefault() {
// First check if binding to a local works
NetworkService networkService = new NetworkService(Collections.emptyList());
StubUserManager userManager = new StubUserManager();
PostgresNetty psql = new PostgresNetty(Settings.EMPTY, mock(SQLOperations.class), userManager, networkService, new AlwaysOKAuthentication(userManager), new NettyBootstrap(), mock(SslContextProvider.class));
try {
psql.doStart();
} finally {
psql.doStop();
psql.close();
}
}
use of io.crate.auth.AlwaysOKAuthentication in project crate by crate.
the class PostgresWireProtocolTest method testBindMessageCanBeReadIfTypeForParamsIsUnknown.
@Test
public void testBindMessageCanBeReadIfTypeForParamsIsUnknown() throws Exception {
PostgresWireProtocol ctx = new PostgresWireProtocol(sqlOperations, sessionContext -> AccessControl.DISABLED, new AlwaysOKAuthentication(userName -> User.CRATE_USER), null);
channel = new EmbeddedChannel(ctx.decoder, ctx.handler);
ByteBuf buffer = Unpooled.buffer();
ClientMessages.sendStartupMessage(buffer, "doc");
// no type hints for parameters
ClientMessages.sendParseMessage(buffer, "S1", "select ?, ?", new int[0]);
List<Object> params = Arrays.asList(10, 20);
ClientMessages.sendBindMessage(buffer, "P1", "S1", params);
channel.writeInbound(buffer);
channel.releaseInbound();
Session session = sessions.get(0);
// If the query can be retrieved via portalName it means bind worked
assertThat(session.getQuery("P1"), is("select ?, ?"));
}
use of io.crate.auth.AlwaysOKAuthentication in project crate by crate.
the class PostgresWireProtocolTest method testDescribeStatementMessage.
@Test
public void testDescribeStatementMessage() throws Exception {
PostgresWireProtocol ctx = new PostgresWireProtocol(sqlOperations, sessionContext -> AccessControl.DISABLED, new AlwaysOKAuthentication(userName -> User.CRATE_USER), null);
channel = new EmbeddedChannel(ctx.decoder, ctx.handler);
{
ByteBuf buffer = Unpooled.buffer();
ClientMessages.sendStartupMessage(buffer, "doc");
ClientMessages.sendParseMessage(buffer, "S1", "select ? in (1, 2, 3)", new int[0]);
channel.writeInbound(buffer);
channel.releaseInbound();
// we're not interested in the startup, parse, or bind replies
channel.flushOutbound();
channel.releaseOutbound();
channel.outboundMessages().clear();
}
{
// try the describe statement variant
ByteBuf buffer = Unpooled.buffer();
ClientMessages.sendDescribeMessage(buffer, ClientMessages.DescribeType.STATEMENT, "S1");
channel.writeInbound(buffer);
channel.releaseInbound();
// we should get back a ParameterDescription message
channel.flushOutbound();
ByteBuf response = channel.readOutbound();
try {
assertThat(response.readByte(), is((byte) 't'));
assertThat(response.readInt(), is(10));
assertThat(response.readShort(), is((short) 1));
assertThat(response.readInt(), is(PGTypes.get(DataTypes.INTEGER).oid()));
} finally {
response.release();
}
// we should get back a RowDescription message
response = channel.readOutbound();
try {
assertThat(response.readByte(), is((byte) 'T'));
assertThat(response.readInt(), is(46));
assertThat(response.readShort(), is((short) 1));
assertThat(PostgresWireProtocol.readCString(response), is("($1 = ANY([1, 2, 3]))"));
assertThat(response.readInt(), is(0));
assertThat(response.readShort(), is((short) 0));
assertThat(response.readInt(), is(PGTypes.get(DataTypes.BOOLEAN).oid()));
assertThat(response.readShort(), is(PGTypes.get(DataTypes.BOOLEAN).typeLen()));
assertThat(response.readInt(), is(PGTypes.get(DataTypes.LONG).typeMod()));
assertThat(response.readShort(), is((short) 0));
} finally {
response.release();
}
}
}
Aggregations