Skip to content

Commit 66f19f0

Browse files
committed
Review remarks
Signed-off-by: Nils Bandener <[email protected]>
1 parent 2c321d6 commit 66f19f0

File tree

4 files changed

+23
-27
lines changed

4 files changed

+23
-27
lines changed

src/integrationTest/java/org/opensearch/security/privileges/int_tests/IndexAuthorizationReadOnlyIntTests.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -885,6 +885,8 @@ public void search_alias_pattern() throws Exception {
885885
public void search_alias_pattern_negation() throws Exception {
886886
try (TestRestClient restClient = cluster.getRestClient(user)) {
887887
TestRestClient.HttpResponse httpResponse = restClient.get("alias_*,-alias_ab1/_search?size=1000");
888+
// Another interesting effect: The negation on alias names does actually have no effect.
889+
// This is this time a bug in core. TODO: File issue
888890
assertThat(
889891
httpResponse,
890892
containsExactly(index_a1, index_a2, index_a3, index_b1, index_c1).at("hits.hits[*]._index")

src/integrationTest/java/org/opensearch/test/framework/cluster/TestRestClient.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -525,6 +525,11 @@ public void close() {
525525
// TODO: Is there anything to clean up here?
526526
}
527527

528+
/**
529+
* Helper method to create very simple dynamic JSON request bodies.
530+
* @param attributes Key-value pairs, keys on even indices, values on odd indices.
531+
* @return A request body that can be passed to the get(), post(), etc. methods.
532+
*/
528533
public static HttpEntity json(Object... attributes) {
529534
Map<String, Object> map = new HashMap<>();
530535

src/integrationTest/java/org/opensearch/test/framework/data/TestIndexOrAliasOrDatastream.java

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -28,18 +28,6 @@ public interface TestIndexOrAliasOrDatastream {
2828

2929
void delete(Client client);
3030

31-
default TestIndexOrAliasOrDatastream intersection(TestIndexOrAliasOrDatastream other) {
32-
if (other == this) {
33-
return this;
34-
}
35-
36-
if (!this.name().equals(other.name())) {
37-
throw new IllegalArgumentException("Cannot intersect different indices: " + this + " vs " + other);
38-
}
39-
40-
return this;
41-
}
42-
4331
static void createInitialTestObjects(LocalCluster cluster, TestIndexOrAliasOrDatastream... testIndexLikeArray) {
4432
try (Client client = cluster.getInternalNodeClient()) {
4533
for (TestIndexOrAliasOrDatastream testIndexLike : testIndexLikeArray) {

src/integrationTest/java/org/opensearch/test/framework/matcher/RestIndexMatchers.java

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import org.hamcrest.Matcher;
3030

3131
import org.opensearch.security.DefaultObjectMapper;
32+
import org.opensearch.security.support.ConfigConstants;
3233
import org.opensearch.test.framework.cluster.TestRestClient;
3334
import org.opensearch.test.framework.data.TestIndex;
3435
import 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

Comments
 (0)