use of io.crate.action.sql.SessionContext in project crate by crate.
the class CurrentSchemaFunctionTest method testNormalizeCurrentSchemaDefaultSchema.
@Test
public void testNormalizeCurrentSchemaDefaultSchema() throws Exception {
sqlExpressions = new SqlExpressions(tableSources, new SessionContext(0, Option.NONE, null));
functions = sqlExpressions.getInstance(Functions.class);
assertNormalize("current_schema()", isLiteral("doc"), false);
}
use of io.crate.action.sql.SessionContext in project crate by crate.
the class SchemasTest method testResolveTableInfoForInvalidFQNThrowsSchemaUnknownException.
@Test
public void testResolveTableInfoForInvalidFQNThrowsSchemaUnknownException() throws IOException {
SQLExecutor sqlExecutor = getSqlExecutorBuilderForTable(new RelationName("schema", "t")).build();
QualifiedName invalidFqn = QualifiedName.of("bogus_schema", "t");
SessionContext sessionContext = sqlExecutor.getSessionContext();
expectedException.expect(SchemaUnknownException.class);
expectedException.expectMessage("Schema 'bogus_schema' unknown");
sqlExecutor.schemas().resolveTableInfo(invalidFqn, Operation.READ, sessionContext.sessionUser(), sessionContext.searchPath());
}
use of io.crate.action.sql.SessionContext in project crate by crate.
the class SchemasTest method testResolveTableInfoThrowsRelationUnknownIfRelationIsNotInSearchPath.
@Test
public void testResolveTableInfoThrowsRelationUnknownIfRelationIsNotInSearchPath() throws IOException {
SQLExecutor sqlExecutor = getSqlExecutorBuilderForTable(new RelationName("schema", "t")).build();
QualifiedName table = QualifiedName.of("missing_table");
SessionContext sessionContext = sqlExecutor.getSessionContext();
expectedException.expect(RelationUnknown.class);
expectedException.expectMessage("Relation 'missing_table' unknown");
sqlExecutor.schemas().resolveTableInfo(table, Operation.READ, sessionContext.sessionUser(), sessionContext.searchPath());
}
use of io.crate.action.sql.SessionContext in project crate by crate.
the class SchemasTest method testResolveTableInfoLooksUpRelationInSearchPath.
@Test
public void testResolveTableInfoLooksUpRelationInSearchPath() throws IOException {
SQLExecutor sqlExecutor = getSqlExecutorBuilderForTable(new RelationName("schema", "t"), "doc", "schema").build();
QualifiedName tableQn = QualifiedName.of("t");
SessionContext sessionContext = sqlExecutor.getSessionContext();
TableInfo tableInfo = sqlExecutor.schemas().resolveTableInfo(tableQn, Operation.READ, sessionContext.sessionUser(), sessionContext.searchPath());
RelationName relation = tableInfo.ident();
assertThat(relation.schema(), is("schema"));
assertThat(relation.name(), is("t"));
}
use of io.crate.action.sql.SessionContext in project crate by crate.
the class PostgresWireProtocolTest method testSslRejection.
@Test
public void testSslRejection() {
PostgresWireProtocol ctx = new PostgresWireProtocol(mock(SQLOperations.class), sessionContext -> AccessControl.DISABLED, new AlwaysOKAuthentication(userName -> null), null);
channel = new EmbeddedChannel(ctx.decoder, ctx.handler);
ByteBuf buffer = Unpooled.buffer();
ClientMessages.sendSslReqMessage(buffer);
channel.writeInbound(buffer);
// We should get back an 'N'...
ByteBuf responseBuffer = channel.readOutbound();
try {
byte response = responseBuffer.readByte();
assertEquals(response, 'N');
} finally {
responseBuffer.release();
}
// ...and continue unencrypted (no ssl handler)
for (Map.Entry<String, ChannelHandler> entry : channel.pipeline()) {
assertThat(entry.getValue(), isOneOf(ctx.decoder, ctx.handler));
}
}
Aggregations