Skip to content

Commit

Permalink
fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
jandro996 committed Jun 21, 2024
1 parent 60d33b8 commit f0ce538
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<RequestContext, AgentSpan, Flow<Void>> 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:
Expand Down

0 comments on commit f0ce538

Please sign in to comment.