File tree 3 files changed +26
-2
lines changed
src/test/java/com/rabbitmq/client/test/ssl
3 files changed +26
-2
lines changed Original file line number Diff line number Diff line change 19
19
import com .rabbitmq .client .impl .nio .NioParams ;
20
20
import com .rabbitmq .client .test .BrokerTestCase ;
21
21
import com .rabbitmq .client .test .TestUtils ;
22
+ import java .util .Collection ;
22
23
import java .util .concurrent .atomic .AtomicReference ;
24
+ import java .util .stream .Collectors ;
25
+ import java .util .stream .Stream ;
23
26
import javax .net .ssl .SSLContext ;
24
27
import javax .net .ssl .TrustManager ;
25
28
import org .junit .Test ;
@@ -84,7 +87,10 @@ public void connectionGetConsume() throws Exception {
84
87
85
88
@ Test
86
89
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 ());
88
94
for (String protocol : protocols ) {
89
95
SSLContext sslContext = SSLContext .getInstance (protocol );
90
96
sslContext .init (null , new TrustManager [] {new TrustEverythingTrustManager ()}, null );
Original file line number Diff line number Diff line change 21
21
import java .security .KeyStore ;
22
22
import java .security .NoSuchAlgorithmException ;
23
23
import java .util .Arrays ;
24
+ import java .util .Collection ;
25
+ import java .util .stream .Collectors ;
24
26
import javax .net .ssl .KeyManagerFactory ;
25
27
import javax .net .ssl .SSLContext ;
26
28
import javax .net .ssl .TrustManagerFactory ;
@@ -107,6 +109,16 @@ public static SSLContext getSSLContext() throws NoSuchAlgorithmException {
107
109
throw new NoSuchAlgorithmException ();
108
110
}
109
111
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
+
110
122
@ FunctionalInterface
111
123
interface CallableSupplier <T > {
112
124
Original file line number Diff line number Diff line change 22
22
import com .rabbitmq .client .Connection ;
23
23
import com .rabbitmq .client .impl .nio .NioParams ;
24
24
import java .io .IOException ;
25
+ import java .util .Collection ;
25
26
import java .util .concurrent .CountDownLatch ;
26
27
import java .util .concurrent .TimeUnit ;
27
28
import java .util .concurrent .TimeoutException ;
28
29
29
30
import java .util .concurrent .atomic .AtomicReference ;
30
31
import java .util .function .Supplier ;
32
+ import java .util .stream .Collectors ;
33
+ import java .util .stream .Stream ;
31
34
import javax .net .ssl .SSLContext ;
32
35
import javax .net .ssl .SSLSocket ;
33
36
@@ -69,7 +72,10 @@ public void openConnection()
69
72
70
73
@ Test
71
74
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 ());
73
79
for (String protocol : protocols ) {
74
80
SSLContext sslContext = SSLContext .getInstance (protocol );
75
81
ConnectionFactory cf = TestUtils .connectionFactory ();
You can’t perform that action at this time.
0 commit comments