View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
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); // 3+1, since ACL will be set for the creator by default
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  }