From f0ce5387de460d93874eec0676713565297bf5bb Mon Sep 17 00:00:00 2001 From: "alejandro.gonzalez" Date: Fri, 21 Jun 2024 08:04:30 +0200 Subject: [PATCH] fix test --- .../java/com/datadog/appsec/AppSecSystem.java | 7 ++--- .../appsec/AppSecSystemSpecification.groovy | 27 +++---------------- 2 files changed, 8 insertions(+), 26 deletions(-) diff --git a/dd-java-agent/appsec/src/main/java/com/datadog/appsec/AppSecSystem.java b/dd-java-agent/appsec/src/main/java/com/datadog/appsec/AppSecSystem.java index 506f15cf61b..152f7b8c7d2 100644 --- a/dd-java-agent/appsec/src/main/java/com/datadog/appsec/AppSecSystem.java +++ b/dd-java-agent/appsec/src/main/java/com/datadog/appsec/AppSecSystem.java @@ -41,6 +41,7 @@ public class AppSecSystem { private static AppSecConfigServiceImpl APP_SEC_CONFIG_SERVICE; private static ReplaceableEventProducerService REPLACEABLE_EVENT_PRODUCER; // testing private static Runnable RESET_SUBSCRIPTION_SERVICE; + private static RateLimiter RATE_LIMITER; // For testing purpose public static void start(SubscriptionService gw, SharedCommunicationObjects sco) { try { @@ -81,17 +82,17 @@ private static void doStart(SubscriptionService gw, SharedCommunicationObjects s sco.createRemaining(config); - RateLimiter rateLimiter = getRateLimiter(config, sco.monitoring); + RATE_LIMITER = getRateLimiter(config, sco.monitoring); GatewayBridge gatewayBridge = new GatewayBridge( gw, REPLACEABLE_EVENT_PRODUCER, - rateLimiter, + RATE_LIMITER, requestSampler, APP_SEC_CONFIG_SERVICE.getTraceSegmentPostProcessors()); - loadModules(eventDispatcher, rateLimiter); + loadModules(eventDispatcher, RATE_LIMITER); gatewayBridge.init(); RESET_SUBSCRIPTION_SERVICE = gatewayBridge::stop; diff --git a/dd-java-agent/appsec/src/test/groovy/com/datadog/appsec/AppSecSystemSpecification.groovy b/dd-java-agent/appsec/src/test/groovy/com/datadog/appsec/AppSecSystemSpecification.groovy index 624fd81db6d..8255bbfcd7f 100644 --- a/dd-java-agent/appsec/src/test/groovy/com/datadog/appsec/AppSecSystemSpecification.groovy +++ b/dd-java-agent/appsec/src/test/groovy/com/datadog/appsec/AppSecSystemSpecification.groovy @@ -83,39 +83,20 @@ class AppSecSystemSpecification extends DDSpecification { 1 * traceSegment.setTagTop('actor.ip', '1.1.1.1') } - //TODO - /* void 'honors appsec.trace.rate.limit'() { - BiFunction> requestEndedCB - RequestContext requestContext = Mock() - TraceSegment traceSegment = Mock() - AppSecRequestContext appSecReqCtx = Mock() - def sco = sharedCommunicationObjects() - Counter throttledCounter = Mock() - IGSpanInfo span = Mock(AgentSpan) setup: injectSysConfig('dd.appsec.trace.rate.limit', '5') + def sco = sharedCommunicationObjects() + def counter = 0 when: AppSecSystem.start(subService, sco) - 7.times { requestEndedCB.apply(requestContext, span) } then: - span.getTags() >> ['http.client_ip':'1.1.1.1'] - 1 * sco.monitoring.newCounter('_dd.java.appsec.rate_limit.dropped_traces') >> throttledCounter - 1 * subService.registerCallback(EVENTS.requestEnded(), _) >> { requestEndedCB = it[1]; null } - 7 * requestContext.getData(RequestContextSlot.APPSEC) >> appSecReqCtx - 7 * requestContext.traceSegment >> traceSegment - 7 * appSecReqCtx.transferCollectedEvents() >> [Stub(AppSecEvent)] - // allow for one extra in case we move to another second and round down the prev count - (5..6) * appSecReqCtx.getRequestHeaders() >> [:] - (5..6) * appSecReqCtx.getResponseHeaders() >> [:] - (5..6) * traceSegment.setDataTop("appsec", _) - (1..2) * throttledCounter.increment(1) - } + AppSecSystem.RATE_LIMITER.limitPerSec == 5 - */ + } void 'throws if the config file is not parseable'() { setup: