Remove (deprecated) support for '+' in index expressions (elastic/x-pack-elasticsearch#1749)
Original commit: elastic/x-pack-elasticsearch@fc3fa2b842
This commit is contained in:
parent
40700f22b1
commit
6344bff121
|
@ -251,24 +251,18 @@ public class IndicesAndAliasesResolver {
|
||||||
//TODO Investigate reusing code from vanilla es to resolve index names and wildcards
|
//TODO Investigate reusing code from vanilla es to resolve index names and wildcards
|
||||||
private List<String> replaceWildcardsWithAuthorizedIndices(String[] indices, IndicesOptions indicesOptions, MetaData metaData,
|
private List<String> replaceWildcardsWithAuthorizedIndices(String[] indices, IndicesOptions indicesOptions, MetaData metaData,
|
||||||
List<String> authorizedIndices, boolean replaceWildcards) {
|
List<String> authorizedIndices, boolean replaceWildcards) {
|
||||||
//the order matters when it comes to + and -
|
//the order matters when it comes to exclusions
|
||||||
List<String> finalIndices = new ArrayList<>();
|
List<String> finalIndices = new ArrayList<>();
|
||||||
boolean wildcardSeen = false;
|
boolean wildcardSeen = false;
|
||||||
for (String index : indices) {
|
for (String index : indices) {
|
||||||
String aliasOrIndex;
|
String aliasOrIndex;
|
||||||
boolean minus = false;
|
boolean minus = false;
|
||||||
if (index.charAt(0) == '+') {
|
if (index.charAt(0) == '-' && wildcardSeen) {
|
||||||
aliasOrIndex = index.substring(1);
|
|
||||||
} else if (index.charAt(0) == '-') {
|
|
||||||
if (wildcardSeen) {
|
|
||||||
aliasOrIndex = index.substring(1);
|
aliasOrIndex = index.substring(1);
|
||||||
minus = true;
|
minus = true;
|
||||||
} else {
|
} else {
|
||||||
aliasOrIndex = index;
|
aliasOrIndex = index;
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
aliasOrIndex = index;
|
|
||||||
}
|
|
||||||
|
|
||||||
// we always need to check for date math expressions
|
// we always need to check for date math expressions
|
||||||
final String dateMathName = nameExpressionResolver.resolveDateMathExpression(aliasOrIndex);
|
final String dateMathName = nameExpressionResolver.resolveDateMathExpression(aliasOrIndex);
|
||||||
|
|
|
@ -237,9 +237,9 @@ public class IndicesAndAliasesResolverTests extends ESTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testExplicitMixedWildcardDashIndices() {
|
public void testExplicitMixedWildcardDashIndices() {
|
||||||
SearchRequest request = new SearchRequest("-index21", "-does_not_exist", "-index1*", "--index11", "+-index20");
|
SearchRequest request = new SearchRequest("-index21", "-does_not_exist", "-index1*", "--index11");
|
||||||
Set<String> indices = defaultIndicesResolver.resolve(request, metaData, buildAuthorizedIndices(userDashIndices, SearchAction.NAME));
|
Set<String> indices = defaultIndicesResolver.resolve(request, metaData, buildAuthorizedIndices(userDashIndices, SearchAction.NAME));
|
||||||
String[] expectedIndices = new String[]{"-index10", "-index21", "-index20", "-does_not_exist"};
|
String[] expectedIndices = new String[]{"-index10", "-index21", "-does_not_exist"};
|
||||||
assertThat(indices.size(), equalTo(expectedIndices.length));
|
assertThat(indices.size(), equalTo(expectedIndices.length));
|
||||||
assertThat(request.indices().length, equalTo(expectedIndices.length));
|
assertThat(request.indices().length, equalTo(expectedIndices.length));
|
||||||
assertThat(indices, hasItems(expectedIndices));
|
assertThat(indices, hasItems(expectedIndices));
|
||||||
|
@ -257,8 +257,8 @@ public class IndicesAndAliasesResolverTests extends ESTestCase {
|
||||||
assertThat(request.indices(), arrayContainingInAnyOrder(expectedIndices));
|
assertThat(request.indices(), arrayContainingInAnyOrder(expectedIndices));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testDashIndicesPlusAndMinus() {
|
public void testDashIndicesMinus() {
|
||||||
SearchRequest request = new SearchRequest("+-index10", "+-index11", "--index11", "-index20");
|
SearchRequest request = new SearchRequest("-index10", "-index11", "--index11", "-index20");
|
||||||
request.indicesOptions(IndicesOptions.fromOptions(false, randomBoolean(), randomBoolean(), randomBoolean()));
|
request.indicesOptions(IndicesOptions.fromOptions(false, randomBoolean(), randomBoolean(), randomBoolean()));
|
||||||
Set<String> indices = defaultIndicesResolver.resolve(request, metaData, buildAuthorizedIndices(userDashIndices, SearchAction.NAME));
|
Set<String> indices = defaultIndicesResolver.resolve(request, metaData, buildAuthorizedIndices(userDashIndices, SearchAction.NAME));
|
||||||
String[] expectedIndices = new String[]{"-index10", "-index11", "--index11", "-index20"};
|
String[] expectedIndices = new String[]{"-index10", "-index11", "--index11", "-index20"};
|
||||||
|
@ -268,6 +268,13 @@ public class IndicesAndAliasesResolverTests extends ESTestCase {
|
||||||
assertThat(request.indices(), arrayContainingInAnyOrder(expectedIndices));
|
assertThat(request.indices(), arrayContainingInAnyOrder(expectedIndices));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testDashIndicesPlus() {
|
||||||
|
SearchRequest request = new SearchRequest("+bar");
|
||||||
|
request.indicesOptions(IndicesOptions.fromOptions(true, false, randomBoolean(), randomBoolean()));
|
||||||
|
expectThrows(IndexNotFoundException.class,
|
||||||
|
() -> defaultIndicesResolver.resolve(request, metaData, buildAuthorizedIndices(userDashIndices, SearchAction.NAME)));
|
||||||
|
}
|
||||||
|
|
||||||
public void testDashNotExistingIndex() {
|
public void testDashNotExistingIndex() {
|
||||||
SearchRequest request = new SearchRequest("-does_not_exist");
|
SearchRequest request = new SearchRequest("-does_not_exist");
|
||||||
request.indicesOptions(IndicesOptions.fromOptions(false, randomBoolean(), randomBoolean(), randomBoolean()));
|
request.indicesOptions(IndicesOptions.fromOptions(false, randomBoolean(), randomBoolean(), randomBoolean()));
|
||||||
|
@ -389,8 +396,8 @@ public class IndicesAndAliasesResolverTests extends ESTestCase {
|
||||||
assertThat(request.indices(), arrayContainingInAnyOrder(replacedIndices));
|
assertThat(request.indices(), arrayContainingInAnyOrder(replacedIndices));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testResolveWildcardsPlusAndMinusExpandWilcardsOpenStrict() {
|
public void testResolveWildcardsExclusionsExpandWilcardsOpenStrict() {
|
||||||
SearchRequest request = new SearchRequest("*", "-foofoo*", "+barbaz", "+foob*");
|
SearchRequest request = new SearchRequest("*", "-foofoo*", "barbaz", "foob*");
|
||||||
request.indicesOptions(IndicesOptions.fromOptions(false, true, true, false));
|
request.indicesOptions(IndicesOptions.fromOptions(false, true, true, false));
|
||||||
Set<String> indices = defaultIndicesResolver.resolve(request, metaData, buildAuthorizedIndices(user, SearchAction.NAME));
|
Set<String> indices = defaultIndicesResolver.resolve(request, metaData, buildAuthorizedIndices(user, SearchAction.NAME));
|
||||||
String[] replacedIndices = new String[]{"bar", "barbaz"};
|
String[] replacedIndices = new String[]{"bar", "barbaz"};
|
||||||
|
@ -411,8 +418,8 @@ public class IndicesAndAliasesResolverTests extends ESTestCase {
|
||||||
assertThat(request.indices(), arrayContainingInAnyOrder(replacedIndices));
|
assertThat(request.indices(), arrayContainingInAnyOrder(replacedIndices));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testResolveWildcardsPlusAndMinusExpandWilcardsOpenAndClosedStrict() {
|
public void testResolveWildcardsExclusionExpandWilcardsOpenAndClosedStrict() {
|
||||||
SearchRequest request = new SearchRequest("*", "-foofoo*", "+barbaz");
|
SearchRequest request = new SearchRequest("*", "-foofoo*", "barbaz");
|
||||||
request.indicesOptions(IndicesOptions.fromOptions(false, randomBoolean(), true, true));
|
request.indicesOptions(IndicesOptions.fromOptions(false, randomBoolean(), true, true));
|
||||||
Set<String> indices = defaultIndicesResolver.resolve(request, metaData, buildAuthorizedIndices(user, SearchAction.NAME));
|
Set<String> indices = defaultIndicesResolver.resolve(request, metaData, buildAuthorizedIndices(user, SearchAction.NAME));
|
||||||
String[] replacedIndices = new String[]{"bar", "bar-closed", "barbaz"};
|
String[] replacedIndices = new String[]{"bar", "bar-closed", "barbaz"};
|
||||||
|
@ -422,8 +429,8 @@ public class IndicesAndAliasesResolverTests extends ESTestCase {
|
||||||
assertThat(request.indices(), arrayContainingInAnyOrder(replacedIndices));
|
assertThat(request.indices(), arrayContainingInAnyOrder(replacedIndices));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testResolveWildcardsPlusAndMinusExpandWilcardsOpenAndClosedIgnoreUnavailable() {
|
public void testResolveWildcardsExclusionExpandWilcardsOpenAndClosedIgnoreUnavailable() {
|
||||||
SearchRequest request = new SearchRequest("*", "-foofoo*", "+barbaz");
|
SearchRequest request = new SearchRequest("*", "-foofoo*", "barbaz");
|
||||||
request.indicesOptions(IndicesOptions.fromOptions(true, randomBoolean(), true, true));
|
request.indicesOptions(IndicesOptions.fromOptions(true, randomBoolean(), true, true));
|
||||||
Set<String> indices = defaultIndicesResolver.resolve(request, metaData, buildAuthorizedIndices(user, SearchAction.NAME));
|
Set<String> indices = defaultIndicesResolver.resolve(request, metaData, buildAuthorizedIndices(user, SearchAction.NAME));
|
||||||
String[] replacedIndices = new String[]{"bar", "bar-closed"};
|
String[] replacedIndices = new String[]{"bar", "bar-closed"};
|
||||||
|
|
|
@ -186,7 +186,7 @@ public class ReadActionsTests extends SecurityIntegTestCase {
|
||||||
//index1 is not authorized and referred to through wildcard, test111 and test112 are excluded
|
//index1 is not authorized and referred to through wildcard, test111 and test112 are excluded
|
||||||
createIndicesWithRandomAliases("test1", "test10", "test111", "test112", "test2", "index1");
|
createIndicesWithRandomAliases("test1", "test10", "test111", "test112", "test2", "index1");
|
||||||
|
|
||||||
SearchResponse searchResponse = client().prepareSearch("+test2", "+test11*", "index*", "-test2*").get();
|
SearchResponse searchResponse = client().prepareSearch("test2", "test11*", "index*", "-test2*").get();
|
||||||
assertReturnedIndices(searchResponse, "test111", "test112");
|
assertReturnedIndices(searchResponse, "test111", "test112");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -194,7 +194,7 @@ public class ReadActionsTests extends SecurityIntegTestCase {
|
||||||
//index1 is not authorized and referred to through wildcard, test111 and test112 are excluded
|
//index1 is not authorized and referred to through wildcard, test111 and test112 are excluded
|
||||||
createIndicesWithRandomAliases("test1", "test10", "test111", "test112", "test2", "index1");
|
createIndicesWithRandomAliases("test1", "test10", "test111", "test112", "test2", "index1");
|
||||||
|
|
||||||
SearchResponse searchResponse = client().prepareSearch("+test10", "+test11*", "index*", "-test111", "-test112").get();
|
SearchResponse searchResponse = client().prepareSearch("test10", "test11*", "index*", "-test111", "-test112").get();
|
||||||
assertReturnedIndices(searchResponse, "test10");
|
assertReturnedIndices(searchResponse, "test10");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue