Search in sources :

Example 81 with Timeout

use of org.junit.jupiter.api.Timeout in project zookeeper by apache.

the class QuorumSSLTest method testHostnameVerificationWithValidIpAddressAndInvalidHostname.

@Test
@Timeout(value = 5, unit = TimeUnit.MINUTES)
public void testHostnameVerificationWithValidIpAddressAndInvalidHostname() throws Exception {
    String badhostnameKeystorePath = tmpDir + "/badhost.jks";
    X509Certificate badHostCert = buildEndEntityCert(defaultKeyPair, rootCertificate, rootKeyPair.getPrivate(), "bleepbloop", "127.0.0.1", null, null);
    writeKeystore(badHostCert, defaultKeyPair, badhostnameKeystorePath);
    testHostnameVerification(badhostnameKeystorePath, true);
}
Also used : X509Certificate(java.security.cert.X509Certificate) SecretUtilsTest(org.apache.zookeeper.common.SecretUtilsTest) Test(org.junit.jupiter.api.Test) Timeout(org.junit.jupiter.api.Timeout)

Example 82 with Timeout

use of org.junit.jupiter.api.Timeout in project zookeeper by apache.

the class QuorumSSLTest method testRollingUpgrade.

@Test
@Timeout(value = 5, unit = TimeUnit.MINUTES)
public void testRollingUpgrade() throws Exception {
    // Form a quorum without ssl
    q1 = new MainThread(1, clientPortQp1, quorumConfiguration);
    q2 = new MainThread(2, clientPortQp2, quorumConfiguration);
    q3 = new MainThread(3, clientPortQp3, quorumConfiguration);
    Map<Integer, MainThread> members = new HashMap<>();
    members.put(clientPortQp1, q1);
    members.put(clientPortQp2, q2);
    members.put(clientPortQp3, q3);
    for (MainThread member : members.values()) {
        member.start();
    }
    for (int clientPort : members.keySet()) {
        assertTrue(ClientBase.waitForServerUp("127.0.0.1:" + clientPort, CONNECTION_TIMEOUT));
    }
    // Set SSL system properties and port unification, begin restarting servers
    setSSLSystemProperties();
    stopAppendConfigRestartAll(members, PORT_UNIFICATION_ENABLED);
    stopAppendConfigRestartAll(members, SSL_QUORUM_ENABLED);
    stopAppendConfigRestartAll(members, PORT_UNIFICATION_DISABLED);
}
Also used : BigInteger(java.math.BigInteger) HashMap(java.util.HashMap) CRLDistPoint(org.bouncycastle.asn1.x509.CRLDistPoint) DistributionPoint(org.bouncycastle.asn1.x509.DistributionPoint) SecretUtilsTest(org.apache.zookeeper.common.SecretUtilsTest) Test(org.junit.jupiter.api.Test) Timeout(org.junit.jupiter.api.Timeout)

Example 83 with Timeout

use of org.junit.jupiter.api.Timeout in project zookeeper by apache.

the class QuorumSSLTest method testCertificateRevocationList.

@Test
@Timeout(value = 5, unit = TimeUnit.MINUTES)
public void testCertificateRevocationList() throws Exception {
    q1 = new MainThread(1, clientPortQp1, quorumConfiguration, SSL_QUORUM_ENABLED);
    q2 = new MainThread(2, clientPortQp2, quorumConfiguration, SSL_QUORUM_ENABLED);
    q1.start();
    q2.start();
    assertTrue(ClientBase.waitForServerUp("127.0.0.1:" + clientPortQp1, CONNECTION_TIMEOUT));
    assertTrue(ClientBase.waitForServerUp("127.0.0.1:" + clientPortQp2, CONNECTION_TIMEOUT));
    String revokedInCRLKeystorePath = tmpDir + "/crl_revoked.jks";
    String crlPath = tmpDir + "/crl.pem";
    X509Certificate revokedInCRLCert = buildEndEntityCert(defaultKeyPair, rootCertificate, rootKeyPair.getPrivate(), HOSTNAME, null, crlPath, null);
    writeKeystore(revokedInCRLCert, defaultKeyPair, revokedInCRLKeystorePath);
    buildCRL(revokedInCRLCert, crlPath);
    System.setProperty(quorumX509Util.getSslKeystoreLocationProperty(), revokedInCRLKeystorePath);
    // This server should join successfully
    q3 = new MainThread(3, clientPortQp3, quorumConfiguration, SSL_QUORUM_ENABLED);
    q3.start();
    assertTrue(ClientBase.waitForServerUp("127.0.0.1:" + clientPortQp3, CONNECTION_TIMEOUT));
    q1.shutdown();
    q2.shutdown();
    q3.shutdown();
    assertTrue(ClientBase.waitForServerDown("127.0.0.1:" + clientPortQp1, CONNECTION_TIMEOUT));
    assertTrue(ClientBase.waitForServerDown("127.0.0.1:" + clientPortQp2, CONNECTION_TIMEOUT));
    assertTrue(ClientBase.waitForServerDown("127.0.0.1:" + clientPortQp3, CONNECTION_TIMEOUT));
    setSSLSystemProperties();
    System.setProperty(quorumX509Util.getSslCrlEnabledProperty(), "true");
    X509Certificate validCertificate = buildEndEntityCert(defaultKeyPair, rootCertificate, rootKeyPair.getPrivate(), HOSTNAME, null, crlPath, null);
    writeKeystore(validCertificate, defaultKeyPair, validKeystorePath);
    q1.start();
    q2.start();
    assertTrue(ClientBase.waitForServerUp("127.0.0.1:" + clientPortQp1, CONNECTION_TIMEOUT));
    assertTrue(ClientBase.waitForServerUp("127.0.0.1:" + clientPortQp2, CONNECTION_TIMEOUT));
    System.setProperty(quorumX509Util.getSslKeystoreLocationProperty(), revokedInCRLKeystorePath);
    q3.start();
    assertFalse(ClientBase.waitForServerUp("127.0.0.1:" + clientPortQp3, CONNECTION_TIMEOUT));
}
Also used : X509Certificate(java.security.cert.X509Certificate) SecretUtilsTest(org.apache.zookeeper.common.SecretUtilsTest) Test(org.junit.jupiter.api.Test) Timeout(org.junit.jupiter.api.Timeout)

Example 84 with Timeout

use of org.junit.jupiter.api.Timeout in project zookeeper by apache.

the class QuorumSSLTest method testHostnameVerificationWithInvalidHostname.

@Test
@Timeout(value = 5, unit = TimeUnit.MINUTES)
public void testHostnameVerificationWithInvalidHostname() throws Exception {
    String badhostnameKeystorePath = tmpDir + "/badhost.jks";
    X509Certificate badHostCert = buildEndEntityCert(defaultKeyPair, rootCertificate, rootKeyPair.getPrivate(), "bleepbloop", null, null, null);
    writeKeystore(badHostCert, defaultKeyPair, badhostnameKeystorePath);
    testHostnameVerification(badhostnameKeystorePath, false);
}
Also used : X509Certificate(java.security.cert.X509Certificate) SecretUtilsTest(org.apache.zookeeper.common.SecretUtilsTest) Test(org.junit.jupiter.api.Test) Timeout(org.junit.jupiter.api.Timeout)

Example 85 with Timeout

use of org.junit.jupiter.api.Timeout in project zookeeper by apache.

the class StandaloneDisabledTest method startSingleServerTest.

/**
 * Test normal quorum operations work cleanly
 * with just a single server.
 */
@Test
@Timeout(value = 10, unit = TimeUnit.MINUTES)
public void startSingleServerTest() throws Exception {
    setUpData();
    // start one server
    startServer(leaderId, serverStrings.get(leaderId) + "\n");
    ReconfigTest.testServerHasConfig(zkHandles[leaderId], null, null);
    LOG.info("Initial Configuration:\n{}", new String(zkHandles[leaderId].getConfig(this, new Stat())));
    // start and add 2 followers
    startFollowers();
    testReconfig(leaderId, true, reconfigServers);
    LOG.info("Configuration after adding 2 followers:\n{}", new String(zkHandles[leaderId].getConfig(this, new Stat())));
    // shutdown leader- quorum should still exist
    shutDownServer(leaderId);
    ReconfigTest.testNormalOperation(zkHandles[follower1], zkHandles[follower2]);
    // should not be able to remove follower 2
    // No quorum in new config (1/2)
    reconfigServers.clear();
    reconfigServers.add(Integer.toString(follower2));
    try {
        ReconfigTest.reconfig(zkAdminHandles[follower1], null, reconfigServers, null, -1);
        fail("reconfig completed successfully even though there is no quorum up in new config!");
    } catch (KeeperException.NewConfigNoQuorum e) {
    }
    // reconfigure out leader and follower 1. Remaining follower
    // 2 should elect itself as leader and run by itself
    reconfigServers.clear();
    reconfigServers.add(Integer.toString(leaderId));
    reconfigServers.add(Integer.toString(follower1));
    testReconfig(follower2, false, reconfigServers);
    LOG.info("Configuration after removing leader and follower 1:\n{}", new String(zkHandles[follower2].getConfig(this, new Stat())));
    // Kill server 1 to avoid it interferences with FLE of the quorum {2, 3, 4}.
    shutDownServer(follower1);
    // Try to remove follower2, which is the only remaining server. This should fail.
    reconfigServers.clear();
    reconfigServers.add(Integer.toString(follower2));
    try {
        zkAdminHandles[follower2].reconfigure(null, reconfigServers, null, -1, new Stat());
        fail("reconfig completed successfully even though there is no quorum up in new config!");
    } catch (KeeperException.BadArgumentsException e) {
    // This is expected.
    } catch (Exception e) {
        fail("Should have been BadArgumentsException!");
    }
    // Add two participants and change them to observers to check
    // that we can reconfigure down to one participant with observers.
    ArrayList<String> observerStrings = new ArrayList<String>();
    startObservers(observerStrings);
    // add partcipants
    testReconfig(follower2, true, reconfigServers);
    // change to observers
    testReconfig(follower2, true, observerStrings);
    LOG.info("Configuration after adding two observers:\n{}", new String(zkHandles[follower2].getConfig(this, new Stat())));
    shutDownData();
}
Also used : Stat(org.apache.zookeeper.data.Stat) ArrayList(java.util.ArrayList) KeeperException(org.apache.zookeeper.KeeperException) KeeperException(org.apache.zookeeper.KeeperException) Test(org.junit.jupiter.api.Test) ReconfigTest(org.apache.zookeeper.test.ReconfigTest) Timeout(org.junit.jupiter.api.Timeout)

Aggregations

Timeout (org.junit.jupiter.api.Timeout)291 Test (org.junit.jupiter.api.Test)235 CountDownLatch (java.util.concurrent.CountDownLatch)71 ZooKeeper (org.apache.zookeeper.ZooKeeper)33 AtomicReference (java.util.concurrent.atomic.AtomicReference)32 ArrayList (java.util.ArrayList)31 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)29 RepeatedTest (org.junit.jupiter.api.RepeatedTest)29 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)29 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)28 LocalChannel (io.netty.channel.local.LocalChannel)27 CountdownWatcher (org.apache.zookeeper.test.ClientBase.CountdownWatcher)26 ServerBootstrap (io.netty.bootstrap.ServerBootstrap)25 IOException (java.io.IOException)25 Bootstrap (io.netty.bootstrap.Bootstrap)24 MethodSource (org.junit.jupiter.params.provider.MethodSource)24 Channel (io.netty.channel.Channel)23 NioEventLoopGroup (io.netty.channel.nio.NioEventLoopGroup)21 ChannelHandlerContext (io.netty.channel.ChannelHandlerContext)19 ChannelInboundHandlerAdapter (io.netty.channel.ChannelInboundHandlerAdapter)19