|
13 | 13 |
|
14 | 14 | import io.vertx.core.Future;
|
15 | 15 | import io.vertx.core.Vertx;
|
| 16 | +import io.vertx.core.VertxOptions; |
| 17 | +import io.vertx.core.buffer.Buffer; |
| 18 | +import io.vertx.core.dns.AddressResolverOptions; |
16 | 19 | import io.vertx.core.net.PemKeyCertOptions;
|
17 | 20 | import io.vertx.core.net.PemTrustOptions;
|
18 | 21 | import io.vertx.ext.unit.TestContext;
|
@@ -260,6 +263,53 @@ public void testConnFailWithVerifyIdentitySslMode(TestContext ctx) {
|
260 | 263 | }));
|
261 | 264 | }
|
262 | 265 |
|
| 266 | + @Test |
| 267 | + public void testTLSInvalidHostname(TestContext ctx) { |
| 268 | + MySQLConnection.connect( |
| 269 | + vertx, |
| 270 | + options |
| 271 | + .setSslMode(SslMode.VERIFY_IDENTITY) |
| 272 | + // The hostname in the test certificate is MySQL_Server_8.0.17_Auto_Generated_Server_Certificate, |
| 273 | + // so 'localhost' should make for a failed connection |
| 274 | + .setHost("localhost") |
| 275 | + .setHostnameVerificationAlgorithm("HTTPS") |
| 276 | + .setPemTrustOptions(new PemTrustOptions().addCertPath("tls/files/ca.pem")) |
| 277 | + .setPemKeyCertOptions(new PemKeyCertOptions() |
| 278 | + .setCertPath("tls/files/client-cert.pem") |
| 279 | + .setKeyPath("tls/files/client-key.pem")), |
| 280 | + ctx.asyncAssertFailure(err -> { |
| 281 | + ctx.assertEquals(err.getMessage(), "No name matching localhost found"); |
| 282 | + })); |
| 283 | + } |
| 284 | + |
| 285 | + @Test |
| 286 | + public void testTLSCorrectHostname(TestContext ctx) { |
| 287 | + Vertx vertxWithHosts = Vertx.vertx( |
| 288 | + new VertxOptions() |
| 289 | + .setAddressResolverOptions( |
| 290 | + new AddressResolverOptions() |
| 291 | + .setHostsValue(Buffer.buffer("127.0.0.1 MySQL_Server_8.0.17_Auto_Generated_Server_Certificate\n")) |
| 292 | + ) |
| 293 | + ); |
| 294 | + |
| 295 | + MySQLConnection.connect( |
| 296 | + vertxWithHosts, |
| 297 | + options |
| 298 | + .setSslMode(SslMode.VERIFY_IDENTITY) |
| 299 | + // The hostname in the test certificate is MySQL_Server_8.0.17_Auto_Generated_Server_Certificate, |
| 300 | + // so 'localhost' should make for a failed connection |
| 301 | + .setHost("MySQL_Server_8.0.17_Auto_Generated_Server_Certificate") |
| 302 | + .setHostnameVerificationAlgorithm("HTTPS") |
| 303 | + .setPemTrustOptions(new PemTrustOptions().addCertPath("tls/files/ca.pem")) |
| 304 | + .setPemKeyCertOptions(new PemKeyCertOptions() |
| 305 | + .setCertPath("tls/files/client-cert.pem") |
| 306 | + .setKeyPath("tls/files/client-key.pem")), |
| 307 | + ctx.asyncAssertSuccess(conn -> { |
| 308 | + ctx.assertTrue(conn.isSSL()); |
| 309 | + vertxWithHosts.close(); |
| 310 | + })); |
| 311 | + } |
| 312 | + |
263 | 313 | @Test
|
264 | 314 | public void testConnFail(TestContext ctx) {
|
265 | 315 | options.setSslMode(SslMode.REQUIRED);
|
|
0 commit comments