diff --git a/acl/src/main/java/org/apache/rocketmq/acl/common/AclUtils.java b/acl/src/main/java/org/apache/rocketmq/acl/common/AclUtils.java index f32acaf2f74..d13c0362bec 100644 --- a/acl/src/main/java/org/apache/rocketmq/acl/common/AclUtils.java +++ b/acl/src/main/java/org/apache/rocketmq/acl/common/AclUtils.java @@ -23,7 +23,7 @@ import java.util.Map; import java.util.SortedMap; -import com.alibaba.fastjson.JSONObject; +import com.alibaba.fastjson2.JSONObject; import org.apache.commons.lang3.StringUtils; import org.apache.rocketmq.common.constant.LoggerName; import org.apache.rocketmq.logging.org.slf4j.Logger; diff --git a/acl/src/test/java/org/apache/rocketmq/acl/common/AclUtilsTest.java b/acl/src/test/java/org/apache/rocketmq/acl/common/AclUtilsTest.java index 03bceade770..be74e54ed33 100644 --- a/acl/src/test/java/org/apache/rocketmq/acl/common/AclUtilsTest.java +++ b/acl/src/test/java/org/apache/rocketmq/acl/common/AclUtilsTest.java @@ -16,7 +16,7 @@ */ package org.apache.rocketmq.acl.common; -import com.alibaba.fastjson.JSONObject; +import com.alibaba.fastjson2.JSONObject; import org.apache.commons.lang3.StringUtils; import org.apache.rocketmq.acl.plain.PlainAccessData; import org.apache.rocketmq.common.PlainAccessConfig; @@ -32,8 +32,13 @@ import java.util.Collections; import java.util.List; import java.util.Map; +import java.util.Objects; import java.util.UUID; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + public class AclUtilsTest { @Test @@ -296,4 +301,25 @@ public void getAclRPCHookTest() throws IOException { Assert.assertNull(incompleteContRPCHook); } } + + @Test + public void testGetAclRPCHookByFileName() { + RPCHook actual = AclUtils.getAclRPCHook(Objects.requireNonNull(AclUtilsTest.class.getResource("/acl_hook/plain_acl.yml")).getPath()); + assertNotNull(actual); + assertTrue(actual instanceof AclClientRPCHook); + assertAclClientRPCHook((AclClientRPCHook) actual); + } + + @Test + public void testGetAclRPCHookByInputStream() { + RPCHook actual = AclUtils.getAclRPCHook(Objects.requireNonNull(AclUtilsTest.class.getResourceAsStream("/acl_hook/plain_acl.yml"))); + assertNotNull(actual); + assertTrue(actual instanceof AclClientRPCHook); + assertAclClientRPCHook((AclClientRPCHook) actual); + } + + private void assertAclClientRPCHook(final AclClientRPCHook actual) { + assertEquals("rocketmq2", actual.getSessionCredentials().getAccessKey()); + assertEquals("12345678", actual.getSessionCredentials().getSecretKey()); + } } diff --git a/acl/src/test/resources/acl_hook/plain_acl.yml b/acl/src/test/resources/acl_hook/plain_acl.yml new file mode 100644 index 00000000000..66bf5762279 --- /dev/null +++ b/acl/src/test/resources/acl_hook/plain_acl.yml @@ -0,0 +1,21 @@ +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +## suggested format + +- accessKey: rocketmq2 + secretKey: 12345678 + whiteRemoteAddress: 192.168.1.* + admin: true