diff --git a/pom.xml b/pom.xml index a6586e1f..033ca77d 100644 --- a/pom.xml +++ b/pom.xml @@ -83,7 +83,7 @@ org.springframework.cloud spring-cloud-dependencies - Finchley.RELEASE + Finchley.SR4 pom import diff --git a/spring-cloud-zuul-ratelimit-core/src/main/java/com/marcosbarbero/cloud/autoconfigure/zuul/ratelimit/config/properties/RateLimitType.java b/spring-cloud-zuul-ratelimit-core/src/main/java/com/marcosbarbero/cloud/autoconfigure/zuul/ratelimit/config/properties/RateLimitType.java index c17d85e5..6e32d1b1 100644 --- a/spring-cloud-zuul-ratelimit-core/src/main/java/com/marcosbarbero/cloud/autoconfigure/zuul/ratelimit/config/properties/RateLimitType.java +++ b/spring-cloud-zuul-ratelimit-core/src/main/java/com/marcosbarbero/cloud/autoconfigure/zuul/ratelimit/config/properties/RateLimitType.java @@ -31,14 +31,9 @@ public enum RateLimitType { ORIGIN { @Override public boolean apply(HttpServletRequest request, Route route, RateLimitUtils rateLimitUtils, String matcher) { - if(matcher.contains("/")) { - try { - SubnetUtils subnetUtils = new SubnetUtils(matcher); - return subnetUtils.getInfo().isInRange(rateLimitUtils.getRemoteAddress(request)); - } - catch(Exception e) { - return false; - } + if (matcher.contains("/")) { + SubnetUtils subnetUtils = new SubnetUtils(matcher); + return subnetUtils.getInfo().isInRange(rateLimitUtils.getRemoteAddress(request)); } return matcher.equals(rateLimitUtils.getRemoteAddress(request)); } diff --git a/spring-cloud-zuul-ratelimit-core/src/test/java/com/marcosbarbero/cloud/autoconfigure/zuul/ratelimit/config/properties/RateLimitTypeTest.java b/spring-cloud-zuul-ratelimit-core/src/test/java/com/marcosbarbero/cloud/autoconfigure/zuul/ratelimit/config/properties/RateLimitTypeTest.java index 4ea0f120..576f8f8a 100644 --- a/spring-cloud-zuul-ratelimit-core/src/test/java/com/marcosbarbero/cloud/autoconfigure/zuul/ratelimit/config/properties/RateLimitTypeTest.java +++ b/spring-cloud-zuul-ratelimit-core/src/test/java/com/marcosbarbero/cloud/autoconfigure/zuul/ratelimit/config/properties/RateLimitTypeTest.java @@ -59,6 +59,14 @@ public void applyOrigin() { assertThat(apply).isTrue(); } + @Test + public void applyOriginInRange() { + when(httpServletRequest.getRemoteAddr()).thenReturn("127.0.0.10"); + + boolean apply = RateLimitType.ORIGIN.apply(httpServletRequest, route, rateLimitUtils, "127.0.0.8/29"); + assertThat(apply).isTrue(); + } + @Test public void applyOriginNoMatch() { when(httpServletRequest.getRemoteAddr()).thenReturn("testAddr");