|
@@ -13,7 +13,6 @@ import org.elasticsearch.action.admin.indices.get.GetIndexRequest;
|
|
import org.elasticsearch.action.fieldcaps.FieldCapabilitiesAction;
|
|
import org.elasticsearch.action.fieldcaps.FieldCapabilitiesAction;
|
|
import org.elasticsearch.action.fieldcaps.FieldCapabilitiesRequest;
|
|
import org.elasticsearch.action.fieldcaps.FieldCapabilitiesRequest;
|
|
import org.elasticsearch.client.Request;
|
|
import org.elasticsearch.client.Request;
|
|
-import org.elasticsearch.client.ResponseException;
|
|
|
|
import org.elasticsearch.common.Strings;
|
|
import org.elasticsearch.common.Strings;
|
|
import org.elasticsearch.common.settings.Settings;
|
|
import org.elasticsearch.common.settings.Settings;
|
|
import org.elasticsearch.common.xcontent.XContentBuilder;
|
|
import org.elasticsearch.common.xcontent.XContentBuilder;
|
|
@@ -97,14 +96,14 @@ public abstract class SqlSecurityTestCase extends ESRestTestCase {
|
|
}
|
|
}
|
|
return Paths.get(auditLogFileString);
|
|
return Paths.get(auditLogFileString);
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
@SuppressForbidden(reason="security doesn't work with mock filesystem")
|
|
@SuppressForbidden(reason="security doesn't work with mock filesystem")
|
|
private static Path lookupRolledOverAuditLog() {
|
|
private static Path lookupRolledOverAuditLog() {
|
|
String auditLogFileString = System.getProperty("tests.audit.yesterday.logfile");
|
|
String auditLogFileString = System.getProperty("tests.audit.yesterday.logfile");
|
|
if (null == auditLogFileString) {
|
|
if (null == auditLogFileString) {
|
|
throw new IllegalStateException("tests.audit.yesterday.logfile must be set to run this test. It should be automatically "
|
|
throw new IllegalStateException("tests.audit.yesterday.logfile must be set to run this test. It should be automatically "
|
|
+ "set by gradle.");
|
|
+ "set by gradle.");
|
|
- }
|
|
|
|
|
|
+ }
|
|
return Paths.get(auditLogFileString);
|
|
return Paths.get(auditLogFileString);
|
|
}
|
|
}
|
|
|
|
|
|
@@ -120,7 +119,7 @@ public abstract class SqlSecurityTestCase extends ESRestTestCase {
|
|
* How much of the audit log was written before the test started.
|
|
* How much of the audit log was written before the test started.
|
|
*/
|
|
*/
|
|
private static long auditLogWrittenBeforeTestStart;
|
|
private static long auditLogWrittenBeforeTestStart;
|
|
-
|
|
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* If the audit log file rolled over. This is a rare case possible only at midnight.
|
|
* If the audit log file rolled over. This is a rare case possible only at midnight.
|
|
*/
|
|
*/
|
|
@@ -188,7 +187,7 @@ public abstract class SqlSecurityTestCase extends ESRestTestCase {
|
|
} catch (IOException e) {
|
|
} catch (IOException e) {
|
|
throw new RuntimeException(e);
|
|
throw new RuntimeException(e);
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
// The log file can roll over without being caught by assertLogs() method: in those tests where exceptions are being handled
|
|
// The log file can roll over without being caught by assertLogs() method: in those tests where exceptions are being handled
|
|
// and no audit logs being read (and, thus, assertLogs() is not called) - for example testNoMonitorMain() method: there are no
|
|
// and no audit logs being read (and, thus, assertLogs() is not called) - for example testNoMonitorMain() method: there are no
|
|
// calls to auditLogs(), and the method could run while the audit file is rolled over.
|
|
// calls to auditLogs(), and the method could run while the audit file is rolled over.
|
|
@@ -205,12 +204,7 @@ public abstract class SqlSecurityTestCase extends ESRestTestCase {
|
|
@AfterClass
|
|
@AfterClass
|
|
public static void wipeIndicesAfterTests() throws IOException {
|
|
public static void wipeIndicesAfterTests() throws IOException {
|
|
try {
|
|
try {
|
|
- adminClient().performRequest(new Request("DELETE", "*"));
|
|
|
|
- } catch (ResponseException e) {
|
|
|
|
- // 404 here just means we had no indexes
|
|
|
|
- if (e.getResponse().getStatusLine().getStatusCode() != 404) {
|
|
|
|
- throw e;
|
|
|
|
- }
|
|
|
|
|
|
+ wipeAllIndices();
|
|
} finally {
|
|
} finally {
|
|
// Clear the static state so other subclasses can reuse it later
|
|
// Clear the static state so other subclasses can reuse it later
|
|
oneTimeSetup = false;
|
|
oneTimeSetup = false;
|
|
@@ -586,7 +580,7 @@ public abstract class SqlSecurityTestCase extends ESRestTestCase {
|
|
if (sm != null) {
|
|
if (sm != null) {
|
|
sm.checkPermission(new SpecialPermission());
|
|
sm.checkPermission(new SpecialPermission());
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
BufferedReader[] logReaders = new BufferedReader[2];
|
|
BufferedReader[] logReaders = new BufferedReader[2];
|
|
AccessController.doPrivileged((PrivilegedAction<Void>) () -> {
|
|
AccessController.doPrivileged((PrivilegedAction<Void>) () -> {
|
|
try {
|
|
try {
|
|
@@ -604,7 +598,7 @@ public abstract class SqlSecurityTestCase extends ESRestTestCase {
|
|
throw new RuntimeException(e);
|
|
throw new RuntimeException(e);
|
|
}
|
|
}
|
|
});
|
|
});
|
|
-
|
|
|
|
|
|
+
|
|
// The "index" is used as a way of reading from both rolled over file and current audit file in order: rolled over file
|
|
// The "index" is used as a way of reading from both rolled over file and current audit file in order: rolled over file
|
|
// first, then the audit log file. Very rarely we will read from the rolled over file: when the test happened to run
|
|
// first, then the audit log file. Very rarely we will read from the rolled over file: when the test happened to run
|
|
// at midnight and the audit file rolled over during the test.
|
|
// at midnight and the audit file rolled over during the test.
|