Skip to content
This repository has been archived by the owner on Aug 2, 2022. It is now read-only.

Commit

Permalink
Support security plugin in comparison test (#760)
Browse files Browse the repository at this point in the history
* Support security plugin

* Wipe index permission issue
  • Loading branch information
dai-chen authored and joshuali925 committed Sep 28, 2020
1 parent 7c2e63a commit 72b5cf4
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import com.amazon.opendistroforelasticsearch.sql.correctness.runner.resultset.DBResult;
import java.io.IOException;
import java.util.List;
import java.util.Properties;
import org.elasticsearch.client.Request;
import org.elasticsearch.client.Response;
import org.elasticsearch.client.RestClient;
Expand All @@ -39,7 +40,7 @@ public class ESConnection implements DBConnection {
private final RestClient client;

public ESConnection(String connectionUrl, RestClient client) {
this.connection = new JDBCConnection("Elasticsearch", connectionUrl);
this.connection = new JDBCConnection("Elasticsearch", connectionUrl, populateProperties());
this.client = client;
}

Expand Down Expand Up @@ -84,6 +85,20 @@ public void close() {
connection.close();
}

private Properties populateProperties() {
Properties properties = new Properties();
if (Boolean.parseBoolean(System.getProperty("https", "false"))) {
properties.put("useSSL", "true");
}
if (!System.getProperty("user", "").isEmpty()) {
properties.put("user", System.getProperty("user"));
properties.put("password", System.getProperty("password", ""));
properties.put("trustSelfSigned", "true");
properties.put("hostnameVerification", "false");
}
return properties;
}

private void performRequest(Request request) {
try {
Response response = client.performRequest(request);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import java.sql.Statement;
import java.util.Arrays;
import java.util.List;
import java.util.Properties;
import org.json.JSONObject;

/**
Expand All @@ -49,20 +50,36 @@ public class JDBCConnection implements DBConnection {
*/
private final String connectionUrl;

/**
* JDBC driver config properties.
*/
private final Properties properties;

/**
* Current live connection
*/
private Connection connection;

public JDBCConnection(String databaseName, String connectionUrl) {
this(databaseName, connectionUrl, new Properties());
}

/**
* Create a JDBC connection with parameters given (but not connect to database at the moment).
* @param databaseName database name
* @param connectionUrl connection URL
* @param properties config properties
*/
public JDBCConnection(String databaseName, String connectionUrl, Properties properties) {
this.databaseName = databaseName;
this.connectionUrl = connectionUrl;
this.properties = properties;
}

@Override
public void connect() {
try {
connection = DriverManager.getConnection(connectionUrl);
connection = DriverManager.getConnection(connectionUrl, properties);
} catch (Exception e) {
throw new IllegalStateException("Failed to open connection", e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentFactory;
import org.elasticsearch.rest.RestStatus;
import org.elasticsearch.test.rest.ESRestTestCase;
import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.Before;
Expand All @@ -72,7 +71,7 @@
* <p>
* TODO: this base class should extends ODFERestTestCase
*/
public abstract class RestIntegTestCase extends ESRestTestCase {
public abstract class RestIntegTestCase extends ODFERestTestCase {

@Before
public void setUpIndices() throws Exception {
Expand Down Expand Up @@ -134,7 +133,7 @@ public static void dumpCoverage() {
*/
@AfterClass
public static void cleanUpIndices() throws IOException {
wipeAllIndices();
wipeAllODFEIndices();
wipeAllClusterSettings();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ protected void init() throws Exception {
*/
@AfterClass
public static void cleanUp() {
if (runner == null) {
return;
}

try {
TestConfig config = new TestConfig(emptyMap());
for (TestDataSet dataSet : config.getTestDataSets()) {
Expand Down

0 comments on commit 72b5cf4

Please sign in to comment.