|
| 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 | + |
| 20 | +package org.apache.iotdb.confignode.manager.pipe.source; |
| 21 | + |
| 22 | +import org.apache.iotdb.commons.auth.entity.PrivilegeUnion; |
| 23 | +import org.apache.iotdb.commons.exception.MetadataException; |
| 24 | +import org.apache.iotdb.commons.utils.StatusUtils; |
| 25 | +import org.apache.iotdb.confignode.manager.ConfigManager; |
| 26 | +import org.apache.iotdb.confignode.manager.PermissionManager; |
| 27 | +import org.apache.iotdb.confignode.rpc.thrift.TPermissionInfoResp; |
| 28 | +import org.apache.iotdb.confignode.service.ConfigNode; |
| 29 | +import org.apache.iotdb.db.exception.StorageEngineException; |
| 30 | + |
| 31 | +import org.apache.tsfile.exception.write.WriteProcessException; |
| 32 | +import org.junit.After; |
| 33 | +import org.junit.Assert; |
| 34 | +import org.junit.Before; |
| 35 | +import org.junit.Test; |
| 36 | + |
| 37 | +import java.io.IOException; |
| 38 | + |
| 39 | +public class PipeConfigTreePrivilegeParseVisitorTest { |
| 40 | + |
| 41 | + private final PipeConfigTreePrivilegeParseVisitor skipVisitor = |
| 42 | + new PipeConfigTreePrivilegeParseVisitor(true); |
| 43 | + private final PipeConfigTreePrivilegeParseVisitor throwVisitor = |
| 44 | + new PipeConfigTreePrivilegeParseVisitor(false); |
| 45 | + |
| 46 | + private ConfigNode oldInstance; |
| 47 | + |
| 48 | + @Before |
| 49 | + public void setUp() |
| 50 | + throws IOException, WriteProcessException, MetadataException, InterruptedException { |
| 51 | + oldInstance = ConfigNode.getInstance(); |
| 52 | + ConfigNode.setInstance(new ConfigNode()); |
| 53 | + final ConfigManager configManager = new ConfigManager(); |
| 54 | + configManager.setPermissionManager(new TestPermissionManager()); |
| 55 | + ConfigNode.getInstance().setConfigManager(configManager); |
| 56 | + } |
| 57 | + |
| 58 | + @After |
| 59 | + public void tearDown() throws IOException, StorageEngineException { |
| 60 | + ConfigNode.setInstance(oldInstance); |
| 61 | + } |
| 62 | + |
| 63 | + @Test |
| 64 | + public void testCreateDatabase() { |
| 65 | + Assert.assertTrue(skipVisitor.canReadSysSchema("root.db", null, true)); |
| 66 | + } |
| 67 | + |
| 68 | + private static class TestPermissionManager extends PermissionManager { |
| 69 | + public TestPermissionManager() { |
| 70 | + super(null, null); |
| 71 | + } |
| 72 | + |
| 73 | + @Override |
| 74 | + public TPermissionInfoResp checkUserPrivileges( |
| 75 | + final String username, final PrivilegeUnion union) { |
| 76 | + return new TPermissionInfoResp(StatusUtils.OK); |
| 77 | + } |
| 78 | + } |
| 79 | +} |
0 commit comments