Search in sources :

Example 21 with SessionContext

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);
}
Also used : SessionContext(io.crate.action.sql.SessionContext) Functions(io.crate.metadata.Functions) SqlExpressions(io.crate.testing.SqlExpressions) AbstractScalarFunctionsTest(io.crate.operation.scalar.AbstractScalarFunctionsTest) Test(org.junit.Test)

Example 22 with SessionContext

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());
}
Also used : SQLExecutor(io.crate.testing.SQLExecutor) QualifiedName(io.crate.sql.tree.QualifiedName) SessionContext(io.crate.action.sql.SessionContext) CrateDummyClusterServiceUnitTest(io.crate.test.integration.CrateDummyClusterServiceUnitTest) Test(org.junit.Test) ViewsMetadataTest(io.crate.metadata.view.ViewsMetadataTest)

Example 23 with SessionContext

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());
}
Also used : SQLExecutor(io.crate.testing.SQLExecutor) QualifiedName(io.crate.sql.tree.QualifiedName) SessionContext(io.crate.action.sql.SessionContext) CrateDummyClusterServiceUnitTest(io.crate.test.integration.CrateDummyClusterServiceUnitTest) Test(org.junit.Test) ViewsMetadataTest(io.crate.metadata.view.ViewsMetadataTest)

Example 24 with SessionContext

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"));
}
Also used : SQLExecutor(io.crate.testing.SQLExecutor) QualifiedName(io.crate.sql.tree.QualifiedName) SessionContext(io.crate.action.sql.SessionContext) TableInfo(io.crate.metadata.table.TableInfo) CrateDummyClusterServiceUnitTest(io.crate.test.integration.CrateDummyClusterServiceUnitTest) Test(org.junit.Test) ViewsMetadataTest(io.crate.metadata.view.ViewsMetadataTest)

Example 25 with SessionContext

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));
    }
}
Also used : Arrays(java.util.Arrays) SessionContext(io.crate.action.sql.SessionContext) PGTypes(io.crate.protocols.postgres.types.PGTypes) CrateDummyClusterServiceUnitTest(io.crate.test.integration.CrateDummyClusterServiceUnitTest) Provider(org.elasticsearch.common.inject.Provider) Unpooled(io.netty.buffer.Unpooled) DependencyCarrier(io.crate.planner.DependencyCarrier) Settings(org.elasticsearch.common.settings.Settings) After(org.junit.After) Map(java.util.Map) SecureString(org.elasticsearch.common.settings.SecureString) SQLOperations(io.crate.action.sql.SQLOperations) Matchers.isOneOf(org.hamcrest.Matchers.isOneOf) User(io.crate.user.User) StandardCharsets(java.nio.charset.StandardCharsets) List(java.util.List) Session(io.crate.action.sql.Session) Version(org.elasticsearch.Version) DataTypes(io.crate.types.DataTypes) UserManager(io.crate.user.UserManager) Matchers.is(org.hamcrest.Matchers.is) DescribeResult(io.crate.action.sql.DescribeResult) Mockito.any(org.mockito.Mockito.any) Mockito.mock(org.mockito.Mockito.mock) AccessControl(io.crate.auth.AccessControl) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) CompletableFuture(java.util.concurrent.CompletableFuture) JobsLogs(io.crate.execution.engine.collect.stats.JobsLogs) ArrayList(java.util.ArrayList) ByteBuf(io.netty.buffer.ByteBuf) Authentication(io.crate.auth.Authentication) SQLExecutor(io.crate.testing.SQLExecutor) StubUserManager(io.crate.user.StubUserManager) Nullable(javax.annotation.Nullable) Before(org.junit.Before) ArgumentMatchers.anyChar(org.mockito.ArgumentMatchers.anyChar) JobKilledException(io.crate.exceptions.JobKilledException) AuthenticationMethod(io.crate.auth.AuthenticationMethod) EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel) Test(org.junit.Test) Mockito.times(org.mockito.Mockito.times) Mockito.when(org.mockito.Mockito.when) Mockito.verify(org.mockito.Mockito.verify) Channel(io.netty.channel.Channel) TimeUnit(java.util.concurrent.TimeUnit) Mockito(org.mockito.Mockito) ChannelHandler(io.netty.channel.ChannelHandler) AlwaysOKAuthentication(io.crate.auth.AlwaysOKAuthentication) Collections(java.util.Collections) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) AlwaysOKAuthentication(io.crate.auth.AlwaysOKAuthentication) EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel) SecureString(org.elasticsearch.common.settings.SecureString) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) ChannelHandler(io.netty.channel.ChannelHandler) ByteBuf(io.netty.buffer.ByteBuf) SQLOperations(io.crate.action.sql.SQLOperations) Map(java.util.Map) CrateDummyClusterServiceUnitTest(io.crate.test.integration.CrateDummyClusterServiceUnitTest) Test(org.junit.Test)

Aggregations

SessionContext (io.crate.action.sql.SessionContext)31 Test (org.junit.Test)26 CrateDummyClusterServiceUnitTest (io.crate.test.integration.CrateDummyClusterServiceUnitTest)18 SQLExecutor (io.crate.testing.SQLExecutor)14 User (io.crate.user.User)13 List (java.util.List)13 ArrayList (java.util.ArrayList)12 DependencyCarrier (io.crate.planner.DependencyCarrier)11 DataTypes (io.crate.types.DataTypes)11 Arrays (java.util.Arrays)11 Map (java.util.Map)11 DescribeResult (io.crate.action.sql.DescribeResult)10 SQLOperations (io.crate.action.sql.SQLOperations)10 Session (io.crate.action.sql.Session)10 AccessControl (io.crate.auth.AccessControl)10 AlwaysOKAuthentication (io.crate.auth.AlwaysOKAuthentication)10 Authentication (io.crate.auth.Authentication)10 AuthenticationMethod (io.crate.auth.AuthenticationMethod)10 JobKilledException (io.crate.exceptions.JobKilledException)10 JobsLogs (io.crate.execution.engine.collect.stats.JobsLogs)10