11package io .quarkus .websockets .next .test .client ;
22
3+ import static org .junit .jupiter .api .Assertions .assertArrayEquals ;
34import static org .junit .jupiter .api .Assertions .assertEquals ;
5+ import static org .junit .jupiter .api .Assertions .assertNotNull ;
6+ import static org .junit .jupiter .api .Assertions .assertNull ;
7+ import static org .junit .jupiter .api .Assertions .assertThrows ;
48import static org .junit .jupiter .api .Assertions .assertTrue ;
59
610import java .io .File ;
1014import java .util .concurrent .CopyOnWriteArrayList ;
1115import java .util .concurrent .CountDownLatch ;
1216import java .util .concurrent .TimeUnit ;
17+ import java .util .concurrent .atomic .AtomicReference ;
18+
19+ import javax .net .ssl .SSLPeerUnverifiedException ;
1320
1421import jakarta .inject .Inject ;
1522
2532import io .quarkus .websockets .next .WebSocket ;
2633import io .quarkus .websockets .next .WebSocketClient ;
2734import io .quarkus .websockets .next .WebSocketClientConnection ;
35+ import io .quarkus .websockets .next .WebSocketConnection ;
2836import io .quarkus .websockets .next .WebSocketConnector ;
2937import io .smallrye .certs .Format ;
3038import io .smallrye .certs .junit5 .Certificate ;
@@ -53,20 +61,39 @@ public class TlsClientEndpointTest {
5361 URI uri ;
5462
5563 @ Test
56- void testClient () throws InterruptedException , URISyntaxException {
64+ void testClient () throws InterruptedException , SSLPeerUnverifiedException , URISyntaxException {
5765 assertClient (uri );
5866 URI wssUri = new URI ("wss" , uri .getUserInfo (), uri .getHost (), uri .getPort (), uri .getPath (), uri .getQuery (),
5967 uri .getFragment ());
6068 assertClient (wssUri );
6169 }
6270
63- void assertClient (URI uri ) throws InterruptedException , URISyntaxException {
71+ void assertClient (URI uri ) throws InterruptedException , SSLPeerUnverifiedException {
6472 WebSocketClientConnection connection = connector
6573 .baseUri (uri )
6674 // The value will be encoded automatically
6775 .pathParam ("name" , "Lu=" )
6876 .connectAndAwait ();
6977 assertTrue (connection .isSecure ());
78+ assertNotNull (connection .sslSession ());
79+ assertNull (connection .sslSession ().getLocalPrincipal ());
80+ assertNull (connection .sslSession ().getLocalCertificates ());
81+ assertNotNull (connection .sslSession ().getPeerPrincipal ());
82+ assertNotNull (connection .sslSession ().getPeerCertificates ());
83+
84+ assertTrue (ServerEndpoint .openedLatch .await (5 , TimeUnit .SECONDS ));
85+ assertTrue (ServerEndpoint .CONNECTION_REF .get ().isSecure ());
86+ assertNotNull (ServerEndpoint .CONNECTION_REF .get ().sslSession ());
87+ assertNotNull (ServerEndpoint .CONNECTION_REF .get ().sslSession ().getLocalPrincipal ());
88+ assertNotNull (ServerEndpoint .CONNECTION_REF .get ().sslSession ().getLocalCertificates ());
89+ assertThrows (SSLPeerUnverifiedException .class ,
90+ () -> ServerEndpoint .CONNECTION_REF .get ().sslSession ().getPeerPrincipal ());
91+ assertThrows (SSLPeerUnverifiedException .class ,
92+ () -> ServerEndpoint .CONNECTION_REF .get ().sslSession ().getPeerCertificates ());
93+ assertEquals (connection .sslSession ().getPeerPrincipal (),
94+ ServerEndpoint .CONNECTION_REF .get ().sslSession ().getLocalPrincipal ());
95+ assertArrayEquals (connection .sslSession ().getPeerCertificates (),
96+ ServerEndpoint .CONNECTION_REF .get ().sslSession ().getLocalCertificates ());
7097
7198 assertEquals ("Lu=" , connection .pathParam ("name" ));
7299 connection .sendTextAndAwait ("Hi!" );
@@ -86,10 +113,16 @@ void assertClient(URI uri) throws InterruptedException, URISyntaxException {
86113 @ WebSocket (path = "/endpoint/{name}" )
87114 public static class ServerEndpoint {
88115
116+ static final AtomicReference <WebSocketConnection > CONNECTION_REF = new AtomicReference <>();
117+
118+ static volatile CountDownLatch openedLatch = new CountDownLatch (1 );
119+
89120 static volatile CountDownLatch closedLatch = new CountDownLatch (1 );
90121
91122 @ OnOpen
92- String open (@ PathParam String name ) {
123+ String open (@ PathParam String name , WebSocketConnection connection ) {
124+ CONNECTION_REF .set (connection );
125+ openedLatch .countDown ();
93126 return "Hello " + name + "!" ;
94127 }
95128
@@ -104,6 +137,8 @@ void close() {
104137 }
105138
106139 static void reset () {
140+ CONNECTION_REF .set (null );
141+ openedLatch = new CountDownLatch (1 );
107142 closedLatch = new CountDownLatch (1 );
108143 }
109144
0 commit comments