zookeeper-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From anmolnar <...@git.apache.org>
Subject [GitHub] zookeeper pull request #679: ZOOKEEPER-3172: Quorum TLS - fix port unificati...
Date Wed, 14 Nov 2018 23:31:23 GMT
Github user anmolnar commented on a diff in the pull request:

    https://github.com/apache/zookeeper/pull/679#discussion_r233661917
  
    --- Diff: zookeeper-server/src/test/java/org/apache/zookeeper/server/quorum/UnifiedServerSocketTest.java
---
    @@ -17,156 +17,644 @@
      */
     package org.apache.zookeeper.server.quorum;
     
    +import java.io.BufferedInputStream;
    +import java.io.IOException;
    +import java.net.ConnectException;
    +import java.net.InetSocketAddress;
    +import java.net.Socket;
    +import java.net.SocketException;
    +import java.util.ArrayList;
    +import java.util.Collection;
    +import java.util.List;
    +import java.util.Random;
    +
    +import javax.net.ssl.HandshakeCompletedEvent;
    +import javax.net.ssl.HandshakeCompletedListener;
    +import javax.net.ssl.SSLSocket;
    +
     import org.apache.zookeeper.PortAssignment;
     import org.apache.zookeeper.client.ZKClientConfig;
    +import org.apache.zookeeper.common.BaseX509ParameterizedTestCase;
     import org.apache.zookeeper.common.ClientX509Util;
    -import org.apache.zookeeper.common.Time;
    +import org.apache.zookeeper.common.KeyStoreFileType;
    +import org.apache.zookeeper.common.X509Exception;
    +import org.apache.zookeeper.common.X509KeyType;
    +import org.apache.zookeeper.common.X509TestContext;
     import org.apache.zookeeper.common.X509Util;
     import org.apache.zookeeper.server.ServerCnxnFactory;
     import org.junit.Assert;
     import org.junit.Before;
     import org.junit.Test;
    +import org.junit.runner.RunWith;
    +import org.junit.runners.Parameterized;
     
    -import javax.net.ssl.HandshakeCompletedEvent;
    -import javax.net.ssl.HandshakeCompletedListener;
    -import javax.net.ssl.SSLSocket;
    -import java.io.IOException;
    -import java.net.ConnectException;
    -import java.net.InetSocketAddress;
    -import java.net.Socket;
    -
    -import static org.hamcrest.CoreMatchers.equalTo;
    -import static org.junit.Assert.assertThat;
    +@RunWith(Parameterized.class)
    +public class UnifiedServerSocketTest extends BaseX509ParameterizedTestCase {
     
    -public class UnifiedServerSocketTest {
    +    @Parameterized.Parameters
    +    public static Collection<Object[]> params() {
    +        ArrayList<Object[]> result = new ArrayList<>();
    +        int paramIndex = 0;
    +        for (X509KeyType caKeyType : X509KeyType.values()) {
    +            for (X509KeyType certKeyType : X509KeyType.values()) {
    +                for (Boolean hostnameVerification : new Boolean[] { true, false  }) {
    +                    result.add(new Object[]{
    +                            caKeyType,
    +                            certKeyType,
    +                            hostnameVerification,
    +                            paramIndex++
    +                    });
    +                }
    +            }
    +        }
    +        return result;
    +    }
     
         private static final int MAX_RETRIES = 5;
         private static final int TIMEOUT = 1000;
    +    private static final byte[] DATA_TO_CLIENT = "hello client".getBytes();
    +    private static final byte[] DATA_FROM_CLIENT = "hello server".getBytes();
     
         private X509Util x509Util;
         private int port;
    -    private volatile boolean handshakeCompleted;
    +    private InetSocketAddress localServerAddress;
    +    private final Object handshakeCompletedLock = new Object();
    +    // access only inside synchronized(handshakeCompletedLock) { ... } blocks
    +    private boolean handshakeCompleted = false;
    +
    +    public UnifiedServerSocketTest(
    +            final X509KeyType caKeyType,
    +            final X509KeyType certKeyType,
    +            final Boolean hostnameVerification,
    +            final Integer paramIndex) {
    +        super(paramIndex, () -> {
    +            try {
    +                return X509TestContext.newBuilder()
    +                    .setTempDir(tempDir)
    +                    .setKeyStoreKeyType(certKeyType)
    +                    .setTrustStoreKeyType(caKeyType)
    +                    .setHostnameVerification(hostnameVerification)
    +                    .build();
    +            } catch (Exception e) {
    +                throw new RuntimeException(e);
    +            }
    +        });
    +    }
     
         @Before
         public void setUp() throws Exception {
    -        handshakeCompleted = false;
    -
             port = PortAssignment.unique();
    +        localServerAddress = new InetSocketAddress("localhost", port);
    --- End diff --
    
    Thanks.


---

Mime
View raw message