From 2a046ccbf915bcf6e3708e03b160a136596d85a4 Mon Sep 17 00:00:00 2001
From: JZH <576811031@QQ.COM>
Date: Wed, 15 Jul 2020 15:43:58 +0800
Subject: [PATCH 1/6] Solve the problem of prefix and suffix matching
---
.../zuul/api/route/PrefixRoutePathMatcher.java | 12 ++++++++++--
.../zuul/api/route/RegexRoutePathMatcher.java | 15 +++++++++++----
2 files changed, 21 insertions(+), 6 deletions(-)
diff --git a/sentinel-adapter/sentinel-zuul-adapter/src/main/java/com/alibaba/csp/sentinel/adapter/gateway/zuul/api/route/PrefixRoutePathMatcher.java b/sentinel-adapter/sentinel-zuul-adapter/src/main/java/com/alibaba/csp/sentinel/adapter/gateway/zuul/api/route/PrefixRoutePathMatcher.java
index 21e636e589..1bcac236cf 100644
--- a/sentinel-adapter/sentinel-zuul-adapter/src/main/java/com/alibaba/csp/sentinel/adapter/gateway/zuul/api/route/PrefixRoutePathMatcher.java
+++ b/sentinel-adapter/sentinel-zuul-adapter/src/main/java/com/alibaba/csp/sentinel/adapter/gateway/zuul/api/route/PrefixRoutePathMatcher.java
@@ -17,11 +17,13 @@
import com.alibaba.csp.sentinel.util.AssertUtil;
import com.alibaba.csp.sentinel.util.function.Predicate;
-
import com.netflix.zuul.context.RequestContext;
+import org.apache.commons.lang.StringUtils;
import org.springframework.util.AntPathMatcher;
import org.springframework.util.PathMatcher;
+import javax.servlet.http.HttpServletRequest;
+
/**
* @author Eric Zhao
* @since 1.6.0
@@ -42,7 +44,13 @@ public PrefixRoutePathMatcher(String pattern) {
@Override
public boolean test(RequestContext context) {
- String path = context.getRequest().getServletPath();
+ //Solve the problem of prefix and suffix matching
+ HttpServletRequest request = context.getRequest();
+ String path = request.getServletPath();
+ String pathInfo = request.getPathInfo();
+ if (StringUtils.length(pathInfo) > 0) {
+ path = path + pathInfo;
+ }
if (canMatch) {
return pathMatcher.match(pattern, path);
}
diff --git a/sentinel-adapter/sentinel-zuul-adapter/src/main/java/com/alibaba/csp/sentinel/adapter/gateway/zuul/api/route/RegexRoutePathMatcher.java b/sentinel-adapter/sentinel-zuul-adapter/src/main/java/com/alibaba/csp/sentinel/adapter/gateway/zuul/api/route/RegexRoutePathMatcher.java
index daf1310ec3..0b2bcf4168 100644
--- a/sentinel-adapter/sentinel-zuul-adapter/src/main/java/com/alibaba/csp/sentinel/adapter/gateway/zuul/api/route/RegexRoutePathMatcher.java
+++ b/sentinel-adapter/sentinel-zuul-adapter/src/main/java/com/alibaba/csp/sentinel/adapter/gateway/zuul/api/route/RegexRoutePathMatcher.java
@@ -15,12 +15,13 @@
*/
package com.alibaba.csp.sentinel.adapter.gateway.zuul.api.route;
-import java.util.regex.Pattern;
-
import com.alibaba.csp.sentinel.util.AssertUtil;
import com.alibaba.csp.sentinel.util.function.Predicate;
-
import com.netflix.zuul.context.RequestContext;
+import org.apache.commons.lang.StringUtils;
+
+import javax.servlet.http.HttpServletRequest;
+import java.util.regex.Pattern;
/**
* @author Eric Zhao
@@ -39,7 +40,13 @@ public RegexRoutePathMatcher(String pattern) {
@Override
public boolean test(RequestContext context) {
- String path = context.getRequest().getServletPath();
+ //Solve the problem of prefix and suffix matching
+ HttpServletRequest request = context.getRequest();
+ String path = request.getServletPath();
+ String pathInfo = request.getPathInfo();
+ if (StringUtils.length(pathInfo) > 0) {
+ path = path + pathInfo;
+ }
return regex.matcher(path).matches();
}
From 89671f0f1fa1c8735fccdc1bbed580d93e2a7b36 Mon Sep 17 00:00:00 2001
From: JZH <576811031@QQ.COM>
Date: Mon, 20 Jul 2020 10:10:16 +0800
Subject: [PATCH 2/6] Use Apache Common StringUtils isBlank to improve the
robustness of judgment
---
.../adapter/gateway/zuul/api/route/PrefixRoutePathMatcher.java | 2 +-
.../adapter/gateway/zuul/api/route/RegexRoutePathMatcher.java | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/sentinel-adapter/sentinel-zuul-adapter/src/main/java/com/alibaba/csp/sentinel/adapter/gateway/zuul/api/route/PrefixRoutePathMatcher.java b/sentinel-adapter/sentinel-zuul-adapter/src/main/java/com/alibaba/csp/sentinel/adapter/gateway/zuul/api/route/PrefixRoutePathMatcher.java
index 1bcac236cf..566c17a8b6 100644
--- a/sentinel-adapter/sentinel-zuul-adapter/src/main/java/com/alibaba/csp/sentinel/adapter/gateway/zuul/api/route/PrefixRoutePathMatcher.java
+++ b/sentinel-adapter/sentinel-zuul-adapter/src/main/java/com/alibaba/csp/sentinel/adapter/gateway/zuul/api/route/PrefixRoutePathMatcher.java
@@ -48,7 +48,7 @@ public boolean test(RequestContext context) {
HttpServletRequest request = context.getRequest();
String path = request.getServletPath();
String pathInfo = request.getPathInfo();
- if (StringUtils.length(pathInfo) > 0) {
+ if (StringUtils.isNotBlank(pathInfo)) {
path = path + pathInfo;
}
if (canMatch) {
diff --git a/sentinel-adapter/sentinel-zuul-adapter/src/main/java/com/alibaba/csp/sentinel/adapter/gateway/zuul/api/route/RegexRoutePathMatcher.java b/sentinel-adapter/sentinel-zuul-adapter/src/main/java/com/alibaba/csp/sentinel/adapter/gateway/zuul/api/route/RegexRoutePathMatcher.java
index 0b2bcf4168..cf8939231e 100644
--- a/sentinel-adapter/sentinel-zuul-adapter/src/main/java/com/alibaba/csp/sentinel/adapter/gateway/zuul/api/route/RegexRoutePathMatcher.java
+++ b/sentinel-adapter/sentinel-zuul-adapter/src/main/java/com/alibaba/csp/sentinel/adapter/gateway/zuul/api/route/RegexRoutePathMatcher.java
@@ -44,7 +44,7 @@ public boolean test(RequestContext context) {
HttpServletRequest request = context.getRequest();
String path = request.getServletPath();
String pathInfo = request.getPathInfo();
- if (StringUtils.length(pathInfo) > 0) {
+ if (StringUtils.isNotBlank(pathInfo)) {
path = path + pathInfo;
}
return regex.matcher(path).matches();
From 7b438232ff622db42c1b52de08a0c82bed5f5094 Mon Sep 17 00:00:00 2001
From: JZH <576811031@QQ.COM>
Date: Fri, 24 Jul 2020 15:27:41 +0800
Subject: [PATCH 3/6] =?UTF-8?q?using=20the=20embedded=20com.alibaba.csp.se?=
=?UTF-8?q?ntinel.util.StringUtil=EF=BC=8CAdd=20test=20cases?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../api/route/PrefixRoutePathMatcher.java | 10 ++--
.../zuul/api/route/RegexRoutePathMatcher.java | 10 ++--
.../zuul/route/SentinelZuulRouteTest.java | 52 +++++++++++++++++++
3 files changed, 66 insertions(+), 6 deletions(-)
create mode 100644 sentinel-adapter/sentinel-zuul-adapter/src/test/java/com/alibaba/csp/sentinel/adapter/gateway/zuul/route/SentinelZuulRouteTest.java
diff --git a/sentinel-adapter/sentinel-zuul-adapter/src/main/java/com/alibaba/csp/sentinel/adapter/gateway/zuul/api/route/PrefixRoutePathMatcher.java b/sentinel-adapter/sentinel-zuul-adapter/src/main/java/com/alibaba/csp/sentinel/adapter/gateway/zuul/api/route/PrefixRoutePathMatcher.java
index 566c17a8b6..fc4f9fce7d 100644
--- a/sentinel-adapter/sentinel-zuul-adapter/src/main/java/com/alibaba/csp/sentinel/adapter/gateway/zuul/api/route/PrefixRoutePathMatcher.java
+++ b/sentinel-adapter/sentinel-zuul-adapter/src/main/java/com/alibaba/csp/sentinel/adapter/gateway/zuul/api/route/PrefixRoutePathMatcher.java
@@ -16,9 +16,9 @@
package com.alibaba.csp.sentinel.adapter.gateway.zuul.api.route;
import com.alibaba.csp.sentinel.util.AssertUtil;
+import com.alibaba.csp.sentinel.util.StringUtil;
import com.alibaba.csp.sentinel.util.function.Predicate;
import com.netflix.zuul.context.RequestContext;
-import org.apache.commons.lang.StringUtils;
import org.springframework.util.AntPathMatcher;
import org.springframework.util.PathMatcher;
@@ -48,8 +48,12 @@ public boolean test(RequestContext context) {
HttpServletRequest request = context.getRequest();
String path = request.getServletPath();
String pathInfo = request.getPathInfo();
- if (StringUtils.isNotBlank(pathInfo)) {
- path = path + pathInfo;
+ if (StringUtil.isNotBlank(pathInfo)) {
+ if (StringUtil.isBlank(path)) {
+ path = pathInfo;
+ } else {
+ path = path + pathInfo;
+ }
}
if (canMatch) {
return pathMatcher.match(pattern, path);
diff --git a/sentinel-adapter/sentinel-zuul-adapter/src/main/java/com/alibaba/csp/sentinel/adapter/gateway/zuul/api/route/RegexRoutePathMatcher.java b/sentinel-adapter/sentinel-zuul-adapter/src/main/java/com/alibaba/csp/sentinel/adapter/gateway/zuul/api/route/RegexRoutePathMatcher.java
index cf8939231e..4011c2c624 100644
--- a/sentinel-adapter/sentinel-zuul-adapter/src/main/java/com/alibaba/csp/sentinel/adapter/gateway/zuul/api/route/RegexRoutePathMatcher.java
+++ b/sentinel-adapter/sentinel-zuul-adapter/src/main/java/com/alibaba/csp/sentinel/adapter/gateway/zuul/api/route/RegexRoutePathMatcher.java
@@ -18,7 +18,7 @@
import com.alibaba.csp.sentinel.util.AssertUtil;
import com.alibaba.csp.sentinel.util.function.Predicate;
import com.netflix.zuul.context.RequestContext;
-import org.apache.commons.lang.StringUtils;
+import com.alibaba.csp.sentinel.util.StringUtil;
import javax.servlet.http.HttpServletRequest;
import java.util.regex.Pattern;
@@ -44,8 +44,12 @@ public boolean test(RequestContext context) {
HttpServletRequest request = context.getRequest();
String path = request.getServletPath();
String pathInfo = request.getPathInfo();
- if (StringUtils.isNotBlank(pathInfo)) {
- path = path + pathInfo;
+ if (StringUtil.isNotBlank(pathInfo)) {
+ if (StringUtil.isBlank(path)) {
+ path = pathInfo;
+ } else {
+ path = path + pathInfo;
+ }
}
return regex.matcher(path).matches();
}
diff --git a/sentinel-adapter/sentinel-zuul-adapter/src/test/java/com/alibaba/csp/sentinel/adapter/gateway/zuul/route/SentinelZuulRouteTest.java b/sentinel-adapter/sentinel-zuul-adapter/src/test/java/com/alibaba/csp/sentinel/adapter/gateway/zuul/route/SentinelZuulRouteTest.java
new file mode 100644
index 0000000000..49b1a8c581
--- /dev/null
+++ b/sentinel-adapter/sentinel-zuul-adapter/src/test/java/com/alibaba/csp/sentinel/adapter/gateway/zuul/route/SentinelZuulRouteTest.java
@@ -0,0 +1,52 @@
+package com.alibaba.csp.sentinel.adapter.gateway.zuul.route;
+
+import com.alibaba.csp.sentinel.adapter.gateway.zuul.api.route.PrefixRoutePathMatcher;
+import com.alibaba.csp.sentinel.adapter.gateway.zuul.api.route.RegexRoutePathMatcher;
+import com.netflix.zuul.context.RequestContext;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+
+import javax.servlet.http.HttpServletRequest;
+
+import static com.alibaba.csp.sentinel.adapter.gateway.zuul.constants.ZuulConstant.SERVICE_ID_KEY;
+import static org.mockito.Mockito.when;
+
+/**
+ * @author: jiangzian
+ **/
+public class SentinelZuulRouteTest {
+
+ private final String SERVICE_ID = "servicea";
+
+ private final String URI = "/servicea/test";
+
+ @Mock
+ private HttpServletRequest httpServletRequest;
+
+ private RequestContext requestContext = new RequestContext();
+
+ @Before
+ public void setUp() {
+ MockitoAnnotations.initMocks(this);
+ when(httpServletRequest.getContextPath()).thenReturn("");
+ when(httpServletRequest.getPathInfo()).thenReturn(URI);
+ requestContext.set(SERVICE_ID_KEY, SERVICE_ID);
+ requestContext.setRequest(httpServletRequest);
+ RequestContext.testSetCurrentContext(requestContext);
+ }
+
+ @Test
+ public void testPrefixRoutePathMatche() {
+ PrefixRoutePathMatcher prefixRoutePathMatcher = new PrefixRoutePathMatcher("/**");
+ Assert.assertTrue(prefixRoutePathMatcher.test(requestContext));
+ }
+
+ @Test
+ public void testRegexRoutePathMatcher() {
+ RegexRoutePathMatcher prefixRoutePathMatcher = new RegexRoutePathMatcher(URI);
+ Assert.assertTrue(prefixRoutePathMatcher.test(requestContext));
+ }
+}
From 12d4240bd6619296b99750a8b01b9ecdcfbc24c2 Mon Sep 17 00:00:00 2001
From: JZH <576811031@QQ.COM>
Date: Fri, 24 Jul 2020 17:29:30 +0800
Subject: [PATCH 4/6] reformat code
---
.../adapter/gateway/zuul/api/route/RegexRoutePathMatcher.java | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/sentinel-adapter/sentinel-zuul-adapter/src/main/java/com/alibaba/csp/sentinel/adapter/gateway/zuul/api/route/RegexRoutePathMatcher.java b/sentinel-adapter/sentinel-zuul-adapter/src/main/java/com/alibaba/csp/sentinel/adapter/gateway/zuul/api/route/RegexRoutePathMatcher.java
index 4011c2c624..03494d5d5e 100644
--- a/sentinel-adapter/sentinel-zuul-adapter/src/main/java/com/alibaba/csp/sentinel/adapter/gateway/zuul/api/route/RegexRoutePathMatcher.java
+++ b/sentinel-adapter/sentinel-zuul-adapter/src/main/java/com/alibaba/csp/sentinel/adapter/gateway/zuul/api/route/RegexRoutePathMatcher.java
@@ -16,9 +16,9 @@
package com.alibaba.csp.sentinel.adapter.gateway.zuul.api.route;
import com.alibaba.csp.sentinel.util.AssertUtil;
+import com.alibaba.csp.sentinel.util.StringUtil;
import com.alibaba.csp.sentinel.util.function.Predicate;
import com.netflix.zuul.context.RequestContext;
-import com.alibaba.csp.sentinel.util.StringUtil;
import javax.servlet.http.HttpServletRequest;
import java.util.regex.Pattern;
From 9594562398aca6adaa063fb7badf04c58ee54be2 Mon Sep 17 00:00:00 2001
From: JZH <576811031@QQ.COM>
Date: Mon, 31 Aug 2020 18:14:41 +0800
Subject: [PATCH 5/6] Change the mock method to MockHttpServletRequest, and
change the URL fetching method
---
.../sentinel-zuul-adapter/pom.xml | 6 ++++
.../api/route/PrefixRoutePathMatcher.java | 14 +++-----
.../zuul/api/route/RegexRoutePathMatcher.java | 14 +++-----
.../zuul/route/SentinelZuulRouteTest.java | 34 +++++++++----------
4 files changed, 31 insertions(+), 37 deletions(-)
diff --git a/sentinel-adapter/sentinel-zuul-adapter/pom.xml b/sentinel-adapter/sentinel-zuul-adapter/pom.xml
index e87b401b8f..4cf3a0bb48 100755
--- a/sentinel-adapter/sentinel-zuul-adapter/pom.xml
+++ b/sentinel-adapter/sentinel-zuul-adapter/pom.xml
@@ -69,6 +69,12 @@
mockito-core
test
+
+ org.springframework
+ spring-test
+ 4.3.20.RELEASE
+ test
+
\ No newline at end of file
diff --git a/sentinel-adapter/sentinel-zuul-adapter/src/main/java/com/alibaba/csp/sentinel/adapter/gateway/zuul/api/route/PrefixRoutePathMatcher.java b/sentinel-adapter/sentinel-zuul-adapter/src/main/java/com/alibaba/csp/sentinel/adapter/gateway/zuul/api/route/PrefixRoutePathMatcher.java
index fc4f9fce7d..b592a9cf03 100644
--- a/sentinel-adapter/sentinel-zuul-adapter/src/main/java/com/alibaba/csp/sentinel/adapter/gateway/zuul/api/route/PrefixRoutePathMatcher.java
+++ b/sentinel-adapter/sentinel-zuul-adapter/src/main/java/com/alibaba/csp/sentinel/adapter/gateway/zuul/api/route/PrefixRoutePathMatcher.java
@@ -16,7 +16,6 @@
package com.alibaba.csp.sentinel.adapter.gateway.zuul.api.route;
import com.alibaba.csp.sentinel.util.AssertUtil;
-import com.alibaba.csp.sentinel.util.StringUtil;
import com.alibaba.csp.sentinel.util.function.Predicate;
import com.netflix.zuul.context.RequestContext;
import org.springframework.util.AntPathMatcher;
@@ -44,16 +43,11 @@ public PrefixRoutePathMatcher(String pattern) {
@Override
public boolean test(RequestContext context) {
- //Solve the problem of prefix and suffix matching
+ //Solve the problem of prefix matching
HttpServletRequest request = context.getRequest();
- String path = request.getServletPath();
- String pathInfo = request.getPathInfo();
- if (StringUtil.isNotBlank(pathInfo)) {
- if (StringUtil.isBlank(path)) {
- path = pathInfo;
- } else {
- path = path + pathInfo;
- }
+ String path = request.getRequestURI();
+ if (path == null) {
+ AssertUtil.assertNotBlank(pattern, "requesturi cannot be blank");
}
if (canMatch) {
return pathMatcher.match(pattern, path);
diff --git a/sentinel-adapter/sentinel-zuul-adapter/src/main/java/com/alibaba/csp/sentinel/adapter/gateway/zuul/api/route/RegexRoutePathMatcher.java b/sentinel-adapter/sentinel-zuul-adapter/src/main/java/com/alibaba/csp/sentinel/adapter/gateway/zuul/api/route/RegexRoutePathMatcher.java
index 03494d5d5e..4363e4e795 100644
--- a/sentinel-adapter/sentinel-zuul-adapter/src/main/java/com/alibaba/csp/sentinel/adapter/gateway/zuul/api/route/RegexRoutePathMatcher.java
+++ b/sentinel-adapter/sentinel-zuul-adapter/src/main/java/com/alibaba/csp/sentinel/adapter/gateway/zuul/api/route/RegexRoutePathMatcher.java
@@ -16,7 +16,6 @@
package com.alibaba.csp.sentinel.adapter.gateway.zuul.api.route;
import com.alibaba.csp.sentinel.util.AssertUtil;
-import com.alibaba.csp.sentinel.util.StringUtil;
import com.alibaba.csp.sentinel.util.function.Predicate;
import com.netflix.zuul.context.RequestContext;
@@ -40,16 +39,11 @@ public RegexRoutePathMatcher(String pattern) {
@Override
public boolean test(RequestContext context) {
- //Solve the problem of prefix and suffix matching
+ //Solve the problem of route matching
HttpServletRequest request = context.getRequest();
- String path = request.getServletPath();
- String pathInfo = request.getPathInfo();
- if (StringUtil.isNotBlank(pathInfo)) {
- if (StringUtil.isBlank(path)) {
- path = pathInfo;
- } else {
- path = path + pathInfo;
- }
+ String path = request.getRequestURI();
+ if (path == null) {
+ AssertUtil.assertNotBlank(pattern, "requesturi cannot be blank");
}
return regex.matcher(path).matches();
}
diff --git a/sentinel-adapter/sentinel-zuul-adapter/src/test/java/com/alibaba/csp/sentinel/adapter/gateway/zuul/route/SentinelZuulRouteTest.java b/sentinel-adapter/sentinel-zuul-adapter/src/test/java/com/alibaba/csp/sentinel/adapter/gateway/zuul/route/SentinelZuulRouteTest.java
index 49b1a8c581..7fef28aa07 100644
--- a/sentinel-adapter/sentinel-zuul-adapter/src/test/java/com/alibaba/csp/sentinel/adapter/gateway/zuul/route/SentinelZuulRouteTest.java
+++ b/sentinel-adapter/sentinel-zuul-adapter/src/test/java/com/alibaba/csp/sentinel/adapter/gateway/zuul/route/SentinelZuulRouteTest.java
@@ -6,13 +6,9 @@
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
-import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
-
-import javax.servlet.http.HttpServletRequest;
+import org.springframework.mock.web.MockHttpServletRequest;
import static com.alibaba.csp.sentinel.adapter.gateway.zuul.constants.ZuulConstant.SERVICE_ID_KEY;
-import static org.mockito.Mockito.when;
/**
* @author: jiangzian
@@ -21,32 +17,36 @@ public class SentinelZuulRouteTest {
private final String SERVICE_ID = "servicea";
- private final String URI = "/servicea/test";
-
- @Mock
- private HttpServletRequest httpServletRequest;
+ private final String SERVER_NAME = "www.example.com";
+ private final String REQUEST_URI = "/servicea/test.jsp";
+ private final String QUERY_STRING = "param1=value1¶m";
private RequestContext requestContext = new RequestContext();
+
@Before
public void setUp() {
- MockitoAnnotations.initMocks(this);
- when(httpServletRequest.getContextPath()).thenReturn("");
- when(httpServletRequest.getPathInfo()).thenReturn(URI);
+ MockHttpServletRequest request = new MockHttpServletRequest();
+ request.setServerName(SERVER_NAME);
+ request.setRequestURI(REQUEST_URI);
+ request.setQueryString(QUERY_STRING);
requestContext.set(SERVICE_ID_KEY, SERVICE_ID);
- requestContext.setRequest(httpServletRequest);
+ requestContext.setRequest(request);
RequestContext.testSetCurrentContext(requestContext);
}
@Test
public void testPrefixRoutePathMatche() {
- PrefixRoutePathMatcher prefixRoutePathMatcher = new PrefixRoutePathMatcher("/**");
+ PrefixRoutePathMatcher prefixRoutePathMatcher = new PrefixRoutePathMatcher("/servicea/????.jsp");
Assert.assertTrue(prefixRoutePathMatcher.test(requestContext));
}
@Test
public void testRegexRoutePathMatcher() {
- RegexRoutePathMatcher prefixRoutePathMatcher = new RegexRoutePathMatcher(URI);
- Assert.assertTrue(prefixRoutePathMatcher.test(requestContext));
+ RegexRoutePathMatcher regexRoutePathMatcher = new RegexRoutePathMatcher("/servicea[^\\s]+.jsp");
+ Assert.assertTrue(regexRoutePathMatcher.test(requestContext));
+
+
}
-}
+
+}
\ No newline at end of file
From e96a35f599ac37d9e2faeb2d7f2c5e0c66b87ceb Mon Sep 17 00:00:00 2001
From: JZH <576811031@QQ.COM>
Date: Tue, 1 Sep 2020 11:25:37 +0800
Subject: [PATCH 6/6] Modify the regex matching rule to add an unexpected value
test
---
.../adapter/gateway/zuul/route/SentinelZuulRouteTest.java | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/sentinel-adapter/sentinel-zuul-adapter/src/test/java/com/alibaba/csp/sentinel/adapter/gateway/zuul/route/SentinelZuulRouteTest.java b/sentinel-adapter/sentinel-zuul-adapter/src/test/java/com/alibaba/csp/sentinel/adapter/gateway/zuul/route/SentinelZuulRouteTest.java
index 7fef28aa07..eb67921a77 100644
--- a/sentinel-adapter/sentinel-zuul-adapter/src/test/java/com/alibaba/csp/sentinel/adapter/gateway/zuul/route/SentinelZuulRouteTest.java
+++ b/sentinel-adapter/sentinel-zuul-adapter/src/test/java/com/alibaba/csp/sentinel/adapter/gateway/zuul/route/SentinelZuulRouteTest.java
@@ -39,14 +39,18 @@ public void setUp() {
public void testPrefixRoutePathMatche() {
PrefixRoutePathMatcher prefixRoutePathMatcher = new PrefixRoutePathMatcher("/servicea/????.jsp");
Assert.assertTrue(prefixRoutePathMatcher.test(requestContext));
+
+ prefixRoutePathMatcher = new PrefixRoutePathMatcher("/servicea/????.do");
+ Assert.assertTrue(!prefixRoutePathMatcher.test(requestContext));
}
@Test
public void testRegexRoutePathMatcher() {
- RegexRoutePathMatcher regexRoutePathMatcher = new RegexRoutePathMatcher("/servicea[^\\s]+.jsp");
+ RegexRoutePathMatcher regexRoutePathMatcher = new RegexRoutePathMatcher("/servicea/[a-zA-z]+(\\.jsp)");
Assert.assertTrue(regexRoutePathMatcher.test(requestContext));
-
+ regexRoutePathMatcher = new RegexRoutePathMatcher("/serviceb/[a-zA-z]+(\\.jsp)");
+ Assert.assertTrue(!regexRoutePathMatcher.test(requestContext));
}
}
\ No newline at end of file