@@ -331,7 +331,6 @@ public void testServiceAccountApiKey() throws IOException {
331
331
}
332
332
}
333
333
334
- @ AwaitsFix (bugUrl = "https://github.com/elastic/elasticsearch/issues/82785" )
335
334
public void testApiKeySuperuser () throws IOException {
336
335
if (isRunningAgainstOldCluster ()) {
337
336
final Request createUserRequest = new Request ("PUT" , "/_security/user/api_key_super_creator" );
@@ -354,10 +353,29 @@ public void testApiKeySuperuser() throws IOException {
354
353
)
355
354
)
356
355
);
357
- createApiKeyRequest .setJsonEntity ("""
358
- {
359
- "name": "super_legacy_key"
360
- }""" );
356
+ if (getOldClusterVersion ().onOrAfter (Version .V_7_3_0 )) {
357
+ createApiKeyRequest .setJsonEntity ("""
358
+ {
359
+ "name": "super_legacy_key"
360
+ }""" );
361
+ } else {
362
+ createApiKeyRequest .setJsonEntity ("""
363
+ {
364
+ "name": "super_legacy_key",
365
+ "role_descriptors": {
366
+ "super": {
367
+ "cluster": [ "all" ],
368
+ "indices": [
369
+ {
370
+ "names": [ "*" ],
371
+ "privileges": [ "all" ],
372
+ "allow_restricted_indices": true
373
+ }
374
+ ]
375
+ }
376
+ }
377
+ }""" );
378
+ }
361
379
final Map <String , Object > createApiKeyResponse = entityAsMap (client ().performRequest (createApiKeyRequest ));
362
380
final byte [] keyBytes = (createApiKeyResponse .get ("id" ) + ":" + createApiKeyResponse .get ("api_key" )).getBytes (
363
381
StandardCharsets .UTF_8
@@ -374,12 +392,16 @@ public void testApiKeySuperuser() throws IOException {
374
392
{
375
393
"doc_type": "foo"
376
394
}""" );
377
- indexRequest .setOptions (
378
- expectWarnings (
379
- "this request accesses system indices: [.security-7], but in a future major "
380
- + "version, direct access to system indices will be prevented by default"
381
- ).toBuilder ().addHeader ("Authorization" , apiKeyAuthHeader )
382
- );
395
+ if (getOldClusterVersion ().onOrAfter (Version .V_7_10_0 )) {
396
+ indexRequest .setOptions (
397
+ expectWarnings (
398
+ "this request accesses system indices: [.security-7], but in a future major "
399
+ + "version, direct access to system indices will be prevented by default"
400
+ ).toBuilder ().addHeader ("Authorization" , apiKeyAuthHeader )
401
+ );
402
+ } else {
403
+ indexRequest .setOptions (RequestOptions .DEFAULT .toBuilder ().addHeader ("Authorization" , apiKeyAuthHeader ));
404
+ }
383
405
assertOK (client ().performRequest (indexRequest ));
384
406
}
385
407
} else {
@@ -390,12 +412,17 @@ public void testApiKeySuperuser() throws IOException {
390
412
391
413
// read is ok
392
414
final Request searchRequest = new Request ("GET" , ".security/_search" );
393
- searchRequest .setOptions (
394
- expectWarnings (
395
- "this request accesses system indices: [.security-7], but in a future major "
396
- + "version, direct access to system indices will be prevented by default"
397
- ).toBuilder ().addHeader ("Authorization" , apiKeyAuthHeader )
398
- );
415
+ // TODO: change the warning expectation to be always once #82837 is fixed
416
+ // Configure the warning to be optional due to #82837, it is ok since this test is for something else
417
+ searchRequest .setOptions (RequestOptions .DEFAULT .toBuilder ().setWarningsHandler (warnings -> {
418
+ if (warnings .isEmpty ()) {
419
+ return false ;
420
+ } else if (warnings .size () == 1 ) {
421
+ return false == warnings .get (0 ).startsWith ("this request accesses system indices: [.security-7]" );
422
+ } else {
423
+ return true ;
424
+ }
425
+ }).addHeader ("Authorization" , apiKeyAuthHeader ));
399
426
assertOK (client ().performRequest (searchRequest ));
400
427
401
428
// write must not be allowed
@@ -404,12 +431,7 @@ public void testApiKeySuperuser() throws IOException {
404
431
{
405
432
"doc_type": "foo"
406
433
}""" );
407
- indexRequest .setOptions (
408
- expectWarnings (
409
- "this request accesses system indices: [.security-7], but in a future major "
410
- + "version, direct access to system indices will be prevented by default"
411
- ).toBuilder ().addHeader ("Authorization" , apiKeyAuthHeader )
412
- );
434
+ indexRequest .setOptions (RequestOptions .DEFAULT .toBuilder ().addHeader ("Authorization" , apiKeyAuthHeader ));
413
435
final ResponseException e = expectThrows (ResponseException .class , () -> client ().performRequest (indexRequest ));
414
436
assertThat (e .getResponse ().getStatusLine ().getStatusCode (), equalTo (403 ));
415
437
assertThat (e .getMessage (), containsString ("is unauthorized" ));
0 commit comments