use of org.apache.zookeeper.server.quorum.QuorumPeerTestBase.MainThread in project zookeeper by apache.
the class QuorumDigestAuthTest method testEnableQuorumAuthenticationConfigurations.
/**
* If quorumpeer learner is not auth enabled then self won't be able to join
* quorum. So this test is ensuring that the quorumpeer learner is also auth
* enabled while enabling quorum server require sasl.
*/
@Test(timeout = 10000)
public void testEnableQuorumAuthenticationConfigurations() throws Exception {
Map<String, String> authConfigs = new HashMap<String, String>();
authConfigs.put(QuorumAuth.QUORUM_LEARNER_SASL_LOGIN_CONTEXT, "QuorumLearner");
authConfigs.put(QuorumAuth.QUORUM_SASL_AUTH_ENABLED, "false");
// case-1) 'quorum.auth.enableSasl' is off. Tries to enable server sasl.
authConfigs.put(QuorumAuth.QUORUM_SERVER_SASL_AUTH_REQUIRED, "true");
authConfigs.put(QuorumAuth.QUORUM_LEARNER_SASL_AUTH_REQUIRED, "false");
MainThread mthread = new MainThread(1, PortAssignment.unique(), "", authConfigs);
String[] args = new String[1];
args[0] = mthread.getConfFile().toString();
try {
new QuorumPeerMain() {
@Override
protected void initializeAndRun(String[] args) throws ConfigException, IOException, AdminServer.AdminServerException {
super.initializeAndRun(args);
}
}.initializeAndRun(args);
Assert.fail("Must throw exception as quorum sasl is not enabled!");
} catch (ConfigException e) {
// expected
}
// case-1) 'quorum.auth.enableSasl' is off. Tries to enable learner sasl.
authConfigs.put(QuorumAuth.QUORUM_SERVER_SASL_AUTH_REQUIRED, "false");
authConfigs.put(QuorumAuth.QUORUM_LEARNER_SASL_AUTH_REQUIRED, "true");
try {
new QuorumPeerMain() {
@Override
protected void initializeAndRun(String[] args) throws ConfigException, IOException, AdminServer.AdminServerException {
super.initializeAndRun(args);
}
}.initializeAndRun(args);
Assert.fail("Must throw exception as quorum sasl is not enabled!");
} catch (ConfigException e) {
// expected
}
}
use of org.apache.zookeeper.server.quorum.QuorumPeerTestBase.MainThread in project zookeeper by apache.
the class QuorumKerberosHostBasedAuthTest method testConnectBadServer.
/**
* Test to verify that the bad server connection to the quorum should be rejected.
*/
@Test(timeout = 120000)
public void testConnectBadServer() throws Exception {
String serverPrincipal = hostServerPrincipal.substring(0, hostServerPrincipal.lastIndexOf("@"));
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");
authConfigs.put(QuorumAuth.QUORUM_KERBEROS_SERVICE_PRINCIPAL, serverPrincipal);
String connectStr = startQuorum(3, authConfigs, 3);
CountdownWatcher watcher = new CountdownWatcher();
ZooKeeper zk = new ZooKeeper(connectStr, ClientBase.CONNECTION_TIMEOUT, watcher);
watcher.waitForConnected(ClientBase.CONNECTION_TIMEOUT);
for (int i = 0; i < 10; i++) {
zk.create("/" + i, new byte[0], Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
}
zk.close();
String quorumCfgSection = mt.get(0).getQuorumCfgSection();
StringBuilder sb = new StringBuilder();
sb.append(quorumCfgSection);
int myid = mt.size() + 1;
final int clientPort = PortAssignment.unique();
String server = String.format("server.%d=localhost:%d:%d:participant", myid, PortAssignment.unique(), PortAssignment.unique());
sb.append(server + "\n");
quorumCfgSection = sb.toString();
authConfigs.put(QuorumAuth.QUORUM_LEARNER_SASL_LOGIN_CONTEXT, "QuorumLearnerMyHost");
MainThread badServer = new MainThread(myid, clientPort, quorumCfgSection, authConfigs);
badServer.start();
watcher = new CountdownWatcher();
connectStr = "127.0.0.1:" + clientPort;
zk = new ZooKeeper(connectStr, ClientBase.CONNECTION_TIMEOUT, watcher);
try {
watcher.waitForConnected(ClientBase.CONNECTION_TIMEOUT / 3);
Assert.fail("Must throw exception as the myHost is not an authorized one!");
} catch (TimeoutException e) {
// expected
} finally {
zk.close();
badServer.shutdown();
badServer.deleteBaseDir();
}
}
Aggregations