use of org.apache.flink.shaded.zookeeper3.org.apache.zookeeper.data.ACL in project zookeeper by apache.
the class LearnerTest method syncTest.
@Test
public void syncTest() throws Exception {
File tmpFile = File.createTempFile("test", ".dir", testData);
tmpFile.delete();
try {
FileTxnSnapLog ftsl = new FileTxnSnapLog(tmpFile, tmpFile);
SimpleLearner sl = new SimpleLearner(ftsl);
long startZxid = sl.zk.getLastProcessedZxid();
// Set up bogus streams
ByteArrayOutputStream baos = new ByteArrayOutputStream();
BinaryOutputArchive oa = BinaryOutputArchive.getArchive(baos);
sl.leaderOs = BinaryOutputArchive.getArchive(new ByteArrayOutputStream());
// make streams and socket do something innocuous
sl.bufferedOutput = new BufferedOutputStream(System.out);
sl.sock = new Socket();
// fake messages from the server
QuorumPacket qp = new QuorumPacket(Leader.SNAP, 0, null, null);
oa.writeRecord(qp, null);
sl.zk.getZKDatabase().serializeSnapshot(oa);
oa.writeString("BenWasHere", "signature");
TxnHeader hdr = new TxnHeader(0, 0, 0, 0, ZooDefs.OpCode.create);
CreateTxn txn = new CreateTxn("/foo", new byte[0], new ArrayList<ACL>(), false, sl.zk.getZKDatabase().getNode("/").stat.getCversion());
ByteArrayOutputStream tbaos = new ByteArrayOutputStream();
BinaryOutputArchive boa = BinaryOutputArchive.getArchive(tbaos);
hdr.serialize(boa, "hdr");
txn.serialize(boa, "txn");
tbaos.close();
qp = new QuorumPacket(Leader.PROPOSAL, 1, tbaos.toByteArray(), null);
oa.writeRecord(qp, null);
// setup the messages to be streamed to follower
sl.leaderIs = BinaryInputArchive.getArchive(new ByteArrayInputStream(baos.toByteArray()));
try {
sl.syncWithLeader(3);
} catch (EOFException e) {
}
sl.zk.shutdown();
sl = new SimpleLearner(ftsl);
assertEquals(startZxid, sl.zk.getLastProcessedZxid());
} finally {
TestUtils.deleteFileRecursively(tmpFile);
}
}
use of org.apache.flink.shaded.zookeeper3.org.apache.zookeeper.data.ACL in project zookeeper by apache.
the class KeyAuthClientTest method createNodePrintAcl.
public void createNodePrintAcl(ZooKeeper zk, String path, String testName) {
try {
LOG.debug("KeyAuthenticationProvider Creating Test Node:{}\n", path);
zk.create(path, null, Ids.CREATOR_ALL_ACL, CreateMode.PERSISTENT);
List<ACL> acls = zk.getACL(path, null);
LOG.debug("Node:{} Test:{} ACLs:", path, testName);
for (ACL acl : acls) {
LOG.debug(" {}", acl.toString());
}
} catch (Exception e) {
LOG.debug(" EXCEPTION THROWN", e);
}
}
use of org.apache.flink.shaded.zookeeper3.org.apache.zookeeper.data.ACL in project zookeeper by apache.
the class MultiOperationTest method testMultiGetChildrenAuthentication.
@ParameterizedTest
@ValueSource(booleans = { true, false })
public void testMultiGetChildrenAuthentication(boolean useAsync) throws KeeperException, InterruptedException {
List<ACL> writeOnly = Collections.singletonList(new ACL(ZooDefs.Perms.WRITE, new Id("world", "anyone")));
zk.create("/foo_auth", null, Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
zk.create("/foo_auth/bar", null, Ids.READ_ACL_UNSAFE, CreateMode.PERSISTENT);
zk.create("/foo_no_auth", null, writeOnly, CreateMode.PERSISTENT);
// Check for normal behaviour.
List<OpResult> multiChildrenList = multi(zk, Arrays.asList(Op.getChildren("/foo_auth")), useAsync);
assertEquals(multiChildrenList.size(), 1);
assertTrue(multiChildrenList.get(0) instanceof OpResult.GetChildrenResult);
List<String> childrenList = ((OpResult.GetChildrenResult) multiChildrenList.get(0)).getChildren();
assertEquals(childrenList.size(), 1);
assertEquals(childrenList.get(0), "bar");
// Check for authentication violation.
multiChildrenList = multi(zk, Arrays.asList(Op.getChildren("/foo_no_auth")), useAsync);
assertEquals(multiChildrenList.size(), 1);
assertTrue(multiChildrenList.get(0) instanceof OpResult.ErrorResult);
assertEquals(((OpResult.ErrorResult) multiChildrenList.get(0)).getErr(), KeeperException.Code.NOAUTH.intValue(), "Expected NoAuthException for getting the children of a write only node");
}
use of org.apache.flink.shaded.zookeeper3.org.apache.zookeeper.data.ACL in project zookeeper by apache.
the class MultiOperationTest method testMultiGetChildrenMixedAuthenticationCorrectFirst.
@ParameterizedTest
@ValueSource(booleans = { true, false })
public void testMultiGetChildrenMixedAuthenticationCorrectFirst(boolean useAsync) throws KeeperException, InterruptedException {
List<ACL> writeOnly = Collections.singletonList(new ACL(ZooDefs.Perms.WRITE, new Id("world", "anyone")));
zk.create("/foo_auth", null, Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
zk.create("/foo_auth/bar", null, Ids.READ_ACL_UNSAFE, CreateMode.PERSISTENT);
zk.create("/foo_no_auth", null, writeOnly, CreateMode.PERSISTENT);
// Check for getting the children of the nodes with mixed authentication.
// The getChildren operation returns GetChildrenResult if it happened before the error.
List<OpResult> multiChildrenList;
multiChildrenList = multi(zk, Arrays.asList(Op.getChildren("/foo_auth"), Op.getChildren("/foo_no_auth")), useAsync);
assertSame(multiChildrenList.size(), 2);
assertTrue(multiChildrenList.get(0) instanceof OpResult.GetChildrenResult);
List<String> childrenList = ((OpResult.GetChildrenResult) multiChildrenList.get(0)).getChildren();
assertEquals(childrenList.size(), 1);
assertEquals(childrenList.get(0), "bar");
assertTrue(multiChildrenList.get(1) instanceof OpResult.ErrorResult);
assertEquals(((OpResult.ErrorResult) multiChildrenList.get(1)).getErr(), KeeperException.Code.NOAUTH.intValue(), "Expected NoAuthException for getting the children of a write only node");
}
use of org.apache.flink.shaded.zookeeper3.org.apache.zookeeper.data.ACL in project zookeeper by apache.
the class FinalRequestProcessorTest method testACLDigestHashHiding_OnlyAdmin.
@Test
public void testACLDigestHashHiding_OnlyAdmin() {
// Arrange
testACLs.clear();
testACLs.addAll(Arrays.asList(new ACL(ZooDefs.Perms.READ, new Id("digest", "user:secrethash")), new ACL(ZooDefs.Perms.ADMIN, new Id("digest", "adminuser:adminsecret"))));
List<Id> authInfo = new ArrayList<Id>();
authInfo.add(new Id("digest", "adminuser:adminsecret"));
// Act
Request r = new Request(cnxn, 0, 0, ZooDefs.OpCode.getACL, bb, authInfo);
processor.processRequest(r);
// Assert
assertTrue(responseRecord[0] instanceof GetACLResponse, "Not a GetACL response. Auth failed?");
GetACLResponse rsp = (GetACLResponse) responseRecord[0];
assertThat("Number of ACLs in the response are different", rsp.getAcl().size(), equalTo(2));
// Verify ACLs in the response
assertThat("Password hash mismatch in the response", rsp.getAcl().get(0).getId().getId(), equalTo("user:secrethash"));
assertThat("Password hash mismatch in the response", rsp.getAcl().get(1).getId().getId(), equalTo("adminuser:adminsecret"));
}
Aggregations