@@ -411,17 +411,12 @@ public void testApiKeySuperuser() throws IOException {
411411
412412 // read is ok
413413 final Request searchRequest = new Request ("GET" , ".security/_search" );
414- // TODO: change the warning expectation to be always once #82837 is fixed
415- // Configure the warning to be optional due to #82837, it is ok since this test is for something else
416- searchRequest .setOptions (RequestOptions .DEFAULT .toBuilder ().setWarningsHandler (warnings -> {
417- if (warnings .isEmpty ()) {
418- return false ;
419- } else if (warnings .size () == 1 ) {
420- return false == warnings .get (0 ).startsWith ("this request accesses system indices: [.security-7]" );
421- } else {
422- return true ;
423- }
424- }).addHeader ("Authorization" , apiKeyAuthHeader ));
414+ searchRequest .setOptions (
415+ expectWarnings (
416+ "this request accesses system indices: [.security-7], but in a future major "
417+ + "version, direct access to system indices will be prevented by default"
418+ ).toBuilder ().addHeader ("Authorization" , apiKeyAuthHeader )
419+ );
425420 assertOK (client ().performRequest (searchRequest ));
426421
427422 // write must not be allowed
@@ -430,7 +425,12 @@ public void testApiKeySuperuser() throws IOException {
430425 {
431426 "doc_type": "foo"
432427 }""" );
433- indexRequest .setOptions (RequestOptions .DEFAULT .toBuilder ().addHeader ("Authorization" , apiKeyAuthHeader ));
428+ indexRequest .setOptions (
429+ expectWarnings (
430+ "this request accesses system indices: [.security-7], but in a future major "
431+ + "version, direct access to system indices will be prevented by default"
432+ ).toBuilder ().addHeader ("Authorization" , apiKeyAuthHeader )
433+ );
434434 final ResponseException e = expectThrows (ResponseException .class , () -> client ().performRequest (indexRequest ));
435435 assertThat (e .getResponse ().getStatusLine ().getStatusCode (), equalTo (403 ));
436436 assertThat (e .getMessage (), containsString ("is unauthorized" ));
0 commit comments