@@ -206,7 +206,7 @@ void should_change_sensitivity_if_custom_sensitivity_threshold_provided(HttpClie
206206
207207 @ Test
208208 @ DeployApi ({ "/apis/missing_resource.json" })
209- void should_return_error_if_resource_is_not_configured_properly (HttpClient client ) throws InterruptedException {
209+ void should_return_error_if_resource_is_not_configured_properly (HttpClient client ) {
210210 wiremock .stubFor (get ("/endpoint" ).willReturn (aResponse ().withStatus (200 )));
211211
212212 client
@@ -237,7 +237,7 @@ void should_return_error_if_resource_is_not_configured_properly(HttpClient clien
237237
238238 @ Test
239239 @ DeployApi ({ "/apis/broken_content_check_list.json" })
240- void should_handle_parsing_incorrectly_formatted_list (HttpClient client ) throws InterruptedException {
240+ void should_handle_parsing_incorrectly_formatted_list (HttpClient client ) {
241241 wiremock .stubFor (get ("/endpoint" ).willReturn (aResponse ().withStatus (200 )));
242242
243243 client
@@ -292,12 +292,51 @@ void should_return_an_error_when_inference_fail(HttpClient client) {
292292 })
293293 .assertNoErrors ();
294294 }
295+
296+ @ Test
297+ @ DeployApi ({ "/apis/block_request_policy_empty_contentChecks.json" })
298+ void should_block_request_if_prompt_violation_detected_and_empty_contentChecks (HttpClient client , VertxTestContext context ) {
299+ wiremock .stubFor (get ("/endpoint" ).willReturn (aResponse ().withStatus (200 )));
300+
301+ var metricsAsserts = metricsSubject
302+ .doOnNext (metrics ->
303+ assertThat (metrics )
304+ .extracting (Metrics ::getAdditionalMetrics )
305+ .asInstanceOf (InstanceOfAssertFactories .SET )
306+ .containsExactlyInAnyOrder (
307+ new AdditionalMetric .KeywordMetric ("keyword_action" , "request-blocked" ),
308+ new AdditionalMetric .KeywordMetric ("keyword_content_violations" , "toxic" )
309+ )
310+ )
311+ .ignoreElements ();
312+
313+ var clientAsserts = client
314+ .rxRequest (HttpMethod .GET , "/block-request-empty-contentChecks" )
315+ .flatMap (request ->
316+ request .rxSend (
317+ """
318+ {
319+ "model": "GPT-2000",
320+ "date": "01-01-2025",
321+ "prompt": "Nobody asked for your bullsh*t response."
322+ }
323+ """
324+ )
325+ )
326+ .flatMapPublisher (response -> {
327+ assertThat (response .statusCode ()).isEqualTo (400 );
328+ return response .toFlowable ();
329+ })
330+ .map (responseBody -> assertThat (responseBody ).hasToString ("AI prompt validation detected. Reason: [toxic]" ))
331+ .ignoreElements ();
332+
333+ finalAssert (context , metricsAsserts , clientAsserts );
334+ }
295335 }
296336
337+ @ Disabled ("Flaky on CI will be fixed with: https://gravitee.atlassian.net/browse/APIM-13078" )
297338 @ Nested
298- @ DeployApi (
299- { "/apis/block_request_policy_empty_contentChecks.json" , "/apis/block_request_policy.json" , "/apis/log_request_policy.json" }
300- )
339+ @ DeployApi ({ "/apis/block_request_policy.json" , "/apis/log_request_policy.json" })
301340 class WithRealAiResource extends AbstractAiPromptGuardRailsPolicyIntegrationTest {
302341
303342 Observable <Long > timer ;
@@ -401,48 +440,6 @@ void should_block_request_if_prompt_violation_detected(HttpClient client, VertxT
401440
402441 finalAssert (context , metricsAsserts , clientAsserts );
403442 }
404-
405- @ Test
406- void should_block_request_if_prompt_violation_detected_and_empty_contentChecks (HttpClient client , VertxTestContext context ) {
407- wiremock .stubFor (get ("/endpoint" ).willReturn (aResponse ().withStatus (200 )));
408-
409- var metricsAsserts = metricsSubject
410- .doOnNext (metrics ->
411- assertThat (metrics )
412- .extracting (Metrics ::getAdditionalMetrics )
413- .asInstanceOf (InstanceOfAssertFactories .SET )
414- .containsExactlyInAnyOrder (
415- new AdditionalMetric .KeywordMetric ("keyword_action" , "request-blocked" ),
416- new AdditionalMetric .KeywordMetric ("keyword_content_violations" , "toxic" )
417- )
418- )
419- .ignoreElements ();
420-
421- var clientAsserts = timer
422- .ignoreElements ()
423- .andThen (
424- client
425- .rxRequest (HttpMethod .GET , "/block-request-empty-contentChecks" )
426- .flatMap (request ->
427- request .rxSend (
428- """
429- {
430- "model": "GPT-2000",
431- "date": "01-01-2025",
432- "prompt": "Nobody asked for your bullsh*t response."
433- }"""
434- )
435- )
436- .flatMapPublisher (response -> {
437- assertThat (response .statusCode ()).isEqualTo (400 );
438- return response .toFlowable ();
439- })
440- )
441- .map (responseBody -> assertThat (responseBody ).hasToString ("AI prompt validation detected. Reason: [toxic]" ))
442- .ignoreElements ();
443-
444- finalAssert (context , metricsAsserts , clientAsserts );
445- }
446443 }
447444
448445 private static void finalAssert (VertxTestContext context , Completable metricsAsserts , Completable clientAsserts ) {
0 commit comments