Skip to content

CURATOR-714: Assert that namespace paths are created using CuratorFramework's ACLProvider #505

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,75 @@ public void processResult(CuratorFramework client, CuratorEvent event) throws Ex
}
}

@Test
public void testCreateWithParentsWithAclApplyToParentsInNamespace() throws Exception {
CuratorFramework client = createClient(new DefaultACLProvider());
try {
client.start();

// given: a namespace
CuratorFramework bar = client.usingNamespace("bar");

// when: create a path with custom ACL and applyToParents option open in that namespace
List<ACL> acl =
Collections.singletonList(new ACL(ZooDefs.Perms.CREATE | ZooDefs.Perms.READ, ANYONE_ID_UNSAFE));
bar.create().creatingParentsIfNeeded().withACL(acl, true).forPath("/foo/boo");

// then: the created path has custom ACL
List<ACL> actual_bar_foo_boo = client.getACL().forPath("/bar/foo/boo");
assertEquals(actual_bar_foo_boo, acl);

// then: the parent path has custom ACL
List<ACL> actual_bar_foo = client.getACL().forPath("/bar/foo");
assertEquals(actual_bar_foo, acl);

// then: but the namespace path inherits ACL from CuratorFramework
List<ACL> actual_bar = client.getACL().forPath("/bar");
assertEquals(actual_bar, ZooDefs.Ids.OPEN_ACL_UNSAFE);
} finally {
CloseableUtils.closeQuietly(client);
}
}

@Test
public void testCreateWithParentsWithAclApplyToParentsInNamespaceBackground() throws Exception {
CuratorFramework client = createClient(new DefaultACLProvider());
try {
client.start();

final CountDownLatch latch = new CountDownLatch(1);
BackgroundCallback callback = (client1, event) -> latch.countDown();

List<ACL> acl =
Collections.singletonList(new ACL(ZooDefs.Perms.CREATE | ZooDefs.Perms.READ, ANYONE_ID_UNSAFE));

// given: a namespace
CuratorFramework bar = client.usingNamespace("bar");

// when: create a path with custom ACL and applyToParents option open in that namespace in background
bar.create()
.creatingParentsIfNeeded()
.withACL(acl, true)
.inBackground(callback)
.forPath("/foo/boo");
assertTrue(latch.await(2000, TimeUnit.MILLISECONDS), "Callback not invoked");

// then: the created path has custom ACL
List<ACL> actual_bar_foo_boo = client.getACL().forPath("/bar/foo/boo");
assertEquals(actual_bar_foo_boo, acl);

// then: the parent path has custom ACL
List<ACL> actual_bar_foo = client.getACL().forPath("/bar/foo");
assertEquals(actual_bar_foo, acl);

// then: but the namespace path inherits ACL from CuratorFramework
List<ACL> actual_bar = client.getACL().forPath("/bar");
assertEquals(actual_bar, ZooDefs.Ids.OPEN_ACL_UNSAFE);
} finally {
CloseableUtils.closeQuietly(client);
}
}

/**
* Tests that if no ACL list provided to the create builder, then the ACL list is created based on the client's ACLProvider.
*/
Expand Down Expand Up @@ -235,6 +304,68 @@ public void processResult(CuratorFramework client, CuratorEvent event) throws Ex
}
}

/**
* Tests that if no ACL list provided to the create builder, then the ACL list is created based on the client's ACLProvider.
*/
@Test
public void testCreateWithParentsWithoutAclInNamespace() throws Exception {
CuratorFramework client = createClient(testACLProvider);
try {
client.start();

// given: a namespace
CuratorFramework bar = client.usingNamespace("bar");

// when: create a path in that namespace
bar.create().creatingParentsIfNeeded().forPath("/foo/boo");

// then: all created paths inherit ACLs from CuratorFramework
List<ACL> actual_bar_foo_boo = client.getACL().forPath("/bar/foo/boo");
assertEquals(actual_bar_foo_boo, ZooDefs.Ids.OPEN_ACL_UNSAFE);
List<ACL> actual_bar_foo = client.getACL().forPath("/bar/foo");
assertEquals(actual_bar_foo, READ_CREATE_WRITE);

// then: also the namespace path inherits ACL from CuratorFramework
List<ACL> actual_bar = client.getACL().forPath("/bar");
assertEquals(actual_bar, READ_CREATE);
} finally {
CloseableUtils.closeQuietly(client);
}
}

/**
* Tests that if no ACL list provided to the create builder, then the ACL list is created based on the client's ACLProvider.
*/
@Test
public void testCreateWithParentsWithoutAclInNamespaceBackground() throws Exception {
CuratorFramework client = createClient(testACLProvider);
try {
client.start();

final CountDownLatch latch = new CountDownLatch(1);
BackgroundCallback callback = (client1, event) -> latch.countDown();

// given: a namespace
CuratorFramework bar = client.usingNamespace("bar");

// when: create a path in that namespace in background
bar.create().creatingParentsIfNeeded().inBackground(callback).forPath("/foo/boo");
assertTrue(latch.await(2000, TimeUnit.MILLISECONDS), "Callback not invoked");

// then: all created paths inherit ACLs from CuratorFramework
List<ACL> actual_bar_foo_boo = client.getACL().forPath("/bar/foo/boo");
assertEquals(actual_bar_foo_boo, ZooDefs.Ids.OPEN_ACL_UNSAFE);
List<ACL> actual_bar_foo = client.getACL().forPath("/bar/foo");
assertEquals(actual_bar_foo, READ_CREATE_WRITE);

// then: also the namespace path inherits ACL from CuratorFramework
List<ACL> actual_bar = client.getACL().forPath("/bar");
assertEquals(actual_bar, READ_CREATE);
} finally {
CloseableUtils.closeQuietly(client);
}
}

private void check(
CuratorFramework client, CreateBuilderMain builder, String path, byte[] data, boolean expectedSuccess)
throws Exception {
Expand Down
Loading