File tree Expand file tree Collapse file tree 3 files changed +26
-2
lines changed
src/test/java/com/rabbitmq/client/test/ssl Expand file tree Collapse file tree 3 files changed +26
-2
lines changed Original file line number Diff line number Diff line change 1919import com .rabbitmq .client .impl .nio .NioParams ;
2020import com .rabbitmq .client .test .BrokerTestCase ;
2121import com .rabbitmq .client .test .TestUtils ;
22+ import java .util .Collection ;
2223import java .util .concurrent .atomic .AtomicReference ;
24+ import java .util .stream .Collectors ;
25+ import java .util .stream .Stream ;
2326import javax .net .ssl .SSLContext ;
2427import javax .net .ssl .TrustManager ;
2528import org .junit .Test ;
@@ -84,7 +87,10 @@ public void connectionGetConsume() throws Exception {
8487
8588 @ Test
8689 public void connectionGetConsumeProtocols () throws Exception {
87- String [] protocols = new String [] {"TLSv1.2" , "TLSv1.3" };
90+ Collection <String > availableProtocols = TlsTestUtils .availableTlsProtocols ();
91+ Collection <String > protocols = Stream .of ("TLSv1.2" , "TLSv1.3" )
92+ .filter (p -> availableProtocols .contains (p ))
93+ .collect (Collectors .toList ());
8894 for (String protocol : protocols ) {
8995 SSLContext sslContext = SSLContext .getInstance (protocol );
9096 sslContext .init (null , new TrustManager [] {new TrustEverythingTrustManager ()}, null );
Original file line number Diff line number Diff line change 2121import java .security .KeyStore ;
2222import java .security .NoSuchAlgorithmException ;
2323import java .util .Arrays ;
24+ import java .util .Collection ;
25+ import java .util .stream .Collectors ;
2426import javax .net .ssl .KeyManagerFactory ;
2527import javax .net .ssl .SSLContext ;
2628import javax .net .ssl .TrustManagerFactory ;
@@ -107,6 +109,16 @@ public static SSLContext getSSLContext() throws NoSuchAlgorithmException {
107109 throw new NoSuchAlgorithmException ();
108110 }
109111
112+ static Collection <String > availableTlsProtocols () {
113+ try {
114+ String [] protocols = SSLContext .getDefault ().getSupportedSSLParameters ().getProtocols ();
115+ return Arrays .stream (protocols ).filter (p -> p .toLowerCase ().startsWith ("tls" )).collect (
116+ Collectors .toList ());
117+ } catch (NoSuchAlgorithmException e ) {
118+ throw new RuntimeException (e );
119+ }
120+ }
121+
110122 @ FunctionalInterface
111123 interface CallableSupplier <T > {
112124
Original file line number Diff line number Diff line change 2222import com .rabbitmq .client .Connection ;
2323import com .rabbitmq .client .impl .nio .NioParams ;
2424import java .io .IOException ;
25+ import java .util .Collection ;
2526import java .util .concurrent .CountDownLatch ;
2627import java .util .concurrent .TimeUnit ;
2728import java .util .concurrent .TimeoutException ;
2829
2930import java .util .concurrent .atomic .AtomicReference ;
3031import java .util .function .Supplier ;
32+ import java .util .stream .Collectors ;
33+ import java .util .stream .Stream ;
3134import javax .net .ssl .SSLContext ;
3235import javax .net .ssl .SSLSocket ;
3336
@@ -69,7 +72,10 @@ public void openConnection()
6972
7073 @ Test
7174 public void connectionGetConsumeProtocols () throws Exception {
72- String [] protocols = new String [] {"TLSv1.2" , "TLSv1.3" };
75+ Collection <String > availableProtocols = TlsTestUtils .availableTlsProtocols ();
76+ Collection <String > protocols = Stream .of ("TLSv1.2" , "TLSv1.3" )
77+ .filter (p -> availableProtocols .contains (p ))
78+ .collect (Collectors .toList ());
7379 for (String protocol : protocols ) {
7480 SSLContext sslContext = SSLContext .getInstance (protocol );
7581 ConnectionFactory cf = TestUtils .connectionFactory ();
You can’t perform that action at this time.
0 commit comments