use of org.junit.jupiter.api.Timeout in project zookeeper by apache.
the class MiniKdcTest method testKerberosLogin.
@Test
@Timeout(value = 60)
public void testKerberosLogin() throws Exception {
MiniKdc kdc = getKdc();
File workDir = getWorkDir();
LoginContext loginContext = null;
try {
String principal = "foo";
File keytab = new File(workDir, "foo.keytab");
kdc.createPrincipal(keytab, principal);
Set<Principal> principals = new HashSet<Principal>();
principals.add(new KerberosPrincipal(principal));
// client login
Subject subject = new Subject(false, principals, new HashSet<Object>(), new HashSet<Object>());
loginContext = new LoginContext("", subject, null, KerberosConfiguration.createClientConfig(principal, keytab));
loginContext.login();
subject = loginContext.getSubject();
assertEquals(1, subject.getPrincipals().size());
assertEquals(KerberosPrincipal.class, subject.getPrincipals().iterator().next().getClass());
assertEquals(principal + "@" + kdc.getRealm(), subject.getPrincipals().iterator().next().getName());
loginContext.logout();
// server login
subject = new Subject(false, principals, new HashSet<Object>(), new HashSet<Object>());
loginContext = new LoginContext("", subject, null, KerberosConfiguration.createServerConfig(principal, keytab));
loginContext.login();
subject = loginContext.getSubject();
assertEquals(1, subject.getPrincipals().size());
assertEquals(KerberosPrincipal.class, subject.getPrincipals().iterator().next().getClass());
assertEquals(principal + "@" + kdc.getRealm(), subject.getPrincipals().iterator().next().getName());
loginContext.logout();
} finally {
if (loginContext != null && loginContext.getSubject() != null && !loginContext.getSubject().getPrincipals().isEmpty()) {
loginContext.logout();
}
}
}
use of org.junit.jupiter.api.Timeout in project zookeeper by apache.
the class QuorumAuthUpgradeTest method testAuthLearnerServer.
/**
* Test to verify that servers are able to form quorum.
* peer0 -> quorum.auth.enableSasl=true, quorum.auth.learnerRequireSasl=true, quorum.auth.serverRequireSasl=true
* peer1 -> quorum.auth.enableSasl=true, quorum.auth.learnerRequireSasl=true, quorum.auth.serverRequireSasl=true
*/
@Test
@Timeout(value = 30)
public void testAuthLearnerServer() throws Exception {
Map<String, String> authConfigs = new HashMap<String, String>();
authConfigs.put(QuorumAuth.QUORUM_SASL_AUTH_ENABLED, "true");
authConfigs.put(QuorumAuth.QUORUM_SERVER_SASL_AUTH_REQUIRED, "true");
authConfigs.put(QuorumAuth.QUORUM_LEARNER_SASL_AUTH_REQUIRED, "true");
String connectStr = startQuorum(2, authConfigs, 2);
CountdownWatcher watcher = new CountdownWatcher();
ZooKeeper zk = new ZooKeeper(connectStr, ClientBase.CONNECTION_TIMEOUT, watcher);
watcher.waitForConnected(ClientBase.CONNECTION_TIMEOUT);
zk.create("/foo", new byte[0], Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
zk.close();
}
use of org.junit.jupiter.api.Timeout in project zookeeper by apache.
the class ReconfigLegacyTest method testRestartZooKeeperServer.
/**
* Test case for https://issues.apache.org/jira/browse/ZOOKEEPER-2244
*
* @throws Exception
*/
@Test
@Timeout(value = 120)
public void testRestartZooKeeperServer() throws Exception {
final int[] clientPorts = new int[SERVER_COUNT];
StringBuilder sb = new StringBuilder();
String server;
for (int i = 0; i < SERVER_COUNT; i++) {
clientPorts[i] = PortAssignment.unique();
server = "server." + i + "=127.0.0.1:" + PortAssignment.unique() + ":" + PortAssignment.unique() + ":participant;127.0.0.1:" + clientPorts[i];
sb.append(server + "\n");
}
String currentQuorumCfgSection = sb.toString();
MainThread[] mt = new MainThread[SERVER_COUNT];
for (int i = 0; i < SERVER_COUNT; i++) {
mt[i] = new MainThread(i, clientPorts[i], currentQuorumCfgSection, false);
mt[i].start();
}
// ensure server started
for (int i = 0; i < SERVER_COUNT; i++) {
assertTrue(ClientBase.waitForServerUp("127.0.0.1:" + clientPorts[i], CONNECTION_TIMEOUT), "waiting for server " + i + " being up");
}
ZooKeeper zk = ClientBase.createZKClient("127.0.0.1:" + clientPorts[0]);
String zNodePath = "/serverRestartTest";
String data = "originalData";
zk.create(zNodePath, data.getBytes(), Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
zk.close();
/**
* stop two servers out of three and again start them
*/
mt[0].shutdown();
mt[1].shutdown();
mt[0].start();
mt[1].start();
// ensure server started
for (int i = 0; i < SERVER_COUNT; i++) {
assertTrue(ClientBase.waitForServerUp("127.0.0.1:" + clientPorts[i], CONNECTION_TIMEOUT), "waiting for server " + i + " being up");
}
zk = ClientBase.createZKClient("127.0.0.1:" + clientPorts[0]);
byte[] dataBytes = zk.getData(zNodePath, null, null);
String receivedData = new String(dataBytes);
assertEquals(data, receivedData);
for (int i = 0; i < SERVER_COUNT; i++) {
mt[i].shutdown();
}
}
use of org.junit.jupiter.api.Timeout in project zookeeper by apache.
the class FourLetterWordsTest method testFourLetterWords.
/**
* Test the various four letter words
*/
@Test
@Timeout(value = 30)
public void testFourLetterWords() throws Exception {
verify("ruok", "imok");
verify("envi", "java.version");
verify("conf", "clientPort");
verify("stat", "Outstanding");
verify("srvr", "Outstanding");
verify("cons", "queued");
verify("dump", "Session");
verify("wchs", "watches");
verify("wchp", "");
verify("wchc", "");
verify("srst", "reset");
verify("crst", "reset");
verify("stat", "Outstanding");
verify("srvr", "Outstanding");
verify("cons", "queued");
verify("gtmk", "306");
verify("isro", "rw");
TestableZooKeeper zk = createClient();
String sid = getHexSessionId(zk.getSessionId());
verify("stat", "queued");
verify("srvr", "Outstanding");
verify("cons", sid);
verify("dump", sid);
verify("dirs", "size");
zk.getData("/", true, null);
verify("stat", "queued");
verify("srvr", "Outstanding");
verify("cons", sid);
verify("dump", sid);
verify("wchs", "watching 1");
verify("wchp", sid);
verify("wchc", sid);
verify("dirs", "size");
zk.close();
verify("ruok", "imok");
verify("envi", "java.version");
verify("conf", "clientPort");
verify("stat", "Outstanding");
verify("srvr", "Outstanding");
verify("cons", "queued");
verify("dump", "Session");
verify("wchs", "watch");
verify("wchp", "");
verify("wchc", "");
verify("srst", "reset");
verify("crst", "reset");
verify("stat", "Outstanding");
verify("srvr", "Outstanding");
verify("cons", "queued");
verify("mntr", "zk_server_state\tstandalone");
verify("mntr", "num_alive_connections");
verify("stat", "Connections");
verify("srvr", "Connections");
verify("dirs", "size");
}
use of org.junit.jupiter.api.Timeout in project zookeeper by apache.
the class FourLetterWordsWhiteListTest method testFourLetterWordsAllDisabledByDefault.
/*
* ZOOKEEPER-2693: test white list of four letter words.
* For 3.5.x default white list is empty. Verify that is
* the case (except 'stat' command which is enabled in ClientBase
* which other tests depend on.).
*/
@Test
@Timeout(value = 30)
public void testFourLetterWordsAllDisabledByDefault() throws Exception {
stopServer();
FourLetterCommands.resetWhiteList();
System.setProperty("zookeeper.4lw.commands.whitelist", "stat");
startServer();
// Default white list for 3.5.x is empty, so all command should fail.
verifyAllCommandsFail();
TestableZooKeeper zk = createClient();
verifyAllCommandsFail();
zk.getData("/", true, null);
verifyAllCommandsFail();
zk.close();
verifyFuzzyMatch("stat", "Outstanding");
verifyAllCommandsFail();
}
Aggregations