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))));
}
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();
}
}
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();
}
}
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();
}
}
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");
}
Aggregations