Skip to content

Commit

Permalink
add protection for existsAlias with no index and no alias
Browse files Browse the repository at this point in the history
  • Loading branch information
javanna committed Jan 25, 2018
1 parent 55e87d8 commit 0f32d21
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,9 @@ static Request existsAlias(GetAliasesRequest getAliasesRequest) {
Params params = Params.builder();
params.withIndicesOptions(getAliasesRequest.indicesOptions());
params.withLocal(getAliasesRequest.local());
if (getAliasesRequest.indices().length == 0 && getAliasesRequest.aliases().length == 0) {
throw new IllegalArgumentException("existsAlias requires at least an alias or an index");
}
String endpoint = endpoint(getAliasesRequest.indices(), "_alias", getAliasesRequest.aliases());
return new Request("HEAD", endpoint, params.getParams(), null);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -988,7 +988,8 @@ public void testExistsAlias() {
GetAliasesRequest getAliasesRequest = new GetAliasesRequest();
String[] indices = randomIndicesNames(0, 5);
getAliasesRequest.indices(indices);
String[] aliases = randomIndicesNames(0, 5);
//the HEAD endpoint requires at least an alias or an index
String[] aliases = randomIndicesNames(indices.length == 0 ? 1 : 0, 5);
getAliasesRequest.aliases(aliases);
Map<String, String> expectedParams = new HashMap<>();
if (randomBoolean()) {
Expand All @@ -1015,6 +1016,12 @@ public void testExistsAlias() {
assertNull(request.getEntity());
}

public void testExistsAliasNoAliasNoIndex() {
GetAliasesRequest getAliasesRequest = new GetAliasesRequest();
IllegalArgumentException iae = expectThrows(IllegalArgumentException.class, () -> Request.existsAlias(getAliasesRequest));
assertEquals("existsAlias requires at least an alias or an index", iae.getMessage());
}

private static void assertToXContentBody(ToXContent expectedBody, HttpEntity actualEntity) throws IOException {
BytesReference expectedBytes = XContentHelper.toXContent(expectedBody, REQUEST_BODY_CONTENT_TYPE, false);
assertEquals(XContentType.JSON.mediaTypeWithoutParameters(), actualEntity.getContentType().getValue());
Expand Down

0 comments on commit 0f32d21

Please sign in to comment.