|
19 | 19 |
|
20 | 20 | package org.apache.curator.framework.imps;
|
21 | 21 |
|
| 22 | +import static org.apache.zookeeper.ZooDefs.Ids.ANYONE_ID_UNSAFE; |
22 | 23 | import static org.junit.jupiter.api.Assertions.assertNotNull;
|
23 | 24 | import static org.junit.jupiter.api.Assertions.assertNull;
|
| 25 | +import static org.junit.jupiter.api.Assertions.assertThrows; |
| 26 | +import java.util.Collections; |
24 | 27 | import org.apache.curator.framework.CuratorFramework;
|
25 | 28 | import org.apache.curator.framework.CuratorFrameworkFactory;
|
26 | 29 | import org.apache.curator.framework.EnsureContainers;
|
27 | 30 | import org.apache.curator.retry.RetryOneTime;
|
28 | 31 | import org.apache.curator.test.BaseClassForTests;
|
29 | 32 | import org.apache.curator.utils.CloseableUtils;
|
| 33 | +import org.apache.zookeeper.KeeperException; |
| 34 | +import org.apache.zookeeper.ZooDefs; |
| 35 | +import org.apache.zookeeper.data.ACL; |
30 | 36 | import org.junit.jupiter.api.Test;
|
31 | 37 |
|
32 | 38 | public class TestEnsureContainers extends BaseClassForTests {
|
@@ -63,4 +69,31 @@ public void testSingleExecution() throws Exception {
|
63 | 69 | CloseableUtils.closeQuietly(client);
|
64 | 70 | }
|
65 | 71 | }
|
| 72 | + |
| 73 | + @Test |
| 74 | + public void testNodeExistsButNoCreatePermission() throws Exception { |
| 75 | + CuratorFramework client = CuratorFrameworkFactory.newClient(server.getConnectString(), new RetryOneTime(1)); |
| 76 | + try { |
| 77 | + client.start(); |
| 78 | + |
| 79 | + // given: "/bar/foo" created |
| 80 | + client.create().creatingParentsIfNeeded().forPath("/bar/foo"); |
| 81 | + // given: only permission read to "/bar" |
| 82 | + client.setACL() |
| 83 | + .withACL(Collections.singletonList(new ACL(ZooDefs.Perms.READ, ANYONE_ID_UNSAFE))) |
| 84 | + .forPath("/bar"); |
| 85 | + |
| 86 | + // check: create "/bar/foo" will fail with NoAuth |
| 87 | + assertThrows(KeeperException.NoAuthException.class, () -> { |
| 88 | + client.create().forPath("/bar/foo"); |
| 89 | + }); |
| 90 | + |
| 91 | + // when: mkdirs("/bar/foo") |
| 92 | + // then: everything fine as "/bar/foo" exists, and we have READ permission |
| 93 | + EnsureContainers ensureContainers = new EnsureContainers(client, "/bar/foo"); |
| 94 | + ensureContainers.ensure(); |
| 95 | + } finally { |
| 96 | + CloseableUtils.closeQuietly(client); |
| 97 | + } |
| 98 | + } |
66 | 99 | }
|
0 commit comments