Skip to content

Commit

Permalink
Fixed test failures in FlsAndFieldMaskingTests (opensearch-project#4548)
Browse files Browse the repository at this point in the history
Signed-off-by: Nils Bandener <[email protected]>
  • Loading branch information
nibix authored Jul 11, 2024
1 parent 0b2109a commit 08d3a6c
Showing 1 changed file with 12 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,13 @@ public class FlsAndFieldMaskingTests {
"inclusive_exclusive_masked_user"
).roles(ROLE_ONLY_FIELD_TITLE_FLS, ROLE_NO_FIELD_TITLE_FLS, ROLE_ONLY_FIELD_TITLE_MASKED);

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 @@ -303,7 +310,8 @@ public class FlsAndFieldMaskingTests {
USER_BOTH_ONLY_AND_NO_FIELD_TITLE_FLS,
USER_BOTH_ONLY_FIELD_TITLE_FLS_ONLY_FIELD_TITLE_MASKED,
USER_BOTH_NO_FIELD_TITLE_FLS_ONLY_FIELD_TITLE_MASKED,
USER_ALL_ONLY_AND_NO_FIELD_TITLE_FLS_ONLY_FIELD_TITLE_MASKED
USER_ALL_ONLY_AND_NO_FIELD_TITLE_FLS_ONLY_FIELD_TITLE_MASKED,
USER_FLS_INCLUDE_STARS
)
.build();

Expand Down Expand Up @@ -1727,13 +1735,9 @@ private void assertProperSearchResponseForTitleFieldMaskingAndNoTitleFieldAndOnl
@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 @@ -1750,11 +1754,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 @@ -1763,7 +1763,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 08d3a6c

Please sign in to comment.