1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.hadoop.hbase.zookeeper;
20
21 import java.io.IOException;
22 import java.util.List;
23
24 import org.apache.hadoop.conf.Configuration;
25 import org.apache.hadoop.hbase.HBaseConfiguration;
26 import org.apache.hadoop.hbase.HConstants;
27 import org.apache.hadoop.hbase.ZooKeeperConnectionException;
28 import org.apache.hadoop.hbase.security.Superusers;
29 import org.apache.hadoop.hbase.testclassification.SmallTests;
30 import org.apache.zookeeper.ZooDefs.Perms;
31 import org.apache.zookeeper.data.ACL;
32 import org.apache.zookeeper.data.Id;
33 import org.junit.Assert;
34 import org.junit.Test;
35 import org.junit.experimental.categories.Category;
36
37
38
39
40 @Category({SmallTests.class})
41 public class TestZKUtil {
42
43 @Test
44 public void testCreateACL() throws ZooKeeperConnectionException, IOException {
45 Configuration conf = HBaseConfiguration.create();
46 conf.set(Superusers.SUPERUSER_CONF_KEY, "user1,@group1,user2,@group2,user3");
47 String node = "/hbase/testCreateACL";
48 ZooKeeperWatcher watcher = new ZooKeeperWatcher(conf, node, null, false);
49 List<ACL> aclList = ZKUtil.createACL(watcher, node, true);
50 Assert.assertEquals(aclList.size(), 4);
51 Assert.assertTrue(!aclList.contains(new ACL(Perms.ALL, new Id("auth", "@group1")))
52 && !aclList.contains(new ACL(Perms.ALL, new Id("auth", "@group2"))));
53 Assert.assertTrue(aclList.contains(new ACL(Perms.ALL, new Id("auth", "user1")))
54 && aclList.contains(new ACL(Perms.ALL, new Id("auth", "user2")))
55 && aclList.contains(new ACL(Perms.ALL, new Id("auth", "user3"))));
56 }
57 }