Skip to content

Commit

Permalink
Add test showing it is working for admin
Browse files Browse the repository at this point in the history
Signed-off-by: Derek Ho <dxho@amazon.com>
  • Loading branch information
derek-ho committed Jun 11, 2024
1 parent d83395e commit d0b0882
Showing 1 changed file with 18 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,7 @@

import static org.apache.http.HttpStatus.SC_CREATED;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.aMapWithSize;
import static org.hamcrest.Matchers.allOf;
import static org.hamcrest.Matchers.arrayContainingInAnyOrder;
import static org.hamcrest.Matchers.arrayWithSize;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.hasKey;
import static org.hamcrest.Matchers.not;
import static org.hamcrest.Matchers.nullValue;
import static org.hamcrest.Matchers.*;
import static org.opensearch.action.admin.indices.alias.IndicesAliasesRequest.AliasActions.Type.ADD;
import static org.opensearch.action.support.WriteRequest.RefreshPolicy.IMMEDIATE;
import static org.opensearch.client.RequestOptions.DEFAULT;
Expand Down Expand Up @@ -446,6 +438,7 @@ public void shouldPerformCatIndices_positive() throws IOException {

@Test
public void shouldPerformCatAliases_positive() throws IOException {
// DNFOF works for limited access user
try (RestHighLevelClient restHighLevelClient = cluster.getRestHighLevelClient(LIMITED_USER)) {
Request getAliasesRequest = new Request("GET", "/_cat/aliases");
Response getAliasesResponse = restHighLevelClient.getLowLevelClient().performRequest(getAliasesRequest);
Expand All @@ -459,6 +452,22 @@ public void shouldPerformCatAliases_positive() throws IOException {
assertThat(aliases.get(0), not(containsString("horrible_songs")));

}

try (RestHighLevelClient restHighLevelClient = cluster.getRestHighLevelClient(ADMIN_USER)) {
Request getAliasesRequest = new Request("GET", "/_cat/aliases");
Response getAliasesResponse = restHighLevelClient.getLowLevelClient().performRequest(getAliasesRequest);
List<String> aliases = new BufferedReader(new InputStreamReader(getAliasesResponse.getEntity().getContent())).lines()
.collect(Collectors.toList());

// Admin has access to all
assertThat(getAliasesResponse.getStatusLine().getStatusCode(), equalTo(200));
// Aliases have one entry for each index
// This response is [(both-indices: marvelous_songs), (both-indices: horrible_songs), (forbidden-index: horrible_songs)]
assertThat(aliases.size(), equalTo(3));
assertThat(aliases, hasItem(containsString("marvelous_songs")));
assertThat(aliases, hasItem(containsString("horrible_songs")));

}
}

@Test
Expand Down

0 comments on commit d0b0882

Please sign in to comment.