diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
index b7b133472c46a8b00b57230e9f21735667086b99..952ad7398a9269ff84e9571faba8e3411ae72c05 100644
--- a/CONTRIBUTING.md
+++ b/CONTRIBUTING.md
@@ -10,7 +10,7 @@ Nor is code the only way to contribute to the project. We strongly value documen
To submit a change for inclusion, please do the following:
#### If the change is non-trivial please include some unit tests that cover the new functionality.
-#### If you are introducing a completely new feature or API it is a good idea to start a wiki and get consensus on the basic design first.
+#### If you are introducing a completely new feature or API it is a good idea to start a [RIP](https://github.com/apache/rocketmq/wiki/RocketMQ-Improvement-Proposal) and get consensus on the basic design first.
#### It is our job to follow up on patches in a timely fashion. Nag us if we aren't doing our job (sometimes we drop things).
## Becoming a Committer
@@ -19,9 +19,8 @@ We are always interested in adding new contributors. What we look for are series
Nowadays,we have several important contribution points:
#### Wiki & JavaDoc
-#### RocketMQ Console
#### RocketMQ SDK(C++\.Net\Php\Python\Go\Node.js)
-#### RocketMQ MySQL(Oracle\PostgreSQL\Redis\MongoDB\HBase\MSSQL) Replicator
+#### RocketMQ Connectors
##### Prerequisite
If you want to contribute the above listing points, you must abide our some prerequisites:
diff --git a/README.md b/README.md
index 98d97a00ffd2badb69c1f7130144c2e942fc08e2..1c17c7e242f044a513e7f399e175a13cf5a73721 100644
--- a/README.md
+++ b/README.md
@@ -51,3 +51,23 @@ We always welcome new contributions, whether for trivial cleanups, [big new feat
[Apache License, Version 2.0](http://www.apache.org/licenses/LICENSE-2.0.html) Copyright (C) Apache Software Foundation
+----------
+## Export Control Notice
+This distribution includes cryptographic software. The country in which you currently reside may have
+restrictions on the import, possession, use, and/or re-export to another country, of encryption software.
+BEFORE using any encryption software, please check your country's laws, regulations and policies concerning
+the import, possession, or use, and re-export of encryption software, to see if this is permitted. See
+ for more information.
+
+The U.S. Government Department of Commerce, Bureau of Industry and Security (BIS), has classified this
+software as Export Commodity Control Number (ECCN) 5D002.C.1, which includes information security software
+using or performing cryptographic functions with asymmetric algorithms. The form and manner of this Apache
+Software Foundation distribution makes it eligible for export under the License Exception ENC Technology
+Software Unrestricted (TSU) exception (see the BIS Export Administration Regulations, Section 740.13) for
+both object code and source code.
+
+The following provides more details on the included cryptographic software:
+
+This software uses Apache Commons Crypto (https://commons.apache.org/proper/commons-crypto/) to
+support authentication, and encryption and decryption of data sent across the network between
+services.
diff --git a/acl/pom.xml b/acl/pom.xml
index 923acfe6227a7c566917a801b1c74b99198e04fd..ec5ab0493fb588101213d8105a632f5db49bd0e6 100644
--- a/acl/pom.xml
+++ b/acl/pom.xml
@@ -13,7 +13,7 @@
org.apache.rocketmq
rocketmq-all
- 4.5.2-SNAPSHOT
+ 4.6.0-SNAPSHOT
rocketmq-acl
rocketmq-acl ${project.version}
@@ -67,6 +67,10 @@
logback-core
test
+
+ commons-validator
+ commons-validator
+
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 20e1cfa26b90916aecfec39e2669179c85854e20..8973320237c684c68864c29ff0c4a90d75bfdd3e 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,6 +23,7 @@ import java.io.FileNotFoundException;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
+import java.util.ArrayList;
import java.util.Map;
import java.util.SortedMap;
import org.apache.commons.lang3.StringUtils;
@@ -69,24 +70,75 @@ public class AclUtils {
return signature;
}
+ public static void IPv6AddressCheck(String netaddress) {
+ if (isAsterisk(netaddress) || isMinus(netaddress)) {
+ int asterisk = netaddress.indexOf("*");
+ int minus = netaddress.indexOf("-");
+// '*' must be the end of netaddress if it exists
+ if (asterisk > -1 && asterisk != netaddress.length() - 1) {
+ throw new AclException(String.format("Netaddress examine scope Exception netaddress is %s", netaddress));
+ }
+
+// format like "2::ac5:78:1-200:*" or "2::ac5:78:1-200" is legal
+ if (minus > -1) {
+ if (asterisk == -1) {
+ if (minus <= netaddress.lastIndexOf(":")) {
+ throw new AclException(String.format("Netaddress examine scope Exception netaddress is %s", netaddress));
+ }
+ } else {
+ if (minus <= netaddress.lastIndexOf(":", netaddress.lastIndexOf(":") - 1)) {
+ throw new AclException(String.format("Netaddress examine scope Exception netaddress is %s", netaddress));
+ }
+ }
+ }
+ }
+ }
+
+ public static String v6ipProcess(String netaddress, String[] strArray, int index) {
+ int part;
+ String subAddress;
+ boolean isAsterisk = isAsterisk(netaddress);
+ boolean isMinus = isMinus(netaddress);
+ if (isAsterisk && isMinus) {
+ part = 6;
+ int lastColon = netaddress.lastIndexOf(':');
+ int secondLastColon = netaddress.substring(0, lastColon).lastIndexOf(':');
+ subAddress = netaddress.substring(0, secondLastColon);
+ } else if (!isAsterisk && !isMinus) {
+ part = 8;
+ subAddress = netaddress;
+ } else {
+ part = 7;
+ subAddress = netaddress.substring(0, netaddress.lastIndexOf(':'));
+ }
+ return expandIP(subAddress, part);
+ }
+
public static void verify(String netaddress, int index) {
if (!AclUtils.isScope(netaddress, index)) {
throw new AclException(String.format("Netaddress examine scope Exception netaddress is %s", netaddress));
}
}
- public static String[] getAddreeStrArray(String netaddress, String four) {
- String[] fourStrArray = StringUtils.split(four.substring(1, four.length() - 1), ",");
+ public static String[] getAddreeStrArray(String netaddress, String partialAddress) {
+ String[] parAddStrArray = StringUtils.split(partialAddress.substring(1, partialAddress.length() - 1), ",");
String address = netaddress.substring(0, netaddress.indexOf("{"));
- String[] addreeStrArray = new String[fourStrArray.length];
- for (int i = 0; i < fourStrArray.length; i++) {
- addreeStrArray[i] = address + fourStrArray[i];
+ String[] addreeStrArray = new String[parAddStrArray.length];
+ for (int i = 0; i < parAddStrArray.length; i++) {
+ addreeStrArray[i] = address + parAddStrArray[i];
}
return addreeStrArray;
}
- public static boolean isScope(String num, int index) {
- String[] strArray = StringUtils.split(num, ".");
+ public static boolean isScope(String netaddress, int index) {
+// IPv6 Address
+ if (isColon(netaddress)) {
+ netaddress = expandIP(netaddress, 8);
+ String[] strArray = StringUtils.split(netaddress, ":");
+ return isIPv6Scope(strArray, index);
+ }
+
+ String[] strArray = StringUtils.split(netaddress, ".");
if (strArray.length != 4) {
return false;
}
@@ -107,6 +159,10 @@ public class AclUtils {
}
+ public static boolean isColon(String netaddress) {
+ return netaddress.indexOf(':') > -1;
+ }
+
public static boolean isScope(String num) {
return isScope(Integer.valueOf(num.trim()));
}
@@ -119,7 +175,7 @@ public class AclUtils {
return asterisk.indexOf('*') > -1;
}
- public static boolean isColon(String colon) {
+ public static boolean isComma(String colon) {
return colon.indexOf(',') > -1;
}
@@ -128,6 +184,88 @@ public class AclUtils {
}
+ public static boolean isIPv6Scope(String[] num, int index) {
+ for (int i = 0; i < index; i++) {
+ int value;
+ try {
+ value = Integer.parseInt(num[i], 16);
+ } catch (NumberFormatException e) {
+ return false;
+ }
+ if (!isIPv6Scope(value)) {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ public static boolean isIPv6Scope(int num) {
+ int min = Integer.parseInt("0", 16);
+ int max = Integer.parseInt("ffff", 16);
+ return num >= min && num <= max;
+ }
+
+ public static String expandIP(String netaddress, int part) {
+ boolean compress = false;
+ int compressIndex = -1;
+ String[] strArray = StringUtils.split(netaddress, ":");
+ ArrayList indexes = new ArrayList<>();
+ for (int i = 0; i < netaddress.length(); i++) {
+ if (netaddress.charAt(i) == ':') {
+ if (indexes.size() > 0 && i - indexes.get(indexes.size() - 1) == 1) {
+ compressIndex = i;
+ compress = true;
+ }
+ indexes.add(i);
+ }
+ }
+
+ for (int i = 0; i < strArray.length; i++) {
+ if (strArray[i].length() < 4) {
+ strArray[i] = "0000".substring(0, 4 - strArray[i].length()) + strArray[i];
+ }
+ }
+
+ StringBuilder sb = new StringBuilder();
+ if (compress) {
+ int pos = indexes.indexOf(compressIndex);
+ int index = 0;
+ if (!netaddress.startsWith(":")) {
+ for (int i = 0; i < pos; i++) {
+ sb.append(strArray[index]).append(":");
+ index += 1;
+ }
+ }
+ int zeroNum = part - strArray.length;
+ if (netaddress.endsWith(":")) {
+ for (int i = 0; i < zeroNum; i++) {
+ sb.append("0000");
+ if (i != zeroNum - 1) {
+ sb.append(":");
+ }
+ }
+ } else {
+ for (int i = 0; i < zeroNum; i++) {
+ sb.append("0000").append(":");
+ }
+ for (int i = index; i < strArray.length; i++) {
+ sb.append(strArray[i]);
+ if (i != strArray.length - 1) {
+ sb.append(":");
+ }
+ }
+ }
+ } else {
+ for (int i = 0; i < strArray.length; i++) {
+ sb.append(strArray[i]);
+ if (i != strArray.length - 1) {
+ sb.append(":");
+ }
+ }
+ }
+ return sb.toString().toUpperCase();
+ }
+
public static T getYamlDataObject(String path, Class clazz) {
Yaml yaml = new Yaml();
FileInputStream fis = null;
@@ -148,7 +286,7 @@ public class AclUtils {
}
}
- public static boolean writeDataObject(String path, Map dataMap) {
+ public static boolean writeDataObject(String path, Map dataMap) {
Yaml yaml = new Yaml();
PrintWriter pw = null;
try {
@@ -172,15 +310,15 @@ public class AclUtils {
yamlDataObject = AclUtils.getYamlDataObject(fileName,
JSONObject.class);
} catch (Exception e) {
- log.error("Convert yaml file to data object error, ",e);
+ log.error("Convert yaml file to data object error, ", e);
return null;
}
if (yamlDataObject == null || yamlDataObject.isEmpty()) {
- log.warn("Cannot find conf file :{}, acl isn't be enabled." ,fileName);
+ log.warn("Cannot find conf file :{}, acl isn't be enabled.", fileName);
return null;
}
-
+
String accessKey = yamlDataObject.getString(AclConstants.CONFIG_ACCESS_KEY);
String secretKey = yamlDataObject.getString(AclConstants.CONFIG_SECRET_KEY);
@@ -189,7 +327,7 @@ public class AclUtils {
return null;
}
- return new AclClientRPCHook(new SessionCredentials(accessKey,secretKey));
+ return new AclClientRPCHook(new SessionCredentials(accessKey, secretKey));
}
}
diff --git a/acl/src/main/java/org/apache/rocketmq/acl/plain/PlainAccessValidator.java b/acl/src/main/java/org/apache/rocketmq/acl/plain/PlainAccessValidator.java
index c8ce23908484c1f56c9576c6ee97c7b907227539..0d7ddb3053b5b3a408eec2d5893cbd112b4214ae 100644
--- a/acl/src/main/java/org/apache/rocketmq/acl/plain/PlainAccessValidator.java
+++ b/acl/src/main/java/org/apache/rocketmq/acl/plain/PlainAccessValidator.java
@@ -50,7 +50,7 @@ public class PlainAccessValidator implements AccessValidator {
public AccessResource parse(RemotingCommand request, String remoteAddr) {
PlainAccessResource accessResource = new PlainAccessResource();
if (remoteAddr != null && remoteAddr.contains(":")) {
- accessResource.setWhiteRemoteAddress(remoteAddr.split(":")[0]);
+ accessResource.setWhiteRemoteAddress(remoteAddr.substring(0, remoteAddr.lastIndexOf(':')));
} else {
accessResource.setWhiteRemoteAddress(remoteAddr);
}
diff --git a/acl/src/main/java/org/apache/rocketmq/acl/plain/RemoteAddressStrategyFactory.java b/acl/src/main/java/org/apache/rocketmq/acl/plain/RemoteAddressStrategyFactory.java
index cc2dcee77f9b71d5a516b2eb68a10b2744d6364e..6931eb7c426aa3511769f5e9fa8a4abc6c260bb3 100644
--- a/acl/src/main/java/org/apache/rocketmq/acl/plain/RemoteAddressStrategyFactory.java
+++ b/acl/src/main/java/org/apache/rocketmq/acl/plain/RemoteAddressStrategyFactory.java
@@ -19,6 +19,7 @@ package org.apache.rocketmq.acl.plain;
import java.util.HashSet;
import java.util.Set;
import org.apache.commons.lang3.StringUtils;
+import org.apache.commons.validator.routines.InetAddressValidator;
import org.apache.rocketmq.acl.common.AclException;
import org.apache.rocketmq.acl.common.AclUtils;
import org.apache.rocketmq.common.constant.LoggerName;
@@ -41,17 +42,26 @@ public class RemoteAddressStrategyFactory {
if (StringUtils.isBlank(remoteAddr)) {
return BLANK_NET_ADDRESS_STRATEGY;
}
- if ("*".equals(remoteAddr) || "*.*.*.*".equals(remoteAddr)) {
+ if ("*".equals(remoteAddr) || "*.*.*.*".equals(remoteAddr) || "*:*:*:*:*:*:*:*".equals(remoteAddr)) {
return NULL_NET_ADDRESS_STRATEGY;
}
if (remoteAddr.endsWith("}")) {
- String[] strArray = StringUtils.split(remoteAddr, ".");
- String four = strArray[3];
- if (!four.startsWith("{")) {
- throw new AclException(String.format("MultipleRemoteAddressStrategy netaddress examine scope Exception netaddress", remoteAddr));
+ if (AclUtils.isColon(remoteAddr)) {
+ String[] strArray = StringUtils.split(remoteAddr, ":");
+ String last = strArray[strArray.length - 1];
+ if (!last.startsWith("{")) {
+ throw new AclException(String.format("MultipleRemoteAddressStrategy netaddress examine scope Exception netaddress", remoteAddr));
+ }
+ return new MultipleRemoteAddressStrategy(AclUtils.getAddreeStrArray(remoteAddr, last));
+ } else {
+ String[] strArray = StringUtils.split(remoteAddr, ".");
+ String four = strArray[3];
+ if (!four.startsWith("{")) {
+ throw new AclException(String.format("MultipleRemoteAddressStrategy netaddress examine scope Exception netaddress", remoteAddr));
+ }
+ return new MultipleRemoteAddressStrategy(AclUtils.getAddreeStrArray(remoteAddr, four));
}
- return new MultipleRemoteAddressStrategy(AclUtils.getAddreeStrArray(remoteAddr, four));
- } else if (AclUtils.isColon(remoteAddr)) {
+ } else if (AclUtils.isComma(remoteAddr)) {
return new MultipleRemoteAddressStrategy(StringUtils.split(remoteAddr, ","));
} else if (AclUtils.isAsterisk(remoteAddr) || AclUtils.isMinus(remoteAddr)) {
return new RangeRemoteAddressStrategy(remoteAddr);
@@ -81,15 +91,26 @@ public class RemoteAddressStrategyFactory {
private final Set multipleSet = new HashSet<>();
public MultipleRemoteAddressStrategy(String[] strArray) {
+ InetAddressValidator validator = InetAddressValidator.getInstance();
for (String netaddress : strArray) {
- AclUtils.verify(netaddress, 4);
- multipleSet.add(netaddress);
+ if (validator.isValidInet4Address(netaddress)) {
+ multipleSet.add(netaddress);
+ } else if (validator.isValidInet6Address(netaddress)) {
+ multipleSet.add(AclUtils.expandIP(netaddress, 8));
+ } else {
+ throw new AclException(String.format("Netaddress examine Exception netaddress is %s", netaddress));
+ }
}
}
@Override
public boolean match(PlainAccessResource plainAccessResource) {
- return multipleSet.contains(plainAccessResource.getWhiteRemoteAddress());
+ InetAddressValidator validator = InetAddressValidator.getInstance();
+ String whiteRemoteAddress = plainAccessResource.getWhiteRemoteAddress();
+ if (validator.isValidInet6Address(whiteRemoteAddress)) {
+ whiteRemoteAddress = AclUtils.expandIP(whiteRemoteAddress, 8);
+ }
+ return multipleSet.contains(whiteRemoteAddress);
}
}
@@ -100,12 +121,16 @@ public class RemoteAddressStrategyFactory {
public OneRemoteAddressStrategy(String netaddress) {
this.netaddress = netaddress;
- AclUtils.verify(netaddress, 4);
+ InetAddressValidator validator = InetAddressValidator.getInstance();
+ if (!(validator.isValidInet4Address(netaddress) || validator.isValidInet6Address(netaddress))) {
+ throw new AclException(String.format("Netaddress examine Exception netaddress is %s", netaddress));
+ }
}
@Override
public boolean match(PlainAccessResource plainAccessResource) {
- return netaddress.equals(plainAccessResource.getWhiteRemoteAddress());
+ String writeRemoteAddress = AclUtils.expandIP(plainAccessResource.getWhiteRemoteAddress(), 8).toUpperCase();
+ return AclUtils.expandIP(netaddress, 8).toUpperCase().equals(writeRemoteAddress);
}
}
@@ -121,14 +146,29 @@ public class RemoteAddressStrategyFactory {
private int index;
public RangeRemoteAddressStrategy(String remoteAddr) {
- String[] strArray = StringUtils.split(remoteAddr, ".");
- if (analysis(strArray, 1) || analysis(strArray, 2) || analysis(strArray, 3)) {
- AclUtils.verify(remoteAddr, index - 1);
- StringBuffer sb = new StringBuffer().append(strArray[0].trim()).append(".").append(strArray[1].trim()).append(".");
- if (index == 3) {
- sb.append(strArray[2].trim()).append(".");
+// IPv6 Address
+ if (AclUtils.isColon(remoteAddr)) {
+ AclUtils.IPv6AddressCheck(remoteAddr);
+ String[] strArray = StringUtils.split(remoteAddr, ":");
+ for (int i = 1; i < strArray.length; i++) {
+ if (ipv6Analysis(strArray, i)) {
+ AclUtils.verify(remoteAddr, index - 1);
+ String preAddress = AclUtils.v6ipProcess(remoteAddr, strArray, index);
+ this.index = StringUtils.split(preAddress, ":").length;
+ this.head = preAddress;
+ break;
+ }
+ }
+ } else {
+ String[] strArray = StringUtils.split(remoteAddr, ".");
+ if (analysis(strArray, 1) || analysis(strArray, 2) || analysis(strArray, 3)) {
+ AclUtils.verify(remoteAddr, index - 1);
+ StringBuffer sb = new StringBuffer();
+ for (int j = 0; j < index; j++) {
+ sb.append(strArray[j].trim()).append(".");
+ }
+ this.head = sb.toString();
}
- this.head = sb.toString();
}
}
@@ -152,6 +192,27 @@ public class RemoteAddressStrategyFactory {
return this.end > 0 ? true : false;
}
+ private boolean ipv6Analysis(String[] strArray, int index) {
+ String value = strArray[index].trim();
+ this.index = index;
+ if ("*".equals(value)) {
+ int min = Integer.parseInt("0", 16);
+ int max = Integer.parseInt("ffff", 16);
+ setValue(min, max);
+ } else if (AclUtils.isMinus(value)) {
+ if (value.indexOf("-") == 0) {
+ throw new AclException(String.format("RangeRemoteAddressStrategy netaddress examine scope Exception value %s ", value));
+ }
+ String[] valueArray = StringUtils.split(value, "-");
+ this.start = Integer.parseInt(valueArray[0], 16);
+ this.end = Integer.parseInt(valueArray[1], 16);
+ if (!(AclUtils.isIPv6Scope(end) && AclUtils.isIPv6Scope(start) && start <= end)) {
+ throw new AclException(String.format("RangeRemoteAddressStrategy netaddress examine scope Exception start is %s , end is %s", start, end));
+ }
+ }
+ return this.end > 0 ? true : false;
+ }
+
private void setValue(int start, int end) {
this.start = start;
this.end = end;
@@ -160,21 +221,33 @@ public class RemoteAddressStrategyFactory {
@Override
public boolean match(PlainAccessResource plainAccessResource) {
String netAddress = plainAccessResource.getWhiteRemoteAddress();
- if (netAddress.startsWith(this.head)) {
- String value;
- if (index == 3) {
- value = netAddress.substring(this.head.length());
- } else {
- value = netAddress.substring(this.head.length(), netAddress.lastIndexOf('.'));
+ InetAddressValidator validator = InetAddressValidator.getInstance();
+ if (validator.isValidInet4Address(netAddress)) {
+ if (netAddress.startsWith(this.head)) {
+ String value;
+ if (index == 3) {
+ value = netAddress.substring(this.head.length());
+ } else if (index == 2) {
+ value = netAddress.substring(this.head.length(), netAddress.lastIndexOf('.'));
+ } else {
+ value = netAddress.substring(this.head.length(), netAddress.lastIndexOf('.', netAddress.lastIndexOf('.') - 1));
+ }
+ Integer address = Integer.valueOf(value);
+ if (address >= this.start && address <= this.end) {
+ return true;
+ }
}
- Integer address = Integer.valueOf(value);
- if (address >= this.start && address <= this.end) {
- return true;
+ } else if (validator.isValidInet6Address(netAddress)) {
+ netAddress = AclUtils.expandIP(netAddress, 8).toUpperCase();
+ if (netAddress.startsWith(this.head)) {
+ String value = netAddress.substring(5 * index, 5 * index + 4);
+ Integer address = Integer.parseInt(value, 16);
+ if (address >= this.start && address <= this.end) {
+ return true;
+ }
}
}
return false;
}
-
}
-
}
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 5b2627de85dc66f13f1868b7b0c5e014aba3117f..5705b745a0e7472ca7a215468ae20775a53babfb 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
@@ -46,20 +46,35 @@ public class AclUtilsTest {
addressList.add("1.1.1.3");
addressList.add("1.1.1.4");
Assert.assertEquals(newAddressList, addressList);
+
+// IPv6 test
+ String ipv6Address = "1:ac41:9987::bb22:666:{1,2,3,4}";
+ String[] ipv6AddressArray = AclUtils.getAddreeStrArray(ipv6Address, "{1,2,3,4}");
+ List newIPv6AddressList = new ArrayList<>();
+ for (String a : ipv6AddressArray) {
+ newIPv6AddressList.add(a);
+ }
+
+ List ipv6AddressList = new ArrayList<>();
+ ipv6AddressList.add("1:ac41:9987::bb22:666:1");
+ ipv6AddressList.add("1:ac41:9987::bb22:666:2");
+ ipv6AddressList.add("1:ac41:9987::bb22:666:3");
+ ipv6AddressList.add("1:ac41:9987::bb22:666:4");
+ Assert.assertEquals(newIPv6AddressList, ipv6AddressList);
}
@Test
public void isScopeStringArray() {
- String adderss = "12";
+ String address = "12";
for (int i = 0; i < 6; i++) {
- boolean isScope = AclUtils.isScope(adderss, 4);
+ boolean isScope = AclUtils.isScope(address, 4);
if (i == 3) {
Assert.assertTrue(isScope);
} else {
Assert.assertFalse(isScope);
}
- adderss = adderss + ".12";
+ address = address + ".12";
}
}
@@ -77,6 +92,25 @@ public class AclUtilsTest {
isScope = AclUtils.isScope(adderss, 3);
Assert.assertFalse(isScope);
+// IPv6 test
+ adderss = StringUtils.split("1050:0000:0000:0000:0005:0600:300c:326b", ":");
+ isScope = AclUtils.isIPv6Scope(adderss, 8);
+ Assert.assertTrue(isScope);
+ isScope = AclUtils.isIPv6Scope(adderss, 4);
+ Assert.assertTrue(isScope);
+
+ adderss = StringUtils.split("1050:9876:0000:0000:0005:akkg:300c:326b", ":");
+ isScope = AclUtils.isIPv6Scope(adderss, 8);
+ Assert.assertFalse(isScope);
+ isScope = AclUtils.isIPv6Scope(adderss, 4);
+ Assert.assertTrue(isScope);
+
+ adderss = StringUtils.split(AclUtils.expandIP("1050::0005:akkg:300c:326b", 8), ":");
+ isScope = AclUtils.isIPv6Scope(adderss, 8);
+ Assert.assertFalse(isScope);
+ isScope = AclUtils.isIPv6Scope(adderss, 4);
+ Assert.assertTrue(isScope);
+
}
@Test
@@ -102,6 +136,18 @@ public class AclUtilsTest {
isScope = AclUtils.isScope(256);
Assert.assertFalse(isScope);
+ // IPv6 test
+ int min = Integer.parseInt("0", 16);
+ int max = Integer.parseInt("ffff", 16);
+ for (int i = min; i < max + 1; i++) {
+ isScope = AclUtils.isIPv6Scope(i);
+ Assert.assertTrue(isScope);
+ }
+ isScope = AclUtils.isIPv6Scope(-1);
+ Assert.assertFalse(isScope);
+ isScope = AclUtils.isIPv6Scope(max + 1);
+ Assert.assertFalse(isScope);
+
}
@Test
@@ -115,10 +161,10 @@ public class AclUtilsTest {
@Test
public void isColonTest() {
- boolean isColon = AclUtils.isColon(",");
+ boolean isColon = AclUtils.isComma(",");
Assert.assertTrue(isColon);
- isColon = AclUtils.isColon("-");
+ isColon = AclUtils.isComma("-");
Assert.assertFalse(isColon);
}
@@ -131,6 +177,36 @@ public class AclUtilsTest {
Assert.assertFalse(isMinus);
}
+ @Test
+ public void v6ipProcessTest() {
+ String remoteAddr = "5::7:6:1-200:*";
+ String[] strArray = StringUtils.split(remoteAddr, ":");
+ Assert.assertEquals(AclUtils.v6ipProcess(remoteAddr, strArray, 3), "0005:0000:0000:0000:0007:0006");
+
+ remoteAddr = "5::7:6:1-200";
+ strArray = StringUtils.split(remoteAddr, ":");
+ Assert.assertEquals(AclUtils.v6ipProcess(remoteAddr, strArray, 3), "0005:0000:0000:0000:0000:0007:0006");
+
+ remoteAddr = "5::7:6:*";
+ strArray = StringUtils.split(remoteAddr, ":");
+ Assert.assertEquals(AclUtils.v6ipProcess(remoteAddr, strArray, 3), "0005:0000:0000:0000:0000:0007:0006");
+
+ remoteAddr = "5:7:6:*";
+ strArray = StringUtils.split(remoteAddr, ":");
+ Assert.assertEquals(AclUtils.v6ipProcess(remoteAddr, strArray, 3), "0005:0007:0006");
+ }
+
+ @Test
+ public void expandIPTest() {
+ Assert.assertEquals(AclUtils.expandIP("::1", 8), "0000:0000:0000:0000:0000:0000:0000:0001");
+ Assert.assertEquals(AclUtils.expandIP("3::", 8), "0003:0000:0000:0000:0000:0000:0000:0000");
+ Assert.assertEquals(AclUtils.expandIP("2::2", 8), "0002:0000:0000:0000:0000:0000:0000:0002");
+ Assert.assertEquals(AclUtils.expandIP("4::aac4:92", 8), "0004:0000:0000:0000:0000:0000:AAC4:0092");
+ Assert.assertEquals(AclUtils.expandIP("ab23:56:901a::cc6:765:bb:9011", 8), "AB23:0056:901A:0000:0CC6:0765:00BB:9011");
+ Assert.assertEquals(AclUtils.expandIP("ab23:56:901a:1:cc6:765:bb:9011", 8), "AB23:0056:901A:0001:0CC6:0765:00BB:9011");
+ Assert.assertEquals(AclUtils.expandIP("5::7:6", 6), "0005:0000:0000:0000:0007:0006");
+ }
+
@SuppressWarnings("unchecked")
@Test
public void getYamlDataObjectTest() {
@@ -140,7 +216,7 @@ public class AclUtilsTest {
}
@Test
- public void writeDataObject2YamlFileTest() throws IOException{
+ public void writeDataObject2YamlFileTest() throws IOException {
String targetFileName = "src/test/resources/conf/plain_write_acl.yml";
File transport = new File(targetFileName);
@@ -153,7 +229,7 @@ public class AclUtilsTest {
List globalWhiteRemoteAddrs = new ArrayList();
globalWhiteRemoteAddrs.add("10.10.103.*");
globalWhiteRemoteAddrs.add("192.168.0.*");
- aclYamlMap.put("globalWhiteRemoteAddrs",globalWhiteRemoteAddrs);
+ aclYamlMap.put("globalWhiteRemoteAddrs", globalWhiteRemoteAddrs);
// For accounts element in acl yaml config file
List