1
1
package io .quarkus .websockets .next .test .client ;
2
2
3
+ import static org .junit .jupiter .api .Assertions .assertArrayEquals ;
3
4
import 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 ;
4
8
import static org .junit .jupiter .api .Assertions .assertTrue ;
5
9
6
10
import java .io .File ;
10
14
import java .util .concurrent .CopyOnWriteArrayList ;
11
15
import java .util .concurrent .CountDownLatch ;
12
16
import java .util .concurrent .TimeUnit ;
17
+ import java .util .concurrent .atomic .AtomicReference ;
18
+
19
+ import javax .net .ssl .SSLPeerUnverifiedException ;
13
20
14
21
import jakarta .inject .Inject ;
15
22
25
32
import io .quarkus .websockets .next .WebSocket ;
26
33
import io .quarkus .websockets .next .WebSocketClient ;
27
34
import io .quarkus .websockets .next .WebSocketClientConnection ;
35
+ import io .quarkus .websockets .next .WebSocketConnection ;
28
36
import io .quarkus .websockets .next .WebSocketConnector ;
29
37
import io .smallrye .certs .Format ;
30
38
import io .smallrye .certs .junit5 .Certificate ;
@@ -53,20 +61,39 @@ public class TlsClientEndpointTest {
53
61
URI uri ;
54
62
55
63
@ Test
56
- void testClient () throws InterruptedException , URISyntaxException {
64
+ void testClient () throws InterruptedException , SSLPeerUnverifiedException , URISyntaxException {
57
65
assertClient (uri );
58
66
URI wssUri = new URI ("wss" , uri .getUserInfo (), uri .getHost (), uri .getPort (), uri .getPath (), uri .getQuery (),
59
67
uri .getFragment ());
60
68
assertClient (wssUri );
61
69
}
62
70
63
- void assertClient (URI uri ) throws InterruptedException , URISyntaxException {
71
+ void assertClient (URI uri ) throws InterruptedException , SSLPeerUnverifiedException {
64
72
WebSocketClientConnection connection = connector
65
73
.baseUri (uri )
66
74
// The value will be encoded automatically
67
75
.pathParam ("name" , "Lu=" )
68
76
.connectAndAwait ();
69
77
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 ());
70
97
71
98
assertEquals ("Lu=" , connection .pathParam ("name" ));
72
99
connection .sendTextAndAwait ("Hi!" );
@@ -86,10 +113,16 @@ void assertClient(URI uri) throws InterruptedException, URISyntaxException {
86
113
@ WebSocket (path = "/endpoint/{name}" )
87
114
public static class ServerEndpoint {
88
115
116
+ static final AtomicReference <WebSocketConnection > CONNECTION_REF = new AtomicReference <>();
117
+
118
+ static volatile CountDownLatch openedLatch = new CountDownLatch (1 );
119
+
89
120
static volatile CountDownLatch closedLatch = new CountDownLatch (1 );
90
121
91
122
@ OnOpen
92
- String open (@ PathParam String name ) {
123
+ String open (@ PathParam String name , WebSocketConnection connection ) {
124
+ CONNECTION_REF .set (connection );
125
+ openedLatch .countDown ();
93
126
return "Hello " + name + "!" ;
94
127
}
95
128
@@ -104,6 +137,8 @@ void close() {
104
137
}
105
138
106
139
static void reset () {
140
+ CONNECTION_REF .set (null );
141
+ openedLatch = new CountDownLatch (1 );
107
142
closedLatch = new CountDownLatch (1 );
108
143
}
109
144
0 commit comments