Skip to content

Commit e77fb81

Browse files
committed
Tests and flags
1 parent a3e6429 commit e77fb81

File tree

2 files changed

+49
-18
lines changed

2 files changed

+49
-18
lines changed

x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/user/InternalUsers.java

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import org.elasticsearch.action.index.TransportIndexAction;
2929
import org.elasticsearch.action.search.TransportSearchAction;
3030
import org.elasticsearch.action.search.TransportSearchScrollAction;
31+
import org.elasticsearch.cluster.metadata.DataStream;
3132
import org.elasticsearch.index.reindex.ReindexAction;
3233
import org.elasticsearch.xpack.core.XPackPlugin;
3334
import org.elasticsearch.xpack.core.ilm.action.ILMActions;
@@ -245,18 +246,25 @@ public class InternalUsers {
245246
new RoleDescriptor(
246247
UsernamesField.LAZY_ROLLOVER_ROLE,
247248
new String[] {},
248-
new RoleDescriptor.IndicesPrivileges[] {
249-
RoleDescriptor.IndicesPrivileges.builder()
250-
.indices("*")
251-
.privileges(LazyRolloverAction.NAME)
252-
.allowRestrictedIndices(true)
253-
.build(),
254-
RoleDescriptor.IndicesPrivileges.builder()
255-
.indices("*")
256-
// TODO consider a more granular privilege for this
257-
.privileges("manage_failure_store")
258-
.allowRestrictedIndices(true)
259-
.build() },
249+
DataStream.isFailureStoreFeatureFlagEnabled()
250+
? new RoleDescriptor.IndicesPrivileges[] {
251+
RoleDescriptor.IndicesPrivileges.builder()
252+
.indices("*")
253+
.privileges(LazyRolloverAction.NAME)
254+
.allowRestrictedIndices(true)
255+
.build(),
256+
RoleDescriptor.IndicesPrivileges.builder()
257+
.indices("*")
258+
// needed to rollover failure store
259+
.privileges("manage_failure_store")
260+
.allowRestrictedIndices(true)
261+
.build() }
262+
: new RoleDescriptor.IndicesPrivileges[] {
263+
RoleDescriptor.IndicesPrivileges.builder()
264+
.indices("*")
265+
.privileges(LazyRolloverAction.NAME)
266+
.allowRestrictedIndices(true)
267+
.build(), },
260268
null,
261269
null,
262270
new String[] {},

x-pack/plugin/security/qa/security-trial/src/javaRestTest/java/org/elasticsearch/xpack/security/failurestore/FailureStoreSecurityRestIT.java

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import org.elasticsearch.test.cluster.ElasticsearchCluster;
2727
import org.elasticsearch.test.cluster.FeatureFlag;
2828
import org.elasticsearch.test.rest.ESRestTestCase;
29+
import org.elasticsearch.test.rest.ObjectPath;
2930
import org.elasticsearch.xcontent.json.JsonXContent;
3031
import org.elasticsearch.xpack.core.security.user.User;
3132
import org.elasticsearch.xpack.security.SecurityOnTrialLicenseRestTestCase;
@@ -41,6 +42,7 @@
4142
import static org.hamcrest.Matchers.containsInAnyOrder;
4243
import static org.hamcrest.Matchers.equalTo;
4344
import static org.hamcrest.Matchers.hasItem;
45+
import static org.hamcrest.Matchers.is;
4446

4547
public class FailureStoreSecurityRestIT extends ESRestTestCase {
4648

@@ -63,6 +65,8 @@ protected Settings restAdminSettings() {
6365
return Settings.builder().put(ThreadContext.PREFIX + ".Authorization", token).build();
6466
}
6567

68+
private static final String ASYNC_SEARCH_TIMEOUT = "30s";
69+
6670
private static final String DATA_ACCESS_USER = "data_access_user";
6771
private static final String STAR_READ_ONLY_USER = "star_read_only_user";
6872
private static final String FAILURE_STORE_ACCESS_USER = "failure_store_access_user";
@@ -794,7 +798,7 @@ public void testFailureStoreAccess() throws Exception {
794798
}
795799
}
796800
{
797-
Search request = new Search("*::failures,*");
801+
var request = new Search("*::failures,*");
798802
for (var user : users) {
799803
switch (user) {
800804
case FAILURE_STORE_ACCESS_USER:
@@ -852,11 +856,28 @@ private void expect(String user, Search search, int statusCode) {
852856
}
853857

854858
private void expect(String user, Search search, String... docIds) throws Exception {
855-
expect(user, search, response -> expectDocIds(response, docIds));
859+
expectSearch(user, search.toSearchRequest(), response -> expectDocIds(response, docIds));
860+
expectAsyncSearch(user, search.toAsyncSearchRequest(), docIds);
861+
}
862+
863+
@SuppressWarnings("unchecked")
864+
private void expectAsyncSearch(String user, Request request, String... docIds) throws IOException {
865+
Response response = performRequest(user, request);
866+
assertOK(response);
867+
ObjectPath resp = ObjectPath.createFromResponse(response);
868+
Boolean isRunning = resp.evaluate("is_running");
869+
Boolean isPartial = resp.evaluate("is_partial");
870+
assertThat(isRunning, is(false));
871+
assertThat(isPartial, is(false));
872+
873+
List<Object> hits = resp.evaluate("response.hits.hits");
874+
List<String> actual = hits.stream().map(h -> (String) ((Map<String, Object>) h).get("_id")).toList();
875+
876+
assertThat(actual, containsInAnyOrder(docIds));
856877
}
857878

858-
private void expect(String user, Search search, ThrowingConsumer<Response> consumer) throws Exception {
859-
consumer.accept(performRequest(user, search.toSearchRequest()));
879+
private void expectSearch(String user, Request request, ThrowingConsumer<Response> consumer) throws Exception {
880+
consumer.accept(performRequest(user, request));
860881
}
861882

862883
private record Search(String searchTarget, String pathParamString) {
@@ -869,11 +890,13 @@ Request toSearchRequest() {
869890
}
870891

871892
Request toAsyncSearchRequest() {
872-
return new Request("POST", Strings.format("/%s/_async_search%s", searchTarget, pathParamString));
893+
var pathParam = pathParamString.isEmpty()
894+
? "?wait_for_completion_timeout=" + ASYNC_SEARCH_TIMEOUT
895+
: pathParamString + "&wait_for_completion_timeout=" + ASYNC_SEARCH_TIMEOUT;
896+
return new Request("POST", Strings.format("/%s/_async_search%s", searchTarget, pathParam));
873897
}
874898
}
875899

876-
@SuppressWarnings("unchecked")
877900
private static void expectDocIds(Response response, String... docIds) throws IOException {
878901
assertOK(response);
879902
final SearchResponse searchResponse = SearchResponseUtils.parseSearchResponse(responseAsParser(response));

0 commit comments

Comments
 (0)