SQL: Rename testing class
Renamed `RemoteCli` to `EmbeddedCli` because it now contains an embedded version of the SQL CLI. Original commit: elastic/x-pack-elasticsearch@c88a79a029
This commit is contained in:
parent
79d46d1d17
commit
c814e8e60c
|
@ -7,7 +7,7 @@ package org.elasticsearch.xpack.qa.sql.security;
|
||||||
|
|
||||||
import org.elasticsearch.common.settings.Settings;
|
import org.elasticsearch.common.settings.Settings;
|
||||||
import org.elasticsearch.xpack.qa.sql.cli.ErrorsTestCase;
|
import org.elasticsearch.xpack.qa.sql.cli.ErrorsTestCase;
|
||||||
import org.elasticsearch.xpack.qa.sql.cli.RemoteCli.SecurityConfig;
|
import org.elasticsearch.xpack.qa.sql.cli.EmbeddedCli.SecurityConfig;
|
||||||
|
|
||||||
public class CliErrorsIT extends ErrorsTestCase {
|
public class CliErrorsIT extends ErrorsTestCase {
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -7,7 +7,7 @@ package org.elasticsearch.xpack.qa.sql.security;
|
||||||
|
|
||||||
import org.elasticsearch.common.settings.Settings;
|
import org.elasticsearch.common.settings.Settings;
|
||||||
import org.elasticsearch.xpack.qa.sql.cli.FetchSizeTestCase;
|
import org.elasticsearch.xpack.qa.sql.cli.FetchSizeTestCase;
|
||||||
import org.elasticsearch.xpack.qa.sql.cli.RemoteCli.SecurityConfig;
|
import org.elasticsearch.xpack.qa.sql.cli.EmbeddedCli.SecurityConfig;
|
||||||
|
|
||||||
public class CliFetchSizeIT extends FetchSizeTestCase {
|
public class CliFetchSizeIT extends FetchSizeTestCase {
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -8,8 +8,8 @@ package org.elasticsearch.xpack.qa.sql.security;
|
||||||
import org.elasticsearch.common.CheckedConsumer;
|
import org.elasticsearch.common.CheckedConsumer;
|
||||||
import org.elasticsearch.common.io.PathUtils;
|
import org.elasticsearch.common.io.PathUtils;
|
||||||
import org.elasticsearch.xpack.qa.sql.cli.ErrorsTestCase;
|
import org.elasticsearch.xpack.qa.sql.cli.ErrorsTestCase;
|
||||||
import org.elasticsearch.xpack.qa.sql.cli.RemoteCli;
|
import org.elasticsearch.xpack.qa.sql.cli.EmbeddedCli;
|
||||||
import org.elasticsearch.xpack.qa.sql.cli.RemoteCli.SecurityConfig;
|
import org.elasticsearch.xpack.qa.sql.cli.EmbeddedCli.SecurityConfig;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.URISyntaxException;
|
import java.net.URISyntaxException;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
|
@ -66,7 +66,7 @@ public class CliSecurityIT extends SqlSecurityTestCase {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void queryWorksAsAdmin() throws Exception {
|
public void queryWorksAsAdmin() throws Exception {
|
||||||
try (RemoteCli cli = new RemoteCli(elasticsearchAddress(), true, adminSecurityConfig())) {
|
try (EmbeddedCli cli = new EmbeddedCli(elasticsearchAddress(), true, adminSecurityConfig())) {
|
||||||
assertThat(cli.command("SELECT * FROM test ORDER BY a"), containsString("a | b | c"));
|
assertThat(cli.command("SELECT * FROM test ORDER BY a"), containsString("a | b | c"));
|
||||||
assertEquals("---------------+---------------+---------------", cli.readLine());
|
assertEquals("---------------+---------------+---------------", cli.readLine());
|
||||||
assertThat(cli.readLine(), containsString("1 |2 |3"));
|
assertThat(cli.readLine(), containsString("1 |2 |3"));
|
||||||
|
@ -90,9 +90,9 @@ public class CliSecurityIT extends SqlSecurityTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void expectMatchesAdmin(String adminSql, String user, String userSql,
|
public void expectMatchesAdmin(String adminSql, String user, String userSql,
|
||||||
CheckedConsumer<RemoteCli, Exception> customizer) throws Exception {
|
CheckedConsumer<EmbeddedCli, Exception> customizer) throws Exception {
|
||||||
List<String> adminResult = new ArrayList<>();
|
List<String> adminResult = new ArrayList<>();
|
||||||
try (RemoteCli cli = new RemoteCli(elasticsearchAddress(), true, adminSecurityConfig())) {
|
try (EmbeddedCli cli = new EmbeddedCli(elasticsearchAddress(), true, adminSecurityConfig())) {
|
||||||
customizer.accept(cli);
|
customizer.accept(cli);
|
||||||
adminResult.add(cli.command(adminSql));
|
adminResult.add(cli.command(adminSql));
|
||||||
String line;
|
String line;
|
||||||
|
@ -104,7 +104,7 @@ public class CliSecurityIT extends SqlSecurityTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
Iterator<String> expected = adminResult.iterator();
|
Iterator<String> expected = adminResult.iterator();
|
||||||
try (RemoteCli cli = new RemoteCli(elasticsearchAddress(), true, userSecurity(user))) {
|
try (EmbeddedCli cli = new EmbeddedCli(elasticsearchAddress(), true, userSecurity(user))) {
|
||||||
customizer.accept(cli);
|
customizer.accept(cli);
|
||||||
assertTrue(expected.hasNext());
|
assertTrue(expected.hasNext());
|
||||||
assertEquals(expected.next(), cli.command(userSql));
|
assertEquals(expected.next(), cli.command(userSql));
|
||||||
|
@ -122,7 +122,7 @@ public class CliSecurityIT extends SqlSecurityTestCase {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void expectDescribe(Map<String, String> columns, String user) throws Exception {
|
public void expectDescribe(Map<String, String> columns, String user) throws Exception {
|
||||||
try (RemoteCli cli = new RemoteCli(elasticsearchAddress(), true, userSecurity(user))) {
|
try (EmbeddedCli cli = new EmbeddedCli(elasticsearchAddress(), true, userSecurity(user))) {
|
||||||
assertThat(cli.command("DESCRIBE test"), containsString("column | type"));
|
assertThat(cli.command("DESCRIBE test"), containsString("column | type"));
|
||||||
assertEquals("---------------+---------------", cli.readLine());
|
assertEquals("---------------+---------------", cli.readLine());
|
||||||
for (Map.Entry<String, String> column : columns.entrySet()) {
|
for (Map.Entry<String, String> column : columns.entrySet()) {
|
||||||
|
@ -134,7 +134,7 @@ public class CliSecurityIT extends SqlSecurityTestCase {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void expectShowTables(List<String> tables, String user) throws Exception {
|
public void expectShowTables(List<String> tables, String user) throws Exception {
|
||||||
try (RemoteCli cli = new RemoteCli(elasticsearchAddress(), true, userSecurity(user))) {
|
try (EmbeddedCli cli = new EmbeddedCli(elasticsearchAddress(), true, userSecurity(user))) {
|
||||||
String tablesOutput = cli.command("SHOW TABLES");
|
String tablesOutput = cli.command("SHOW TABLES");
|
||||||
assertThat(tablesOutput, containsString("name"));
|
assertThat(tablesOutput, containsString("name"));
|
||||||
assertThat(tablesOutput, containsString("type"));
|
assertThat(tablesOutput, containsString("type"));
|
||||||
|
@ -157,7 +157,7 @@ public class CliSecurityIT extends SqlSecurityTestCase {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void expectUnknownIndex(String user, String sql) throws Exception {
|
public void expectUnknownIndex(String user, String sql) throws Exception {
|
||||||
try (RemoteCli cli = new RemoteCli(elasticsearchAddress(), true, userSecurity(user))) {
|
try (EmbeddedCli cli = new EmbeddedCli(elasticsearchAddress(), true, userSecurity(user))) {
|
||||||
ErrorsTestCase.assertFoundOneProblem(cli.command(sql));
|
ErrorsTestCase.assertFoundOneProblem(cli.command(sql));
|
||||||
assertThat(cli.readLine(), containsString("Unknown index"));
|
assertThat(cli.readLine(), containsString("Unknown index"));
|
||||||
}
|
}
|
||||||
|
@ -169,14 +169,14 @@ public class CliSecurityIT extends SqlSecurityTestCase {
|
||||||
* Cause the CLI to skip its connection test on startup so we
|
* Cause the CLI to skip its connection test on startup so we
|
||||||
* can get a forbidden exception when we run the query.
|
* can get a forbidden exception when we run the query.
|
||||||
*/
|
*/
|
||||||
try (RemoteCli cli = new RemoteCli(elasticsearchAddress(), false, userSecurity(user))) {
|
try (EmbeddedCli cli = new EmbeddedCli(elasticsearchAddress(), false, userSecurity(user))) {
|
||||||
assertThat(cli.command(sql), containsString("is unauthorized for user [" + user + "]"));
|
assertThat(cli.command(sql), containsString("is unauthorized for user [" + user + "]"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void expectUnknownColumn(String user, String sql, String column) throws Exception {
|
public void expectUnknownColumn(String user, String sql, String column) throws Exception {
|
||||||
try (RemoteCli cli = new RemoteCli(elasticsearchAddress(), true, userSecurity(user))) {
|
try (EmbeddedCli cli = new EmbeddedCli(elasticsearchAddress(), true, userSecurity(user))) {
|
||||||
ErrorsTestCase.assertFoundOneProblem(cli.command(sql));
|
ErrorsTestCase.assertFoundOneProblem(cli.command(sql));
|
||||||
assertThat(cli.readLine(), containsString("Unknown column [" + column + "]" + ErrorsTestCase.END));
|
assertThat(cli.readLine(), containsString("Unknown column [" + column + "]" + ErrorsTestCase.END));
|
||||||
}
|
}
|
||||||
|
@ -186,7 +186,7 @@ public class CliSecurityIT extends SqlSecurityTestCase {
|
||||||
public void checkNoMonitorMain(String user) throws Exception {
|
public void checkNoMonitorMain(String user) throws Exception {
|
||||||
// Building the cli will attempt the connection and run the assertion
|
// Building the cli will attempt the connection and run the assertion
|
||||||
@SuppressWarnings("resource") // forceClose will close it
|
@SuppressWarnings("resource") // forceClose will close it
|
||||||
RemoteCli cli = new RemoteCli(elasticsearchAddress(), true, userSecurity(user)) {
|
EmbeddedCli cli = new EmbeddedCli(elasticsearchAddress(), true, userSecurity(user)) {
|
||||||
@Override
|
@Override
|
||||||
protected void assertConnectionTest() throws IOException {
|
protected void assertConnectionTest() throws IOException {
|
||||||
assertThat(readLine(), containsString("action [cluster:monitor/main] is unauthorized for user [" + user + "]"));
|
assertThat(readLine(), containsString("action [cluster:monitor/main] is unauthorized for user [" + user + "]"));
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
package org.elasticsearch.xpack.qa.sql.security;
|
package org.elasticsearch.xpack.qa.sql.security;
|
||||||
|
|
||||||
import org.elasticsearch.common.settings.Settings;
|
import org.elasticsearch.common.settings.Settings;
|
||||||
import org.elasticsearch.xpack.qa.sql.cli.RemoteCli.SecurityConfig;
|
import org.elasticsearch.xpack.qa.sql.cli.EmbeddedCli.SecurityConfig;
|
||||||
import org.elasticsearch.xpack.qa.sql.cli.SelectTestCase;
|
import org.elasticsearch.xpack.qa.sql.cli.SelectTestCase;
|
||||||
|
|
||||||
public class CliSelectIT extends SelectTestCase {
|
public class CliSelectIT extends SelectTestCase {
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
package org.elasticsearch.xpack.qa.sql.security;
|
package org.elasticsearch.xpack.qa.sql.security;
|
||||||
|
|
||||||
import org.elasticsearch.common.settings.Settings;
|
import org.elasticsearch.common.settings.Settings;
|
||||||
import org.elasticsearch.xpack.qa.sql.cli.RemoteCli.SecurityConfig;
|
import org.elasticsearch.xpack.qa.sql.cli.EmbeddedCli.SecurityConfig;
|
||||||
import org.elasticsearch.xpack.qa.sql.cli.ShowTestCase;
|
import org.elasticsearch.xpack.qa.sql.cli.ShowTestCase;
|
||||||
|
|
||||||
public class CliShowIT extends ShowTestCase {
|
public class CliShowIT extends ShowTestCase {
|
||||||
|
|
|
@ -12,7 +12,7 @@ import org.elasticsearch.common.CheckedConsumer;
|
||||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||||
import org.elasticsearch.common.xcontent.json.JsonXContent;
|
import org.elasticsearch.common.xcontent.json.JsonXContent;
|
||||||
import org.elasticsearch.test.rest.ESRestTestCase;
|
import org.elasticsearch.test.rest.ESRestTestCase;
|
||||||
import org.elasticsearch.xpack.qa.sql.cli.RemoteCli.SecurityConfig;
|
import org.elasticsearch.xpack.qa.sql.cli.EmbeddedCli.SecurityConfig;
|
||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
|
|
||||||
|
@ -31,14 +31,14 @@ public abstract class CliIntegrationTestCase extends ESRestTestCase {
|
||||||
return cluster.split(",")[0];
|
return cluster.split(",")[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
private RemoteCli cli;
|
private EmbeddedCli cli;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Asks the CLI Fixture to start a CLI instance.
|
* Asks the CLI Fixture to start a CLI instance.
|
||||||
*/
|
*/
|
||||||
@Before
|
@Before
|
||||||
public void startCli() throws IOException {
|
public void startCli() throws IOException {
|
||||||
cli = new RemoteCli(CliIntegrationTestCase.elasticsearchAddress(), true, securityConfig());
|
cli = new EmbeddedCli(CliIntegrationTestCase.elasticsearchAddress(), true, securityConfig());
|
||||||
}
|
}
|
||||||
|
|
||||||
@After
|
@After
|
||||||
|
|
|
@ -58,9 +58,8 @@ import static org.junit.Assert.fail;
|
||||||
* the CLI using packaging tests which is super "real" but not super fast
|
* the CLI using packaging tests which is super "real" but not super fast
|
||||||
* and doesn't run super frequently.
|
* and doesn't run super frequently.
|
||||||
*/
|
*/
|
||||||
public class RemoteCli implements Closeable {
|
public class EmbeddedCli implements Closeable {
|
||||||
// TODO rename this class to EmbeddedCli very soon
|
private static final Logger logger = Loggers.getLogger(EmbeddedCli.class);
|
||||||
private static final Logger logger = Loggers.getLogger(RemoteCli.class);
|
|
||||||
|
|
||||||
private final Thread exec;
|
private final Thread exec;
|
||||||
private final Cli cli;
|
private final Cli cli;
|
||||||
|
@ -73,7 +72,7 @@ public class RemoteCli implements Closeable {
|
||||||
*/
|
*/
|
||||||
private boolean closed = false;
|
private boolean closed = false;
|
||||||
|
|
||||||
public RemoteCli(String elasticsearchAddress, boolean checkConnectionOnStartup,
|
public EmbeddedCli(String elasticsearchAddress, boolean checkConnectionOnStartup,
|
||||||
@Nullable SecurityConfig security) throws IOException {
|
@Nullable SecurityConfig security) throws IOException {
|
||||||
PipedOutputStream outgoing = new PipedOutputStream();
|
PipedOutputStream outgoing = new PipedOutputStream();
|
||||||
PipedInputStream cliIn = new PipedInputStream(outgoing);
|
PipedInputStream cliIn = new PipedInputStream(outgoing);
|
Loading…
Reference in New Issue