private void testTLS(boolean clientSSL, boolean serverSSL, Function<WebClient, HttpRequest<Buffer>> requestProvider) throws Exception { testTLS(clientSSL, serverSSL, requestProvider, null); }
@Test public void testTLSEnabledDisableRequestTLSAbsURI() throws Exception { testTLS(true, false, client -> client.getAbs("http://" + DEFAULT_HTTPS_HOST + ":" + DEFAULT_HTTPS_PORT)); }
@Test public void testTLSEnabledEnableRequestTLSAbsURI() throws Exception { testTLS(true, true, client -> client.getAbs("https://" + DEFAULT_HTTPS_HOST + ":" + DEFAULT_HTTPS_PORT)); }
@Test public void testTLSEnabled() throws Exception { testTLS(true, true, client -> client.get("/")); }
@Test public void testTLSDisabledDisableRequestTLSAbsURI() throws Exception { testTLS(false, false, client -> client.getAbs("http://" + DEFAULT_HTTPS_HOST + ":" + DEFAULT_HTTPS_PORT)); }
@Test public void testTLSDisabledEnableRequestTLSAbsURI() throws Exception { testTLS(false, true, client -> client.getAbs("https://" + DEFAULT_HTTPS_HOST + ":" + DEFAULT_HTTPS_PORT)); }
@Test public void testTLSEnabledEnableRequestTLS() throws Exception { testTLS(true, true, client -> client.get("/").ssl(true)); }
@Test public void testTLSDisabledDisableRequestTLS() throws Exception { testTLS(false, false, client -> client.get("/").ssl(false)); }
@Test public void testTLSDisabledEnableRequestTLS() throws Exception { testTLS(false, true, client -> client.get("/").ssl(true)); }
@Test public void testTLSEnabledDisableRequestTLS() throws Exception { testTLS(true, false, client -> client.get("/").ssl(false)); }
/** * Regression test for issue #563 (https://github.com/vert-x3/vertx-web/issues/563) * <p> * Only occurred when {@link WebClientOptions#isSsl()} was false for an SSL request. */ @Test public void testTLSQueryParametersIssue563() throws Exception { testTLS(false, true, client -> client.getAbs("https://" + DEFAULT_HTTPS_HOST + ":" + DEFAULT_HTTPS_PORT) .addQueryParam("query1", "value1") .addQueryParam("query2", "value2"), serverRequest -> assertEquals("query1=value1&query2=value2", serverRequest.query())); }
private void testTLS(boolean clientSSL, boolean serverSSL, Function<WebClient, HttpRequest<Buffer>> requestProvider, Consumer<HttpServerRequest> serverAssertions) throws Exception { WebClientOptions clientOptions = new WebClientOptions() .setSsl(clientSSL) .setTrustAll(true) .setDefaultHost(DEFAULT_HTTPS_HOST) .setDefaultPort(DEFAULT_HTTPS_PORT); HttpServerOptions serverOptions = new HttpServerOptions() .setSsl(serverSSL) .setKeyStoreOptions(Cert.SERVER_JKS.get()) .setPort(DEFAULT_HTTPS_PORT) .setHost(DEFAULT_HTTPS_HOST); testTLS(clientOptions, serverOptions, requestProvider, serverAssertions); }
@Test public void testVirtualHostSNI() throws Exception { WebClientOptions clientOptions = new WebClientOptions() .setTrustAll(true) .setDefaultHost(DEFAULT_HTTPS_HOST) .setDefaultPort(DEFAULT_HTTPS_PORT); HttpServerOptions serverOptions = new HttpServerOptions() .setSsl(true) .setSni(true) .setKeyStoreOptions(Cert.SNI_JKS.get()) .setPort(DEFAULT_HTTPS_PORT) .setHost(DEFAULT_HTTPS_HOST); testTLS(clientOptions, serverOptions, req -> req.get("/").virtualHost("host2.com").ssl(true), req -> { assertEquals("host2.com", req.connection().indicatedServerName()); System.out.println(req.host()); }); }