|
20 | 20 | import java.nio.channels.ClosedChannelException; |
21 | 21 | import java.time.Duration; |
22 | 22 | import java.util.Arrays; |
| 23 | +import java.util.Collections; |
| 24 | +import java.util.Map; |
23 | 25 | import java.util.concurrent.Callable; |
24 | 26 |
|
25 | 27 | import io.netty.buffer.PooledByteBufAllocator; |
@@ -267,6 +269,26 @@ void websocketTransportBasicSslCertificateFromFileSystemWithBundle(@ResourcePath |
267 | 269 | testBasicSslWithPemCertificateFromBundle(testCert, testKey, testCert, Transport.WEBSOCKET); |
268 | 270 | } |
269 | 271 |
|
| 272 | + @Test |
| 273 | + @WithPackageResources({ "test-cert.pem", "test-key.pem" }) |
| 274 | + void websocketTransportSslProviderFallsBackToDefaultWhenServerNameIsUnmapped() { |
| 275 | + SslBundle defaultBundle = createBundle("test-cert.pem", "test-key.pem"); |
| 276 | + SslBundle mappedBundle = createBundle("test-cert.pem", "test-key.pem"); |
| 277 | + NettyRSocketServerFactory.HttpServerSslCustomizer customizer = new NettyRSocketServerFactory.HttpServerSslCustomizer( |
| 278 | + Ssl.ClientAuth.NONE, defaultBundle, Map.of("mapped.example", mappedBundle)); |
| 279 | + assertThat(customizer.getSslProvider("unmapped.example")).isSameAs(customizer.getSslProvider(null)); |
| 280 | + } |
| 281 | + |
| 282 | + @Test |
| 283 | + @WithPackageResources({ "test-cert.pem", "test-key.pem" }) |
| 284 | + @SuppressWarnings("NullAway") // Test null check |
| 285 | + void websocketTransportSslProviderReturnsDefaultWhenServerNameIsNull() { |
| 286 | + SslBundle defaultBundle = createBundle("test-cert.pem", "test-key.pem"); |
| 287 | + NettyRSocketServerFactory.HttpServerSslCustomizer customizer = new NettyRSocketServerFactory.HttpServerSslCustomizer( |
| 288 | + Ssl.ClientAuth.NONE, defaultBundle, Collections.emptyMap()); |
| 289 | + assertThat(customizer.getSslProvider(null)).isNotNull(); |
| 290 | + } |
| 291 | + |
270 | 292 | private void checkEchoRequest() { |
271 | 293 | String payload = "test payload"; |
272 | 294 | assertThat(this.requester).isNotNull(); |
@@ -338,6 +360,12 @@ private void testBasicSslWithPemCertificateFromBundle(String certificate, String |
338 | 360 | checkEchoRequest(); |
339 | 361 | } |
340 | 362 |
|
| 363 | + private static SslBundle createBundle(String certificate, String certificatePrivateKey) { |
| 364 | + PemSslStoreDetails keyStoreDetails = PemSslStoreDetails.forCertificate("classpath:" + certificate) |
| 365 | + .withPrivateKey("classpath:" + certificatePrivateKey); |
| 366 | + return SslBundle.of(new PemSslStoreBundle(keyStoreDetails, null)); |
| 367 | + } |
| 368 | + |
341 | 369 | @Test |
342 | 370 | void tcpTransportSslRejectsInsecureClient() { |
343 | 371 | NettyRSocketServerFactory factory = getFactory(); |
|
0 commit comments