|
| 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, software |
| 13 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | + * See the License for the specific language governing permissions and |
| 16 | + * limitations under the License. |
| 17 | + */ |
| 18 | + |
| 19 | +package org.apache.zookeeper.server.auth.znode.groupacl; |
| 20 | + |
| 21 | +import java.util.Collections; |
| 22 | +import java.util.HashMap; |
| 23 | +import java.util.List; |
| 24 | +import java.util.Map; |
| 25 | + |
| 26 | +import org.apache.zookeeper.KeeperException; |
| 27 | +import org.apache.zookeeper.ZooDefs; |
| 28 | +import org.apache.zookeeper.data.ACL; |
| 29 | +import org.apache.zookeeper.data.Id; |
| 30 | +import org.apache.zookeeper.server.PrepRequestProcessor; |
| 31 | +import org.apache.zookeeper.server.auth.X509AuthenticationConfig; |
| 32 | +import org.junit.AfterClass; |
| 33 | +import org.junit.Assert; |
| 34 | +import org.junit.BeforeClass; |
| 35 | +import org.junit.Test; |
| 36 | + |
| 37 | +/** |
| 38 | + * This class test fixupACL method in {@link org.apache.zookeeper.server.PrepRequestProcessor} |
| 39 | + * under the znode group acl settings |
| 40 | + */ |
| 41 | +public class TestFixupACL { |
| 42 | + private final List<Id> superUserAuthInfo = |
| 43 | + Collections.singletonList(new Id("super", "superUserId")); |
| 44 | + private final List<Id> crossDomainComponentAuthInfo = |
| 45 | + Collections.singletonList(new Id("super", "crossDomain")); |
| 46 | + private final List<ACL> aclList = |
| 47 | + Collections.singletonList(new ACL(ZooDefs.Perms.ALL, new Id("x509", "toBeAdded"))); |
| 48 | + private final String testPath = "/zookeeper/testPath"; |
| 49 | + private static final Map<String, String> SYSTEM_PROPERTIES = new HashMap<>(); |
| 50 | + |
| 51 | + static { |
| 52 | + SYSTEM_PROPERTIES.put(X509AuthenticationConfig.SET_X509_CLIENT_ID_AS_ACL, "true"); |
| 53 | + SYSTEM_PROPERTIES |
| 54 | + .put(X509AuthenticationConfig.ZOOKEEPER_ZNODEGROUPACL_SUPERUSER_ID, "superUserId"); |
| 55 | + SYSTEM_PROPERTIES.put(X509AuthenticationConfig.CROSS_DOMAIN_ACCESS_DOMAIN_NAME, "crossDomain"); |
| 56 | + } |
| 57 | + |
| 58 | + @BeforeClass |
| 59 | + public static void beforeClass() { |
| 60 | + SYSTEM_PROPERTIES.forEach(System::setProperty); |
| 61 | + } |
| 62 | + |
| 63 | + @AfterClass |
| 64 | + public static void afterClass() { |
| 65 | + SYSTEM_PROPERTIES.keySet().forEach(System::clearProperty); |
| 66 | + } |
| 67 | + |
| 68 | + @Test |
| 69 | + public void testCrossDomainComponents() throws KeeperException.InvalidACLException { |
| 70 | + List<ACL> returnedList = |
| 71 | + PrepRequestProcessor.fixupACL(testPath, crossDomainComponentAuthInfo, aclList); |
| 72 | + Assert.assertEquals(1, returnedList.size()); |
| 73 | + Id returnedId = returnedList.get(0).getId(); |
| 74 | + Assert.assertEquals("x509", returnedId.getScheme()); |
| 75 | + Assert.assertEquals("crossDomain", returnedId.getId()); |
| 76 | + } |
| 77 | + |
| 78 | + @Test |
| 79 | + public void testSuperUserId() throws KeeperException.InvalidACLException { |
| 80 | + List<ACL> returnedList = |
| 81 | + PrepRequestProcessor.fixupACL(testPath, superUserAuthInfo, aclList); |
| 82 | + Assert.assertEquals(1, returnedList.size()); |
| 83 | + Id returnedId = returnedList.get(0).getId(); |
| 84 | + Assert.assertEquals("x509", returnedId.getScheme()); |
| 85 | + Assert.assertEquals("toBeAdded", returnedId.getId()); |
| 86 | + } |
| 87 | +} |
0 commit comments