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 @Category({SmallTests.class})
38 public class TestZKUtil {
39
40 @Test
41 public void testGetZooKeeperClusterKey() {
42 Configuration conf = HBaseConfiguration.create();
43 conf.set(HConstants.ZOOKEEPER_QUORUM, "\tlocalhost\n");
44 conf.set(HConstants.ZOOKEEPER_CLIENT_PORT, "3333");
45 conf.set(HConstants.ZOOKEEPER_ZNODE_PARENT, "hbase");
46 String clusterKey = ZKConfig.getZooKeeperClusterKey(conf, "test");
47 Assert.assertTrue(!clusterKey.contains("\t") && !clusterKey.contains("\n"));
48 Assert.assertEquals("localhost:3333:hbase,test", clusterKey);
49 }
50
51 @Test
52 public void testCreateACL() throws ZooKeeperConnectionException, IOException {
53 Configuration conf = HBaseConfiguration.create();
54 conf.set(Superusers.SUPERUSER_CONF_KEY, "user1,@group1,user2,@group2,user3");
55 String node = "/hbase/testCreateACL";
56 ZooKeeperWatcher watcher = new ZooKeeperWatcher(conf, node, null, false);
57 List<ACL> aclList = ZKUtil.createACL(watcher, node, true);
58 Assert.assertEquals(aclList.size(), 4);
59 Assert.assertTrue(!aclList.contains(new ACL(Perms.ALL, new Id("auth", "@group1")))
60 && !aclList.contains(new ACL(Perms.ALL, new Id("auth", "@group2"))));
61 Assert.assertTrue(aclList.contains(new ACL(Perms.ALL, new Id("auth", "user1")))
62 && aclList.contains(new ACL(Perms.ALL, new Id("auth", "user2")))
63 && aclList.contains(new ACL(Perms.ALL, new Id("auth", "user3"))));
64 }
65 }