@@ -117,51 +117,20 @@ class ApiSecuritySamplerTest extends DDSpecification {
117117 !preSampled
118118 }
119119
120- void 'preSampleRequest with null route and blocked request does not sample'() {
121- given:
122- def ctx = createContextWithUrl(null, 'GET', 403, 'http://localhost:8080/admin/users')
123- ctx.setWafBlocked() // Request was blocked by AppSec
124- def sampler = new ApiSecuritySamplerImpl()
125-
126- when:
127- def preSampled = sampler.preSampleRequest(ctx)
128-
129- then:
130- !preSampled // Blocked requests should not be sampled
131- }
132-
133- void 'preSampleRequest with null route and 403 non-blocked API does sample'() {
120+ void 'preSampleRequest with null route and non-404 status does sample'() {
134121 given:
135122 def ctx = createContextWithUrl(null, 'GET', 403, 'http://localhost:8080/api/forbidden-resource')
136- // NOT calling setWafBlocked() - this is a legitimate API that returns 403
137123 def sampler = new ApiSecuritySamplerImpl()
138124
139125 when:
140126 def preSampled = sampler.preSampleRequest(ctx)
141127
142128 then:
143- preSampled // Legitimate APIs that return 403 should be sampled
129+ preSampled // Non-404 responses should be sampled when endpoint is available
144130 ctx.getOrComputeEndpoint() != null
145131 ctx.getApiSecurityEndpointHash() != null
146132 }
147133
148- void 'preSampleRequest with null route and blocked request with different status codes does not sample'() {
149- given:
150- def ctx200 = createContextWithUrl(null, 'GET', 200, 'http://localhost:8080/attack')
151- ctx200.setWafBlocked()
152- def ctx500 = createContextWithUrl(null, 'GET', 500, 'http://localhost:8080/attack')
153- ctx500.setWafBlocked()
154- def sampler = new ApiSecuritySamplerImpl()
155-
156- when:
157- def preSampled200 = sampler.preSampleRequest(ctx200)
158- def preSampled500 = sampler.preSampleRequest(ctx500)
159-
160- then:
161- !preSampled200 // Blocked requests should not be sampled regardless of status code
162- !preSampled500
163- }
164-
165134 void 'second request with same endpoint is not sampled'() {
166135 given:
167136 def ctx1 = createContextWithUrl(null, 'GET', 200, 'http://localhost:8080/api/users/123')
@@ -596,21 +565,6 @@ class ApiSecuritySamplerTest extends DDSpecification {
596565 ctx.getApiSecurityEndpointHash() == null // But hash was never set because sampling failed
597566 }
598567
599- void 'RFC-1076: blocked request with valid endpoint does not sample'() {
600- given:
601- def ctx = createContextWithUrl(null, 'POST', 403, 'http://localhost:8080/api/admin/users')
602- ctx.setWafBlocked() // Request blocked by AppSec WAF
603- def sampler = new ApiSecuritySamplerImpl()
604-
605- when:
606- def preSampled = sampler.preSampleRequest(ctx)
607-
608- then:
609- !preSampled
610- // Blocked requests represent attacks, not legitimate API endpoints
611- ctx.getApiSecurityEndpointHash() == null
612- }
613-
614568 // Helper method to compute hash same way as ApiSecuritySamplerImpl
615569 private static long computeApiHash(final String route, final String method, final int statusCode) {
616570 long result = 17
0 commit comments