Skip to content

Commit c69e9e7

Browse files
committed
[TEST] Re-enable ReadActionsTests
Enable this integration test again, with a set timeout on each search action. Relates: elastic#53340
1 parent 59ae46f commit c69e9e7

File tree

1 file changed

+54
-37
lines changed
  • x-pack/plugin/security/src/internalClusterTest/java/org/elasticsearch/xpack/security/authz

1 file changed

+54
-37
lines changed

x-pack/plugin/security/src/internalClusterTest/java/org/elasticsearch/xpack/security/authz/ReadActionsTests.java

+54-37
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import org.elasticsearch.action.termvectors.MultiTermVectorsResponse;
1919
import org.elasticsearch.action.termvectors.TermVectorsAction;
2020
import org.elasticsearch.client.Requests;
21+
import org.elasticsearch.core.TimeValue;
2122
import org.elasticsearch.index.IndexNotFoundException;
2223
import org.elasticsearch.search.SearchHit;
2324
import org.elasticsearch.test.SecurityIntegTestCase;
@@ -26,7 +27,6 @@
2627
import java.util.ArrayList;
2728
import java.util.List;
2829

29-
import static org.apache.lucene.util.LuceneTestCase.AwaitsFix;
3030
import static org.elasticsearch.test.SecurityTestsUtils.assertAuthorizationExceptionDefaultUsers;
3131
import static org.elasticsearch.test.SecurityTestsUtils.assertThrowsAuthorizationExceptionDefaultUsers;
3232
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertNoSearchHits;
@@ -35,7 +35,6 @@
3535
import static org.hamcrest.core.IsInstanceOf.instanceOf;
3636
import static org.hamcrest.number.OrderingComparison.greaterThan;
3737

38-
@AwaitsFix(bugUrl = "https://github.com/elastic/elasticsearch/issues/53340")
3938
public class ReadActionsTests extends SecurityIntegTestCase {
4039

4140
@Override
@@ -53,156 +52,166 @@ public void testSearchForAll() {
5352
//index1 is not authorized and referred to through wildcard
5453
createIndicesWithRandomAliases("test1", "test2", "test3", "index1");
5554

56-
SearchResponse searchResponse = client().prepareSearch().get();
55+
SearchResponse searchResponse = trySearch();
5756
assertReturnedIndices(searchResponse, "test1", "test2", "test3");
5857
}
5958

6059
public void testSearchForWildcard() {
6160
//index1 is not authorized and referred to through wildcard
6261
createIndicesWithRandomAliases("test1", "test2", "test3", "index1");
6362

64-
SearchResponse searchResponse = client().prepareSearch("*").get();
63+
SearchResponse searchResponse = trySearch("*");
6564
assertReturnedIndices(searchResponse, "test1", "test2", "test3");
6665
}
6766

6867
public void testSearchNonAuthorizedWildcard() {
6968
//wildcard doesn't match any authorized index
7069
createIndicesWithRandomAliases("test1", "test2", "index1", "index2");
71-
assertNoSearchHits(client().prepareSearch("index*").get());
70+
assertNoSearchHits(trySearch("index*"));
7271
}
7372

7473
public void testSearchNonAuthorizedWildcardDisallowNoIndices() {
7574
//wildcard doesn't match any authorized index
7675
createIndicesWithRandomAliases("test1", "test2", "index1", "index2");
77-
IndexNotFoundException e = expectThrows(IndexNotFoundException.class, () -> client().prepareSearch("index*")
78-
.setIndicesOptions(IndicesOptions.fromOptions(randomBoolean(), false, true, randomBoolean())).get());
76+
IndexNotFoundException e = expectThrows(
77+
IndexNotFoundException.class,
78+
() -> trySearch(IndicesOptions.fromOptions(randomBoolean(), false, true, randomBoolean()), "index*")
79+
);
7980
assertEquals("no such index [index*]", e.getMessage());
8081
}
8182

8283
public void testEmptyClusterSearchForAll() {
83-
assertNoSearchHits(client().prepareSearch().get());
84+
assertNoSearchHits(trySearch());
8485
}
8586

8687
public void testEmptyClusterSearchForAllDisallowNoIndices() {
87-
IndexNotFoundException e = expectThrows(IndexNotFoundException.class, () -> client().prepareSearch()
88-
.setIndicesOptions(IndicesOptions.fromOptions(randomBoolean(), false, true, randomBoolean())).get());
88+
IndexNotFoundException e = expectThrows(
89+
IndexNotFoundException.class,
90+
() -> trySearch(IndicesOptions.fromOptions(randomBoolean(), false, true, randomBoolean()))
91+
);
8992
assertEquals("no such index [[]]", e.getMessage());
9093
}
9194

9295
public void testEmptyClusterSearchForWildcard() {
93-
SearchResponse searchResponse = client().prepareSearch("*").get();
96+
SearchResponse searchResponse = trySearch("*");
9497
assertNoSearchHits(searchResponse);
9598
}
9699

97100
public void testEmptyClusterSearchForWildcardDisallowNoIndices() {
98-
IndexNotFoundException e = expectThrows(IndexNotFoundException.class, () -> client().prepareSearch("*")
99-
.setIndicesOptions(IndicesOptions.fromOptions(randomBoolean(), false, true, randomBoolean())).get());
101+
IndexNotFoundException e = expectThrows(
102+
IndexNotFoundException.class,
103+
() -> trySearch(IndicesOptions.fromOptions(randomBoolean(), false, true, randomBoolean()), "*")
104+
);
100105
assertEquals("no such index [*]", e.getMessage());
101106
}
102107

103108
public void testEmptyAuthorizedIndicesSearchForAll() {
104109
createIndicesWithRandomAliases("index1", "index2");
105-
assertNoSearchHits(client().prepareSearch().get());
110+
assertNoSearchHits(trySearch());
106111
}
107112

108113
public void testEmptyAuthorizedIndicesSearchForAllDisallowNoIndices() {
109114
createIndicesWithRandomAliases("index1", "index2");
110-
IndexNotFoundException e = expectThrows(IndexNotFoundException.class, () -> client().prepareSearch()
111-
.setIndicesOptions(IndicesOptions.fromOptions(randomBoolean(), false, true, randomBoolean())).get());
115+
IndexNotFoundException e = expectThrows(
116+
IndexNotFoundException.class,
117+
() -> trySearch(IndicesOptions.fromOptions(randomBoolean(), false, true, randomBoolean()))
118+
);
112119
assertEquals("no such index [[]]", e.getMessage());
113120
}
114121

115122
public void testEmptyAuthorizedIndicesSearchForWildcard() {
116123
createIndicesWithRandomAliases("index1", "index2");
117-
assertNoSearchHits(client().prepareSearch("*").get());
124+
assertNoSearchHits(trySearch("*"));
118125
}
119126

120127
public void testEmptyAuthorizedIndicesSearchForWildcardDisallowNoIndices() {
121128
createIndicesWithRandomAliases("index1", "index2");
122-
IndexNotFoundException e = expectThrows(IndexNotFoundException.class, () -> client().prepareSearch("*")
123-
.setIndicesOptions(IndicesOptions.fromOptions(randomBoolean(), false, true, randomBoolean())).get());
129+
IndexNotFoundException e = expectThrows(
130+
IndexNotFoundException.class,
131+
() -> trySearch(IndicesOptions.fromOptions(randomBoolean(), false, true, randomBoolean()), "*")
132+
);
124133
assertEquals("no such index [*]", e.getMessage());
125134
}
126135

127136
public void testExplicitNonAuthorizedIndex() {
128137
createIndicesWithRandomAliases("test1", "test2", "index1");
129-
assertThrowsAuthorizationExceptionDefaultUsers(client().prepareSearch("test*", "index1")::get, SearchAction.NAME);
138+
assertThrowsAuthorizationExceptionDefaultUsers(() -> trySearch("test*", "index1"), SearchAction.NAME);
130139
}
131140

132141
public void testIndexNotFound() {
133142
createIndicesWithRandomAliases("test1", "test2", "index1");
134-
assertThrowsAuthorizationExceptionDefaultUsers(client().prepareSearch("missing")::get, SearchAction.NAME);
143+
assertThrowsAuthorizationExceptionDefaultUsers(() -> trySearch("missing"), SearchAction.NAME);
135144
}
136145

137146
public void testIndexNotFoundIgnoreUnavailable() {
138147
IndicesOptions indicesOptions = IndicesOptions.lenientExpandOpen();
139148
createIndicesWithRandomAliases("test1", "test2", "index1");
140149

141150
String index = randomFrom("test1", "test2");
142-
assertReturnedIndices(client().prepareSearch("missing", index).setIndicesOptions(indicesOptions).get(), index);
151+
assertReturnedIndices(trySearch(indicesOptions, "missing", index), index);
143152

144-
assertReturnedIndices(client().prepareSearch("missing", "test*").setIndicesOptions(indicesOptions).get(), "test1", "test2");
153+
assertReturnedIndices(trySearch(indicesOptions, "missing", "test*"), "test1", "test2");
145154

146-
assertReturnedIndices(client().prepareSearch("missing_*", "test*").setIndicesOptions(indicesOptions).get(), "test1", "test2");
155+
assertReturnedIndices(trySearch(indicesOptions, "missing_*", "test*"), "test1", "test2");
147156

148157
//an unauthorized index is the same as a missing one
149-
assertNoSearchHits(client().prepareSearch("missing").setIndicesOptions(indicesOptions).get());
158+
assertNoSearchHits(trySearch(indicesOptions, "missing"));
150159

151-
assertNoSearchHits(client().prepareSearch("index1").setIndicesOptions(indicesOptions).get());
160+
assertNoSearchHits(trySearch(indicesOptions, "index1"));
152161

153-
assertNoSearchHits(client().prepareSearch("missing", "index1").setIndicesOptions(indicesOptions).get());
162+
assertNoSearchHits(trySearch(indicesOptions, "missing", "index1"));
154163

155-
assertNoSearchHits(client().prepareSearch("does_not_match_any_*").setIndicesOptions(indicesOptions).get());
164+
assertNoSearchHits(trySearch(indicesOptions, "does_not_match_any_*"));
156165

157-
assertNoSearchHits(client().prepareSearch("does_not_match_any_*", "index1").setIndicesOptions(indicesOptions).get());
166+
assertNoSearchHits(trySearch(indicesOptions, "does_not_match_any_*", "index1"));
158167

159-
assertNoSearchHits(client().prepareSearch("index*").setIndicesOptions(indicesOptions).get());
168+
assertNoSearchHits(trySearch(indicesOptions, "index*"));
160169

161-
assertNoSearchHits(client().prepareSearch("index*", "missing").setIndicesOptions(indicesOptions).get());
170+
assertNoSearchHits(trySearch(indicesOptions, "index*", "missing"));
162171
}
163172

164173
public void testExplicitExclusion() {
165174
//index1 is not authorized and referred to through wildcard, test2 is excluded
166175
createIndicesWithRandomAliases("test1", "test2", "test3", "index1");
167176

168-
SearchResponse searchResponse = client().prepareSearch("*", "-test2").get();
177+
SearchResponse searchResponse = trySearch("*", "-test2");
169178
assertReturnedIndices(searchResponse, "test1", "test3");
170179
}
171180

172181
public void testWildcardExclusion() {
173182
//index1 is not authorized and referred to through wildcard, test2 is excluded
174183
createIndicesWithRandomAliases("test1", "test2", "test21", "test3", "index1");
175184

176-
SearchResponse searchResponse = client().prepareSearch("*", "-test2*").get();
185+
SearchResponse searchResponse = trySearch("*", "-test2*");
177186
assertReturnedIndices(searchResponse, "test1", "test3");
178187
}
179188

180189
public void testInclusionAndWildcardsExclusion() {
181190
//index1 is not authorized and referred to through wildcard, test111 and test112 are excluded
182191
createIndicesWithRandomAliases("test1", "test10", "test111", "test112", "test2", "index1");
183192

184-
SearchResponse searchResponse = client().prepareSearch("test1*", "index*", "-test11*").get();
193+
SearchResponse searchResponse = trySearch("test1*", "index*", "-test11*");
185194
assertReturnedIndices(searchResponse, "test1", "test10");
186195
}
187196

188197
public void testExplicitAndWildcardsInclusionAndWildcardExclusion() {
189198
//index1 is not authorized and referred to through wildcard, test111 and test112 are excluded
190199
createIndicesWithRandomAliases("test1", "test10", "test111", "test112", "test2", "index1");
191200

192-
SearchResponse searchResponse = client().prepareSearch("test2", "test11*", "index*", "-test2*").get();
201+
SearchResponse searchResponse = trySearch("test2", "test11*", "index*", "-test2*");
193202
assertReturnedIndices(searchResponse, "test111", "test112");
194203
}
195204

196205
public void testExplicitAndWildcardInclusionAndExplicitExclusions() {
197206
//index1 is not authorized and referred to through wildcard, test111 and test112 are excluded
198207
createIndicesWithRandomAliases("test1", "test10", "test111", "test112", "test2", "index1");
199208

200-
SearchResponse searchResponse = client().prepareSearch("test10", "test11*", "index*", "-test111", "-test112").get();
209+
SearchResponse searchResponse = trySearch("test10", "test11*", "index*", "-test111", "-test112");
201210
assertReturnedIndices(searchResponse, "test10");
202211
}
203212

204213
public void testMissingDateMath() {
205-
expectThrows(IndexNotFoundException.class, () -> client().prepareSearch("<logstash-{now/M}>").get());
214+
expectThrows(IndexNotFoundException.class, () -> trySearch("<logstash-{now/M}>"));
206215
}
207216

208217
public void testMultiSearchUnauthorizedIndex() {
@@ -397,6 +406,14 @@ public void testMultiTermVectors() {
397406
assertThat(response.getResponses()[4].getFailure().getCause(), instanceOf(IndexNotFoundException.class));
398407
}
399408

409+
private SearchResponse trySearch(String ... indices) {
410+
return client().prepareSearch(indices).get(TimeValue.timeValueSeconds(20));
411+
}
412+
413+
private SearchResponse trySearch(IndicesOptions options, String ... indices) {
414+
return client().prepareSearch(indices).setIndicesOptions(options).get(TimeValue.timeValueSeconds(20));
415+
}
416+
400417
private static void assertReturnedIndices(SearchResponse searchResponse, String... indices) {
401418
List<String> foundIndices = new ArrayList<>();
402419
for (SearchHit searchHit : searchResponse.getHits().getHits()) {

0 commit comments

Comments
 (0)