Search in sources :

Example 1 with StubUserManager

use of io.crate.user.StubUserManager in project crate by crate.

the class BatchPortalTest method testEachStatementReceivesCorrectParams.

@Test
public void testEachStatementReceivesCorrectParams() throws Throwable {
    SQLExecutor sqlExecutor = SQLExecutor.builder(clusterService).addTable("create table t1 (x int)").build();
    Plan insertPlan = new Plan() {

        @Override
        public StatementType type() {
            return StatementType.INSERT;
        }

        @Override
        public void executeOrFail(DependencyCarrier executor, PlannerContext plannerContext, RowConsumer consumer, Row params, SubQueryResults subQueryResults) {
            consumer.accept(InMemoryBatchIterator.of(params, null), null);
        }
    };
    Planner planner = new Planner(Settings.EMPTY, clusterService, sqlExecutor.nodeCtx, new TableStats(), null, null, sqlExecutor.schemas(), new StubUserManager(), mock(SessionSettingRegistry.class)) {

        @Override
        public Plan plan(AnalyzedStatement analyzedStatement, PlannerContext plannerContext) {
            return insertPlan;
        }
    };
    DependencyCarrier executor = mock(DependencyCarrier.class, Answers.RETURNS_MOCKS);
    Session session = new Session(sqlExecutor.nodeCtx, sqlExecutor.analyzer, planner, new JobsLogs(() -> false), false, executor, AccessControl.DISABLED, SessionContext.systemSessionContext());
    session.parse("S_1", "insert into t1(x) values(1)", Collections.emptyList());
    session.bind("Portal", "S_1", Collections.emptyList(), null);
    final ArrayList<Object[]> s1Rows = new ArrayList<>();
    session.execute("Portal", 0, new BaseResultReceiver() {

        @Override
        public void setNextRow(Row row) {
            s1Rows.add(row.materialize());
        }
    });
    session.parse("S_2", "insert into t1(x) values(?)", Collections.emptyList());
    session.bind("Portal", "S_2", Collections.singletonList(2), null);
    final ArrayList<Object[]> s2Rows = new ArrayList<>();
    session.execute("Portal", 0, new BaseResultReceiver() {

        @Override
        public void setNextRow(Row row) {
            s2Rows.add(row.materialize());
        }
    });
    session.sync().get(5, TimeUnit.SECONDS);
    assertThat(s1Rows, contains(emptyArray()));
    assertThat(s2Rows, contains(arrayContaining(is(2))));
}
Also used : DependencyCarrier(io.crate.planner.DependencyCarrier) SubQueryResults(io.crate.planner.operators.SubQueryResults) ArrayList(java.util.ArrayList) Plan(io.crate.planner.Plan) TableStats(io.crate.statistics.TableStats) StubUserManager(io.crate.user.StubUserManager) SessionSettingRegistry(io.crate.metadata.settings.session.SessionSettingRegistry) PlannerContext(io.crate.planner.PlannerContext) SQLExecutor(io.crate.testing.SQLExecutor) BaseResultReceiver(io.crate.action.sql.BaseResultReceiver) Planner(io.crate.planner.Planner) AnalyzedStatement(io.crate.analyze.AnalyzedStatement) RowConsumer(io.crate.data.RowConsumer) Row(io.crate.data.Row) JobsLogs(io.crate.execution.engine.collect.stats.JobsLogs) Session(io.crate.action.sql.Session) CrateDummyClusterServiceUnitTest(io.crate.test.integration.CrateDummyClusterServiceUnitTest) Test(org.junit.Test)

Example 2 with StubUserManager

use of io.crate.user.StubUserManager 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();
    }
}
Also used : PostgresNetty.resolvePublishPort(io.crate.protocols.postgres.PostgresNetty.resolvePublishPort) User(io.crate.user.User) BindTransportException(org.elasticsearch.transport.BindTransportException) Test(org.junit.Test) BindHttpException(org.elasticsearch.http.BindHttpException) UnknownHostException(java.net.UnknownHostException) Matchers.instanceOf(org.hamcrest.Matchers.instanceOf) NetworkService(org.elasticsearch.common.network.NetworkService) InetAddress.getByName(java.net.InetAddress.getByName) Settings(org.elasticsearch.common.settings.Settings) TransportAddress(org.elasticsearch.common.transport.TransportAddress) Arrays.asList(java.util.Arrays.asList) NettyBootstrap(io.crate.netty.NettyBootstrap) Matchers.equalTo(org.hamcrest.Matchers.equalTo) SslContextProvider(io.crate.protocols.ssl.SslContextProvider) ESTestCase(org.elasticsearch.test.ESTestCase) AlwaysOKAuthentication(io.crate.auth.AlwaysOKAuthentication) SQLOperations(io.crate.action.sql.SQLOperations) StubUserManager(io.crate.user.StubUserManager) Collections(java.util.Collections) Mockito.mock(org.mockito.Mockito.mock) AlwaysOKAuthentication(io.crate.auth.AlwaysOKAuthentication) NetworkService(org.elasticsearch.common.network.NetworkService) BindTransportException(org.elasticsearch.transport.BindTransportException) SslContextProvider(io.crate.protocols.ssl.SslContextProvider) SQLOperations(io.crate.action.sql.SQLOperations) Settings(org.elasticsearch.common.settings.Settings) StubUserManager(io.crate.user.StubUserManager) NettyBootstrap(io.crate.netty.NettyBootstrap) Test(org.junit.Test)

Example 3 with StubUserManager

use of io.crate.user.StubUserManager 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();
    }
}
Also used : AlwaysOKAuthentication(io.crate.auth.AlwaysOKAuthentication) NetworkService(org.elasticsearch.common.network.NetworkService) SslContextProvider(io.crate.protocols.ssl.SslContextProvider) SQLOperations(io.crate.action.sql.SQLOperations) Settings(org.elasticsearch.common.settings.Settings) StubUserManager(io.crate.user.StubUserManager) NettyBootstrap(io.crate.netty.NettyBootstrap) Test(org.junit.Test)

Example 4 with StubUserManager

use of io.crate.user.StubUserManager 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();
    }
}
Also used : AlwaysOKAuthentication(io.crate.auth.AlwaysOKAuthentication) NetworkService(org.elasticsearch.common.network.NetworkService) SslContextProvider(io.crate.protocols.ssl.SslContextProvider) SQLOperations(io.crate.action.sql.SQLOperations) StubUserManager(io.crate.user.StubUserManager) NettyBootstrap(io.crate.netty.NettyBootstrap) Test(org.junit.Test)

Example 5 with StubUserManager

use of io.crate.user.StubUserManager in project crate by crate.

the class PrivilegesDCLAnalyzerTest method testGrantWithoutUserManagementEnabledThrowsException.

@Test
public void testGrantWithoutUserManagementEnabledThrowsException() {
    e = SQLExecutor.builder(clusterService).setUserManager(new StubUserManager()).build();
    expectedException.expect(UnsupportedOperationException.class);
    expectedException.expectMessage("User management is not enabled");
    e.analyze("GRANT DQL TO test");
}
Also used : StubUserManager(io.crate.user.StubUserManager) CrateDummyClusterServiceUnitTest(io.crate.test.integration.CrateDummyClusterServiceUnitTest) Test(org.junit.Test)

Aggregations

StubUserManager (io.crate.user.StubUserManager)6 Test (org.junit.Test)6 SQLOperations (io.crate.action.sql.SQLOperations)4 AlwaysOKAuthentication (io.crate.auth.AlwaysOKAuthentication)4 NettyBootstrap (io.crate.netty.NettyBootstrap)4 SslContextProvider (io.crate.protocols.ssl.SslContextProvider)4 NetworkService (org.elasticsearch.common.network.NetworkService)4 Settings (org.elasticsearch.common.settings.Settings)3 CrateDummyClusterServiceUnitTest (io.crate.test.integration.CrateDummyClusterServiceUnitTest)2 BaseResultReceiver (io.crate.action.sql.BaseResultReceiver)1 Session (io.crate.action.sql.Session)1 AnalyzedStatement (io.crate.analyze.AnalyzedStatement)1 Row (io.crate.data.Row)1 RowConsumer (io.crate.data.RowConsumer)1 JobsLogs (io.crate.execution.engine.collect.stats.JobsLogs)1 SessionSettingRegistry (io.crate.metadata.settings.session.SessionSettingRegistry)1 DependencyCarrier (io.crate.planner.DependencyCarrier)1 Plan (io.crate.planner.Plan)1 Planner (io.crate.planner.Planner)1 PlannerContext (io.crate.planner.PlannerContext)1