Skip to content

Commit

Permalink
[Backport 2.x] Fixed test failures in FlsAndFieldMaskingTests (opense…
Browse files Browse the repository at this point in the history
  • Loading branch information
nibix authored Jul 12, 2024
1 parent 6f4b59d commit db44cce
Showing 1 changed file with 12 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,13 @@ public class FlsAndFieldMaskingTests {
.on("*")
);

static final TestSecurityConfig.User USER_FLS_INCLUDE_STARS = new TestSecurityConfig.User("fls_include_stars_reader").roles(
new TestSecurityConfig.Role("fls_include_stars_reader").clusterPermissions("cluster_composite_ops_ro")
.indexPermissions("read")
.fls(FIELD_STARS)
.on("*")
);

@ClassRule
public static final LocalCluster cluster = new LocalCluster.Builder().clusterManager(ClusterManager.THREE_CLUSTER_MANAGERS)
.anonymousAuth(false)
Expand All @@ -230,7 +237,8 @@ public class FlsAndFieldMaskingTests {
MASKED_ARTIST_LYRICS_READER,
ALL_INDICES_STRING_ARTIST_READER,
ALL_INDICES_STARS_LESS_THAN_ZERO_READER,
TWINS_FIRST_ARTIST_READER
TWINS_FIRST_ARTIST_READER,
USER_FLS_INCLUDE_STARS
)
.build();

Expand Down Expand Up @@ -840,13 +848,9 @@ public void getFieldCapabilities() throws IOException {
@Test
public void flsWithIncludesRulesIncludesFieldMappersFromPlugins() throws IOException {
String indexName = "fls_includes_index";
TestSecurityConfig.Role userRole = new TestSecurityConfig.Role("fls_include_stars_reader").clusterPermissions(
"cluster_composite_ops_ro"
).indexPermissions("read").fls(FIELD_STARS).on("*");
TestSecurityConfig.User user = createUserWithRole("fls_includes_user", userRole);
List<String> docIds = createIndexWithDocs(indexName, SONGS[0], SONGS[1]);

try (RestHighLevelClient restHighLevelClient = cluster.getRestHighLevelClient(user)) {
try (RestHighLevelClient restHighLevelClient = cluster.getRestHighLevelClient(USER_FLS_INCLUDE_STARS)) {
SearchRequest searchRequest = new SearchRequest(indexName);
SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
MatchAllQueryBuilder matchAllQueryBuilder = QueryBuilders.matchAllQuery();
Expand All @@ -863,11 +867,7 @@ public void flsWithIncludesRulesIncludesFieldMappersFromPlugins() throws IOExcep

@Test
public void testFlsOnAClosedAndReopenedIndex() throws IOException {
String indexName = "fls_includes_index";
TestSecurityConfig.Role userRole = new TestSecurityConfig.Role("fls_include_stars_reader").clusterPermissions(
"cluster_composite_ops_ro"
).indexPermissions("read").fls(FIELD_STARS).on("*");
TestSecurityConfig.User user = createUserWithRole("fls_includes_user", userRole);
String indexName = "fls_includes_index2";
List<String> docIds = createIndexWithDocs(indexName, SONGS[0], SONGS[1]);

try (TestRestClient client = cluster.getRestClient(ADMIN_USER)) {
Expand All @@ -876,7 +876,7 @@ public void testFlsOnAClosedAndReopenedIndex() throws IOException {
logsRule.assertThatContainExactly(indexName + " was closed. Setting metadataFields to empty. Closed index is not searchable.");
}

try (RestHighLevelClient restHighLevelClient = cluster.getRestHighLevelClient(user)) {
try (RestHighLevelClient restHighLevelClient = cluster.getRestHighLevelClient(USER_FLS_INCLUDE_STARS)) {
SearchRequest searchRequest = new SearchRequest(indexName);
SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
MatchAllQueryBuilder matchAllQueryBuilder = QueryBuilders.matchAllQuery();
Expand Down

0 comments on commit db44cce

Please sign in to comment.