This commit is contained in:
parent
4b3b002942
commit
655e3d8f75
|
@ -17,7 +17,9 @@ import java.util.Map;
|
||||||
|
|
||||||
import static org.elasticsearch.xpack.core.security.authc.support.UsernamePasswordToken.basicAuthHeaderValue;
|
import static org.elasticsearch.xpack.core.security.authc.support.UsernamePasswordToken.basicAuthHeaderValue;
|
||||||
import static org.hamcrest.CoreMatchers.equalTo;
|
import static org.hamcrest.CoreMatchers.equalTo;
|
||||||
|
import static org.hamcrest.CoreMatchers.not;
|
||||||
import static org.hamcrest.CoreMatchers.notNullValue;
|
import static org.hamcrest.CoreMatchers.notNullValue;
|
||||||
|
import static org.hamcrest.Matchers.empty;
|
||||||
import static org.hamcrest.Matchers.is;
|
import static org.hamcrest.Matchers.is;
|
||||||
|
|
||||||
public class DataFrameAuditorIT extends DataFrameRestTestCase {
|
public class DataFrameAuditorIT extends DataFrameRestTestCase {
|
||||||
|
@ -49,7 +51,6 @@ public class DataFrameAuditorIT extends DataFrameRestTestCase {
|
||||||
setupUser(TEST_USER_NAME, Arrays.asList("data_frame_transforms_admin", DATA_ACCESS_ROLE));
|
setupUser(TEST_USER_NAME, Arrays.asList("data_frame_transforms_admin", DATA_ACCESS_ROLE));
|
||||||
}
|
}
|
||||||
|
|
||||||
@AwaitsFix(bugUrl = "https://github.com/elastic/elasticsearch/issues/40594")
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public void testAuditorWritesAudits() throws Exception {
|
public void testAuditorWritesAudits() throws Exception {
|
||||||
String transformId = "simplePivotForAudit";
|
String transformId = "simplePivotForAudit";
|
||||||
|
@ -62,17 +63,26 @@ public class DataFrameAuditorIT extends DataFrameRestTestCase {
|
||||||
startAndWaitForTransform(transformId, dataFrameIndex, BASIC_AUTH_VALUE_DATA_FRAME_ADMIN_WITH_SOME_DATA_ACCESS);
|
startAndWaitForTransform(transformId, dataFrameIndex, BASIC_AUTH_VALUE_DATA_FRAME_ADMIN_WITH_SOME_DATA_ACCESS);
|
||||||
|
|
||||||
// Make sure we wrote to the audit
|
// Make sure we wrote to the audit
|
||||||
assertTrue(indexExists(DataFrameInternalIndex.AUDIT_INDEX));
|
final Request request = new Request("GET", DataFrameInternalIndex.AUDIT_INDEX + "/_search");
|
||||||
refreshIndex(DataFrameInternalIndex.AUDIT_INDEX);
|
|
||||||
Request request = new Request("GET", DataFrameInternalIndex.AUDIT_INDEX + "/_search");
|
|
||||||
request.setJsonEntity("{\"query\":{\"term\":{\"transform_id\":\"simplePivotForAudit\"}}}");
|
request.setJsonEntity("{\"query\":{\"term\":{\"transform_id\":\"simplePivotForAudit\"}}}");
|
||||||
Map<String, Object> response = entityAsMap(client().performRequest(request));
|
assertBusy(() -> {
|
||||||
Map<?, ?> hitRsp = (Map<?, ?>) ((List<?>) ((Map<?, ?>)response.get("hits")).get("hits")).get(0);
|
assertTrue(indexExists(DataFrameInternalIndex.AUDIT_INDEX));
|
||||||
Map<String, Object> source = (Map<String, Object>)hitRsp.get("_source");
|
});
|
||||||
assertThat(source.get("transform_id"), equalTo(transformId));
|
// Since calls to write the Auditor are sent and forgot (async) we could have returned from the start,
|
||||||
assertThat(source.get("level"), equalTo("info"));
|
// finished the job (as this is a very short DF job), all without the audit being fully written.
|
||||||
assertThat(source.get("message"), is(notNullValue()));
|
assertBusy(() -> {
|
||||||
assertThat(source.get("node_name"), is(notNullValue()));
|
refreshIndex(DataFrameInternalIndex.AUDIT_INDEX);
|
||||||
assertThat(source.get("timestamp"), is(notNullValue()));
|
Map<String, Object> response = entityAsMap(client().performRequest(request));
|
||||||
|
List<?> hitList = ((List<?>) ((Map<?, ?>)response.get("hits")).get("hits"));
|
||||||
|
assertThat(hitList, is(not(empty())));
|
||||||
|
Map<?, ?> hitRsp = (Map<?, ?>) hitList.get(0);
|
||||||
|
Map<String, Object> source = (Map<String, Object>)hitRsp.get("_source");
|
||||||
|
assertThat(source.get("transform_id"), equalTo(transformId));
|
||||||
|
assertThat(source.get("level"), equalTo("info"));
|
||||||
|
assertThat(source.get("message"), is(notNullValue()));
|
||||||
|
assertThat(source.get("node_name"), is(notNullValue()));
|
||||||
|
assertThat(source.get("timestamp"), is(notNullValue()));
|
||||||
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue