@@ -217,13 +217,35 @@ public void testCertificateIdentityBackwardsCompatibility() throws Exception {
217
217
);
218
218
}
219
219
case MIXED -> {
220
- // Mixed cluster should reject certificate identity due to feature gating
221
- var exception = expectThrows (Exception .class , () -> createCrossClusterApiKeyWithCertIdentity ("CN=test-.*" ));
222
- assertThat (
223
- exception .getMessage (),
224
- containsString ("cluster is in a mixed-version state and does not yet support the certificate_identity field" )
225
- );
220
+ try {
221
+ this .createClientsByVersion ();
222
+
223
+ Exception oldNodeException = expectThrows (
224
+ Exception .class ,
225
+ () -> createCrossClusterApiKeyWithCertIdentity (oldVersionClient , "CN=test-.*" )
226
+ );
227
+ assertThat (
228
+ oldNodeException .getMessage (),
229
+ anyOf (containsString ("unknown field [certificate_identity]" ), containsString ("certificate_identity not supported" ))
230
+ );
231
+
232
+ // Test against new node - should get mixed-version error
233
+ Exception newNodeException = expectThrows (
234
+ Exception .class ,
235
+ () -> createCrossClusterApiKeyWithCertIdentity (newVersionClient , "CN=test-.*" )
236
+ );
237
+ assertThat (
238
+ newNodeException .getMessage (),
239
+ containsString (
240
+ "API key creation failed. The cluster is in a mixed-version state and does not yet "
241
+ + "support the [certificate_identity] field. Please retry after the upgrade is complete."
242
+ )
243
+ );
244
+ } finally {
245
+ this .closeClientsByVersion ();
246
+ }
226
247
}
248
+
227
249
case UPGRADED -> {
228
250
// Fully upgraded cluster should support certificate identity
229
251
final Tuple <String , String > apiKey = createCrossClusterApiKeyWithCertIdentity ("CN=test-.*" );
@@ -463,6 +485,11 @@ private void assertQuery(RestClient restClient, String body, Consumer<List<Map<S
463
485
}
464
486
465
487
private Tuple <String , String > createCrossClusterApiKeyWithCertIdentity (String certificateIdentity ) throws IOException {
488
+ return createCrossClusterApiKeyWithCertIdentity (client (), certificateIdentity );
489
+ }
490
+
491
+ private Tuple <String , String > createCrossClusterApiKeyWithCertIdentity (RestClient client , String certificateIdentity )
492
+ throws IOException {
466
493
final String name = "test-cc-api-key-" + randomAlphaOfLengthBetween (3 , 5 );
467
494
final Request createApiKeyRequest = new Request ("POST" , "/_security/cross_cluster/api_key" );
468
495
createApiKeyRequest .setJsonEntity (Strings .format ("""
@@ -478,7 +505,7 @@ private Tuple<String, String> createCrossClusterApiKeyWithCertIdentity(String ce
478
505
}
479
506
}""" , name , certificateIdentity ));
480
507
481
- final Response createResponse = client () .performRequest (createApiKeyRequest );
508
+ final Response createResponse = client .performRequest (createApiKeyRequest );
482
509
assertOK (createResponse );
483
510
final ObjectPath path = ObjectPath .createFromResponse (createResponse );
484
511
final String id = path .evaluate ("id" );
@@ -487,5 +514,4 @@ private Tuple<String, String> createCrossClusterApiKeyWithCertIdentity(String ce
487
514
assertThat (key , notNullValue ());
488
515
return Tuple .tuple (id , key );
489
516
}
490
-
491
517
}
0 commit comments