Skip to content

Commit

Permalink
[ISSUE #4624] Add plain_acl_bak.xml for reset at test case start. (#4625
Browse files Browse the repository at this point in the history
)

* add plain_acl_bak.xml to reset at test case start.

* add license

* reset file at test case start
  • Loading branch information
lizhiboo committed Jul 18, 2022
1 parent ac6ccc5 commit d930cb9
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -470,9 +470,12 @@ public void validateGetAllTopicConfigTest() {

@Test
public void addAccessAclYamlConfigTest() throws InterruptedException {
String backupFileName = System.getProperty("rocketmq.home.dir")
+ File.separator + "conf/plain_acl_bak.yml".replace("/", File.separator);
String targetFileName = System.getProperty("rocketmq.home.dir")
+ File.separator + "conf/plain_acl.yml".replace("/", File.separator);
Map<String, Object> backUpAclConfigMap = AclUtils.getYamlDataObject(targetFileName, Map.class);
+ File.separator + "conf/plain_acl.yml".replace("/", File.separator);
Map<String, Object> backUpAclConfigMap = AclUtils.getYamlDataObject(backupFileName, Map.class);
AclUtils.writeDataObject(targetFileName, backUpAclConfigMap);

PlainAccessConfig plainAccessConfig = new PlainAccessConfig();
plainAccessConfig.setAccessKey("rocketmq3");
Expand Down Expand Up @@ -552,8 +555,12 @@ public void getAccessAclYamlConfigTest() {

@Test
public void updateAccessAclYamlConfigTest() throws InterruptedException {
String targetFileName = System.getProperty("rocketmq.home.dir") + File.separator + "conf/plain_acl.yml";
Map<String, Object> backUpAclConfigMap = AclUtils.getYamlDataObject(targetFileName, Map.class);
String backupFileName = System.getProperty("rocketmq.home.dir")
+ File.separator + "conf/plain_acl_bak.yml".replace("/", File.separator);
String targetFileName = System.getProperty("rocketmq.home.dir")
+ File.separator + "conf/plain_acl.yml".replace("/", File.separator);
Map<String, Object> backUpAclConfigMap = AclUtils.getYamlDataObject(backupFileName, Map.class);
AclUtils.writeDataObject(targetFileName, backUpAclConfigMap);

PlainAccessConfig plainAccessConfig = new PlainAccessConfig();
plainAccessConfig.setAccessKey("rocketmq3");
Expand Down Expand Up @@ -628,9 +635,12 @@ public void updateAccessAclYamlConfigTest() throws InterruptedException {

@Test
public void deleteAccessAclYamlConfigTest() throws InterruptedException {
String backupFileName = System.getProperty("rocketmq.home.dir")
+ File.separator + "conf/plain_acl_bak.yml".replace("/", File.separator);
String targetFileName = System.getProperty("rocketmq.home.dir")
+ File.separator + "conf/plain_acl.yml".replace("/", File.separator);
Map<String, Object> backUpAclConfigMap = AclUtils.getYamlDataObject(targetFileName, Map.class);
+ File.separator + "conf/plain_acl.yml".replace("/", File.separator);
Map<String, Object> backUpAclConfigMap = AclUtils.getYamlDataObject(backupFileName, Map.class);
AclUtils.writeDataObject(targetFileName, backUpAclConfigMap);

PlainAccessConfig plainAccessConfig = new PlainAccessConfig();
plainAccessConfig.setAccessKey("rocketmq3");
Expand Down Expand Up @@ -676,9 +686,12 @@ public void deleteAccessAclYamlConfigTest() throws InterruptedException {

@Test
public void updateGlobalWhiteRemoteAddressesTest() throws InterruptedException {
String backupFileName = System.getProperty("rocketmq.home.dir")
+ File.separator + "conf/plain_acl_bak.yml".replace("/", File.separator);
String targetFileName = System.getProperty("rocketmq.home.dir")
+ File.separator + "conf/plain_acl.yml".replace("/", File.separator);
Map<String, Object> backUpAclConfigMap = AclUtils.getYamlDataObject(targetFileName, Map.class);
+ File.separator + "conf/plain_acl.yml".replace("/", File.separator);
Map<String, Object> backUpAclConfigMap = AclUtils.getYamlDataObject(backupFileName, Map.class);
AclUtils.writeDataObject(targetFileName, backUpAclConfigMap);

List<String> globalWhiteAddrsList = new ArrayList<>();
globalWhiteAddrsList.add("192.168.1.*");
Expand Down Expand Up @@ -794,9 +807,12 @@ public void updateAccessAnotherAclYamlConfigTest() throws IOException, Interrupt

@Test(expected = AclException.class)
public void createAndUpdateAccessAclNullSkExceptionTest() {
String backupFileName = System.getProperty("rocketmq.home.dir")
+ File.separator + "conf/plain_acl_bak.yml".replace("/", File.separator);
String targetFileName = System.getProperty("rocketmq.home.dir")
+ File.separator + "conf/acl/plain_acl.yml".replace("/", File.separator);
Map<String, Object> backUpAclConfigMap = AclUtils.getYamlDataObject(targetFileName, Map.class);
+ File.separator + "conf/plain_acl.yml".replace("/", File.separator);
Map<String, Object> backUpAclConfigMap = AclUtils.getYamlDataObject(backupFileName, Map.class);
AclUtils.writeDataObject(targetFileName, backUpAclConfigMap);

PlainAccessConfig plainAccessConfig = new PlainAccessConfig();
plainAccessConfig.setAccessKey("RocketMQ33");
Expand All @@ -811,9 +827,12 @@ public void createAndUpdateAccessAclNullSkExceptionTest() {
@Test
public void addAccessDefaultAclYamlConfigTest() throws InterruptedException {
PlainAccessValidator plainAccessValidator = new PlainAccessValidator();
String backupFileName = System.getProperty("rocketmq.home.dir")
+ File.separator + "conf/plain_acl_bak.yml".replace("/", File.separator);
String targetFileName = System.getProperty("rocketmq.home.dir")
+ File.separator + "conf/plain_acl.yml".replace("/", File.separator);
Map<String, Object> backUpAclConfigMap = AclUtils.getYamlDataObject(targetFileName, Map.class);
+ File.separator + "conf/plain_acl.yml".replace("/", File.separator);
Map<String, Object> backUpAclConfigMap = AclUtils.getYamlDataObject(backupFileName, Map.class);
AclUtils.writeDataObject(targetFileName, backUpAclConfigMap);

PlainAccessConfig plainAccessConfig = new PlainAccessConfig();
plainAccessConfig.setAccessKey("watchrocketmqh");
Expand Down Expand Up @@ -903,9 +922,12 @@ public void getAllAclConfigTest() {

@Test
public void updateAccessConfigEmptyPermListTest() {
String backupFileName = System.getProperty("rocketmq.home.dir")
+ File.separator + "conf/plain_acl_bak.yml".replace("/", File.separator);
String targetFileName = System.getProperty("rocketmq.home.dir")
+ File.separator + "conf/plain_acl.yml".replace("/", File.separator);
Map<String, Object> backUpAclConfigMap = AclUtils.getYamlDataObject(targetFileName, Map.class);
+ File.separator + "conf/plain_acl.yml".replace("/", File.separator);
Map<String, Object> backUpAclConfigMap = AclUtils.getYamlDataObject(backupFileName, Map.class);
AclUtils.writeDataObject(targetFileName, backUpAclConfigMap);

PlainAccessValidator plainAccessValidator = new PlainAccessValidator();
PlainAccessConfig plainAccessConfig = new PlainAccessConfig();
Expand All @@ -932,9 +954,12 @@ public void updateAccessConfigEmptyPermListTest() {

@Test
public void updateAccessConfigEmptyWhiteRemoteAddressTest() {
String backupFileName = System.getProperty("rocketmq.home.dir")
+ File.separator + "conf/plain_acl_bak.yml".replace("/", File.separator);
String targetFileName = System.getProperty("rocketmq.home.dir")
+ File.separator + "conf/plain_acl.yml".replace("/", File.separator);
Map<String, Object> backUpAclConfigMap = AclUtils.getYamlDataObject(targetFileName, Map.class);
+ File.separator + "conf/plain_acl.yml".replace("/", File.separator);
Map<String, Object> backUpAclConfigMap = AclUtils.getYamlDataObject(backupFileName, Map.class);
AclUtils.writeDataObject(targetFileName, backUpAclConfigMap);

PlainAccessValidator plainAccessValidator = new PlainAccessValidator();
PlainAccessConfig plainAccessConfig = new PlainAccessConfig();
Expand Down
39 changes: 39 additions & 0 deletions acl/src/test/resources/conf/plain_acl_bak.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# 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

globalWhiteRemoteAddresses:
- 10.10.103.*
- 192.168.0.*
accounts:
- accessKey: RocketMQ
secretKey: 12345678
whiteRemoteAddress: 192.168.0.*
admin: false
defaultTopicPerm: DENY
defaultGroupPerm: SUB
topicPerms:
- topicA=DENY
- topicB=PUB|SUB
- topicC=SUB
groupPerms:
- groupA=DENY
- groupB=SUB
- groupC=SUB
- accessKey: rocketmq2
secretKey: 12345678
whiteRemoteAddress: 192.168.1.*
admin: true

0 comments on commit d930cb9

Please sign in to comment.