@@ -218,8 +218,9 @@ public void testCertificateIdentityBackwardsCompatibility() throws Exception {
218
218
}
219
219
case MIXED -> {
220
220
try {
221
- this .createClientsByVersion ();
221
+ this .createClientsByCertificateIdentityCapability ();
222
222
223
+ // Test against old node - should get parsing error
223
224
Exception oldNodeException = expectThrows (
224
225
Exception .class ,
225
226
() -> createCrossClusterApiKeyWithCertIdentity (oldVersionClient , "CN=test-.*" )
@@ -236,16 +237,12 @@ public void testCertificateIdentityBackwardsCompatibility() throws Exception {
236
237
);
237
238
assertThat (
238
239
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
- )
240
+ containsString ("cluster is in a mixed-version state and does not yet support the [certificate_identity] field" )
243
241
);
244
242
} finally {
245
243
this .closeClientsByVersion ();
246
244
}
247
245
}
248
-
249
246
case UPGRADED -> {
250
247
// Fully upgraded cluster should support certificate identity
251
248
final Tuple <String , String > apiKey = createCrossClusterApiKeyWithCertIdentity ("CN=test-.*" );
@@ -484,6 +481,53 @@ private void assertQuery(RestClient restClient, String body, Consumer<List<Map<S
484
481
apiKeysVerifier .accept (apiKeys );
485
482
}
486
483
484
+ private boolean nodeSupportsCertificateIdentity (Map <String , Object > nodeDetails ) {
485
+ String nodeVersionString = (String ) nodeDetails .get ("version" );
486
+ Version nodeVersion = Version .fromString (nodeVersionString );
487
+ // Certificate identity was introduced in 9.2.0
488
+ return nodeVersion .onOrAfter (Version .V_9_2_0 );
489
+ }
490
+
491
+ @ SuppressWarnings ("unchecked" )
492
+ private Map <Boolean , RestClient > getRestClientByCertificateIdentityCapability () throws IOException {
493
+ Response response = client ().performRequest (new Request ("GET" , "_nodes" ));
494
+ assertOK (response );
495
+ ObjectPath objectPath = ObjectPath .createFromResponse (response );
496
+ Map <String , Object > nodesAsMap = objectPath .evaluate ("nodes" );
497
+ Map <Boolean , List <HttpHost >> hostsByCapability = new HashMap <>();
498
+
499
+ for (Map .Entry <String , Object > entry : nodesAsMap .entrySet ()) {
500
+ Map <String , Object > nodeDetails = (Map <String , Object >) entry .getValue ();
501
+ var capabilitySupported = nodeSupportsCertificateIdentity (nodeDetails );
502
+ Map <String , Object > httpInfo = (Map <String , Object >) nodeDetails .get ("http" );
503
+ hostsByCapability .computeIfAbsent (capabilitySupported , k -> new ArrayList <>())
504
+ .add (HttpHost .create ((String ) httpInfo .get ("publish_address" )));
505
+ }
506
+
507
+ Map <Boolean , RestClient > clientsByCapability = new HashMap <>();
508
+ for (var entry : hostsByCapability .entrySet ()) {
509
+ clientsByCapability .put (entry .getKey (), buildClient (restClientSettings (), entry .getValue ().toArray (new HttpHost [0 ])));
510
+ }
511
+ return clientsByCapability ;
512
+ }
513
+
514
+ private void createClientsByCertificateIdentityCapability () throws IOException {
515
+ var clientsByCapability = getRestClientByCertificateIdentityCapability ();
516
+ if (clientsByCapability .size () == 2 ) {
517
+ for (Map .Entry <Boolean , RestClient > client : clientsByCapability .entrySet ()) {
518
+ if (client .getKey () == false ) {
519
+ oldVersionClient = client .getValue ();
520
+ } else {
521
+ newVersionClient = client .getValue ();
522
+ }
523
+ }
524
+ assertThat (oldVersionClient , notNullValue ());
525
+ assertThat (newVersionClient , notNullValue ());
526
+ } else {
527
+ fail ("expected 2 versions during rolling upgrade but got: " + clientsByCapability .size ());
528
+ }
529
+ }
530
+
487
531
private Tuple <String , String > createCrossClusterApiKeyWithCertIdentity (String certificateIdentity ) throws IOException {
488
532
return createCrossClusterApiKeyWithCertIdentity (client (), certificateIdentity );
489
533
}
@@ -514,4 +558,5 @@ private Tuple<String, String> createCrossClusterApiKeyWithCertIdentity(RestClien
514
558
assertThat (key , notNullValue ());
515
559
return Tuple .tuple (id , key );
516
560
}
561
+
517
562
}
0 commit comments