use of com.netflix.zuul.context.RequestContext in project bucket4j-spring-boot-starter by MarcGiffing.
the class ZuulRateLimitFilterTest method should_execute_all_checks_when_using_RateLimitConditionMatchingStrategy_All.
@Test
public void should_execute_all_checks_when_using_RateLimitConditionMatchingStrategy_All() {
MockHttpServletRequest request = new MockHttpServletRequest("GET", "/url");
RequestContext context = new RequestContext();
context.setRequest(request);
RequestContext.testSetCurrentContext(context);
when(rateLimitCheck1.rateLimit(any())).thenReturn(consumptionProbe);
when(rateLimitCheck2.rateLimit(any())).thenReturn(consumptionProbe);
when(rateLimitCheck3.rateLimit(any())).thenReturn(consumptionProbe);
configuration.setStrategy(RateLimitConditionMatchingStrategy.ALL);
filter.run();
verify(rateLimitCheck1, times(1)).rateLimit(any());
verify(rateLimitCheck2, times(1)).rateLimit(any());
verify(rateLimitCheck3, times(1)).rateLimit(any());
}
use of com.netflix.zuul.context.RequestContext in project bucket4j-spring-boot-starter by MarcGiffing.
the class ZuulRateLimitFilterTest method should_execute_only_one_check_when_using_RateLimitConditionMatchingStrategy_FIRST.
@Test
public void should_execute_only_one_check_when_using_RateLimitConditionMatchingStrategy_FIRST() {
MockHttpServletRequest request = new MockHttpServletRequest("GET", "/url");
RequestContext context = new RequestContext();
context.setRequest(request);
RequestContext.testSetCurrentContext(context);
configuration.setStrategy(RateLimitConditionMatchingStrategy.FIRST);
when(rateLimitCheck1.rateLimit(any())).thenReturn(consumptionProbe);
filter.run();
verify(rateLimitCheck1, times(1)).rateLimit(any());
verify(rateLimitCheck2, times(0)).rateLimit(any());
verify(rateLimitCheck3, times(0)).rateLimit(any());
}
use of com.netflix.zuul.context.RequestContext in project bucket4j-spring-boot-starter by MarcGiffing.
the class ZuulRateLimitFilterTest method setup.
@Before
public void setup() {
consumptionProbe = Mockito.mock(ConsumptionProbe.class);
when(consumptionProbe.isConsumed()).thenReturn(true);
rateLimitCheck1 = mock(RateLimitCheck.class);
rateLimitCheck2 = mock(RateLimitCheck.class);
rateLimitCheck3 = mock(RateLimitCheck.class);
configuration = new FilterConfiguration();
configuration.setRateLimitChecks(Arrays.asList(rateLimitCheck1, rateLimitCheck2, rateLimitCheck3));
configuration.setUrl("url");
filter = new ZuulRateLimitFilter(configuration) {
@Override
protected RequestContext getCurrentRequestContext() {
return Mockito.mock(RequestContext.class);
}
};
}
use of com.netflix.zuul.context.RequestContext in project spring-cloud-netflix by spring-cloud.
the class PreDecorationFilterTests method sensitiveHeadersCaseInsensitive.
@Test
public void sensitiveHeadersCaseInsensitive() throws Exception {
this.properties.setPrefix("/api");
this.properties.setStripPrefix(true);
this.properties.setSensitiveHeaders(Collections.singleton("X-bAr"));
this.request.setRequestURI("/api/foo/1");
this.routeLocator.addRoute("/foo/**", "foo");
this.filter.run();
RequestContext ctx = RequestContext.getCurrentContext();
@SuppressWarnings("unchecked") Set<String> sensitiveHeaders = (Set<String>) ctx.get(ProxyRequestHelper.IGNORED_HEADERS);
assertTrue("sensitiveHeaders is wrong: " + sensitiveHeaders, sensitiveHeaders.containsAll(Collections.singletonList("x-bar")));
}
use of com.netflix.zuul.context.RequestContext in project spring-cloud-netflix by spring-cloud.
the class PreDecorationFilterTests method ignoredHeadersAlreadySetInRequestContextDontGetOverridden.
@Test
public void ignoredHeadersAlreadySetInRequestContextDontGetOverridden() throws Exception {
this.properties.setPrefix("/api");
this.properties.setStripPrefix(true);
this.properties.setSensitiveHeaders(Collections.singleton("x-bar"));
this.request.setRequestURI("/api/foo/1");
this.routeLocator.addRoute("/foo/**", "foo");
RequestContext ctx = RequestContext.getCurrentContext();
ctx.set(ProxyRequestHelper.IGNORED_HEADERS, new HashSet<>(Arrays.asList("x-foo")));
this.filter.run();
@SuppressWarnings("unchecked") Set<String> sensitiveHeaders = (Set<String>) ctx.get(ProxyRequestHelper.IGNORED_HEADERS);
assertTrue("sensitiveHeaders is wrong: " + sensitiveHeaders, sensitiveHeaders.containsAll(Arrays.asList("x-bar", "x-foo")));
}
Aggregations