2929import org .hamcrest .Matcher ;
3030
3131import org .opensearch .security .DefaultObjectMapper ;
32+ import org .opensearch .security .support .ConfigConstants ;
3233import org .opensearch .test .framework .cluster .TestRestClient ;
3334import org .opensearch .test .framework .data .TestIndex ;
3435import org .opensearch .test .framework .data .TestIndexOrAliasOrDatastream ;
@@ -110,17 +111,17 @@ public static OnResponseIndexMatcher containsExactly(TestIndexOrAliasOrDatastrea
110111
111112 public static OnResponseIndexMatcher containsExactly (Collection <TestIndexOrAliasOrDatastream > testIndices ) {
112113 Map <String , TestIndexOrAliasOrDatastream > indexNameMap = new HashMap <>();
113- boolean containsOpenSearchIndices = false ;
114+ boolean containsOpenSearchSecurityIndex = false ;
114115
115116 for (TestIndexOrAliasOrDatastream testIndex : testIndices ) {
116117 if (testIndex == TestIndex .openSearchSecurityConfigIndex ()) {
117- containsOpenSearchIndices = true ;
118+ containsOpenSearchSecurityIndex = true ;
118119 } else {
119120 indexNameMap .put (testIndex .name (), testIndex );
120121 }
121122 }
122123
123- return new ContainsExactlyMatcher (indexNameMap , containsOpenSearchIndices );
124+ return new ContainsExactlyMatcher (indexNameMap , containsOpenSearchSecurityIndex );
124125 }
125126 }
126127
@@ -341,7 +342,7 @@ public int size() {
341342 if (!containsOpenSearchSecurityIndex ) {
342343 return expectedIndices .size ();
343344 } else {
344- throw new RuntimeException ( "Size cannot be exactly specified because containsOpenSearchIndices is true" ) ;
345+ return expectedIndices . size () + 1 ;
345346 }
346347 }
347348
@@ -368,7 +369,7 @@ protected Map<String, TestIndexOrAliasOrDatastream> testIndicesIntersection(
368369 continue ;
369370 }
370371
371- result .put (key , index1 . intersection ( index2 ) );
372+ result .put (key , index1 );
372373 }
373374
374375 return Collections .unmodifiableMap (result );
@@ -403,17 +404,17 @@ protected static String formatResponse(TestRestClient.HttpResponse response) {
403404 static class ContainsExactlyMatcher extends AbstractIndexMatcher implements OnResponseIndexMatcher {
404405 private static final Pattern DS_BACKING_INDEX_PATTERN = Pattern .compile ("\\ .ds-(.+)-[0-9]+" );
405406
406- ContainsExactlyMatcher (Map <String , TestIndexOrAliasOrDatastream > indexNameMap , boolean containsOpenSearchIndices ) {
407- super (indexNameMap , containsOpenSearchIndices );
407+ ContainsExactlyMatcher (Map <String , TestIndexOrAliasOrDatastream > indexNameMap , boolean containsOpenSearchSecurityIndex ) {
408+ super (indexNameMap , containsOpenSearchSecurityIndex );
408409 }
409410
410411 ContainsExactlyMatcher (
411412 Map <String , TestIndexOrAliasOrDatastream > indexNameMap ,
412- boolean containsOpenSearchIndices ,
413+ boolean containsOpenSearchSecurityIndex ,
413414 String jsonPath ,
414415 RestMatchers .HttpResponseMatcher statusCodeWhenEmpty
415416 ) {
416- super (indexNameMap , containsOpenSearchIndices , jsonPath , statusCodeWhenEmpty );
417+ super (indexNameMap , containsOpenSearchSecurityIndex , jsonPath , statusCodeWhenEmpty );
417418 }
418419
419420 @ Override
@@ -454,7 +455,7 @@ protected boolean matchesByIndices(
454455 for (Object object : collection ) {
455456 String index = object .toString ();
456457
457- if (containsOpenSearchSecurityIndex && (index .startsWith ( ".opendistro" ))) {
458+ if (containsOpenSearchSecurityIndex && (index .equals ( ConfigConstants . OPENDISTRO_SECURITY_DEFAULT_CONFIG_INDEX ))) {
458459 seenOpenSearchIndicesBuilder .add (index );
459460 } else if (index .startsWith (".ds-" )) {
460461 // We do a special treatment for data stream backing indices. We convert these to the normal data streams if expected
@@ -708,14 +709,14 @@ public OnUserIndexMatcher and(TestIndexOrAliasOrDatastream... testIndices) {
708709 */
709710 static class UnlimitedMatcher extends DiagnosingMatcher <Object > implements OnUserIndexMatcher {
710711
711- private final boolean containsOpenSearchIndices ;
712+ private final boolean containsOpenSearchSecurityIndex ;
712713
713714 UnlimitedMatcher () {
714- this .containsOpenSearchIndices = false ;
715+ this .containsOpenSearchSecurityIndex = false ;
715716 }
716717
717- UnlimitedMatcher (boolean containsOpenSearchIndices ) {
718- this .containsOpenSearchIndices = containsOpenSearchIndices ;
718+ UnlimitedMatcher (boolean containsOpenSearchSecurityIndex ) {
719+ this .containsOpenSearchSecurityIndex = containsOpenSearchSecurityIndex ;
719720 }
720721
721722 @ Override
@@ -743,7 +744,7 @@ public boolean isEmpty() {
743744
744745 @ Override
745746 public boolean containsOpenSearchSecurityIndex () {
746- return containsOpenSearchIndices ;
747+ return containsOpenSearchSecurityIndex ;
747748 }
748749
749750 @ Override
0 commit comments