eolivelli commented on a change in pull request #13354:
URL: https://github.com/apache/pulsar/pull/13354#discussion_r776768732



##########
File path: 
pulsar-common/src/test/java/org/apache/pulsar/common/util/keystoretls/JettySslContextFactoryWithAutoRefreshTest.java
##########
@@ -0,0 +1,186 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.pulsar.common.util.keystoretls;
+
+import com.google.common.io.Resources;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.http.client.methods.HttpGet;
+import org.apache.http.config.RegistryBuilder;
+import org.apache.http.conn.socket.ConnectionSocketFactory;
+import org.apache.http.conn.ssl.NoopHostnameVerifier;
+import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
+import org.apache.http.impl.client.CloseableHttpClient;
+import org.apache.http.impl.client.HttpClientBuilder;
+import org.apache.http.impl.client.HttpClients;
+import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
+import org.apache.logging.log4j.Level;
+import org.apache.logging.log4j.core.config.Configurator;
+import org.eclipse.jetty.server.Server;
+import org.eclipse.jetty.server.ServerConnector;
+import org.eclipse.jetty.util.ssl.SslContextFactory;
+import org.testng.annotations.Test;
+
+import javax.net.ssl.KeyManager;
+import javax.net.ssl.KeyManagerFactory;
+import javax.net.ssl.SSLContext;
+import javax.net.ssl.SSLHandshakeException;
+import javax.net.ssl.TrustManagerFactory;
+import java.io.FileInputStream;
+import java.security.KeyStore;
+import java.security.SecureRandom;
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+
+@Slf4j
+public class JettySslContextFactoryWithAutoRefreshTest {
+
+    @Test
+    public void testJettyTlsServerTls() throws Exception {
+        Configurator.setRootLevel(Level.INFO);
+        Server server = new Server();
+        List<ServerConnector> connectors = new ArrayList<>();
+        SslContextFactory.Server factory = 
KeyStoreSSLContext.createSslContextFactory(null,
+                "JKS", 
Resources.getResource("ssl/jetty_server_key.jks").getPath(),
+                "jetty_server_pwd", false, "JKS",
+                Resources.getResource("ssl/jetty_server_trust.jks").getPath(),
+                "jetty_server_pwd", true, null,
+                null, 600);
+        factory.setHostnameVerifier((s, sslSession) -> true);
+        ServerConnector connector = new ServerConnector(server, factory);
+        connector.setPort(0);
+        connectors.add(connector);
+        server.setConnectors(connectors.toArray(new ServerConnector[0]));
+        server.start();
+        // client connect
+        HttpClientBuilder httpClientBuilder = HttpClients.custom();
+        RegistryBuilder<ConnectionSocketFactory> registryBuilder = 
RegistryBuilder.create();
+        registryBuilder.register("https", new 
SSLConnectionSocketFactory(getClientSslContext(), new NoopHostnameVerifier()));
+        PoolingHttpClientConnectionManager cm = new 
PoolingHttpClientConnectionManager(registryBuilder.build());
+        httpClientBuilder.setConnectionManager(cm);
+        CloseableHttpClient httpClient = httpClientBuilder.build();
+        HttpGet httpGet = new HttpGet("https://localhost:"; + 
connector.getLocalPort());
+        httpClient.execute(httpGet);
+    }
+
+    @Test(expectedExceptions = SSLHandshakeException.class)
+    public void testJettyTlsServerInvalidTlsProtocol() throws Exception {
+        Configurator.setRootLevel(Level.INFO);
+        Server server = new Server();
+        List<ServerConnector> connectors = new ArrayList<>();
+        SslContextFactory.Server factory = 
KeyStoreSSLContext.createSslContextFactory(null,
+                "JKS", 
Resources.getResource("ssl/jetty_server_key.jks").getPath(),
+                "jetty_server_pwd", false, "JKS",
+                Resources.getResource("ssl/jetty_server_trust.jks").getPath(),
+                "jetty_server_pwd", true, null,
+                new HashSet<String>() {
+                    {
+                        this.add("TLSv1.3");
+                    }
+                }, 600);
+        factory.setHostnameVerifier((s, sslSession) -> true);
+        ServerConnector connector = new ServerConnector(server, factory);
+        connector.setPort(0);
+        connectors.add(connector);
+        server.setConnectors(connectors.toArray(new ServerConnector[0]));
+        server.start();

Review comment:
       Please stop all the servers and close all the clients




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to