@@ -157,13 +157,14 @@ class AIGuardInternalTests extends DDSpecification {
157157 Request request = null
158158 Throwable error = null
159159 AIGuard.Evaluation eval = null
160+ Map<String , Object > receivedMeta = null
160161 final throwAbortError = suite. blocking && suite. action != ALLOW
161162 final call = Mock (Call ) {
162163 execute() >> {
163164 return mockResponse(
164165 request,
165166 200 ,
166- [data : [attributes : [action : suite. action, reason : suite. reason, is_blocking_enabled : suite. blocking]]]
167+ [data : [attributes : [action : suite. action, reason : suite. reason, tags : suite . tags ?: [], is_blocking_enabled : suite. blocking]]]
167168 )
168169 }
169170 }
@@ -189,11 +190,18 @@ class AIGuardInternalTests extends DDSpecification {
189190 }
190191 1 * span. setTag(AIGuardInternal . ACTION_TAG , suite. action)
191192 1 * span. setTag(AIGuardInternal . REASON_TAG , suite. reason)
192- 1 * span. setMetaStruct(AIGuardInternal . META_STRUCT_TAG , [messages : suite. messages])
193+ 1 * span. setMetaStruct(AIGuardInternal . META_STRUCT_TAG , _ as Map ) >> {
194+ receivedMeta = it[1 ] as Map<String , Object >
195+ return span
196+ }
193197 if (throwAbortError) {
194198 1 * span. addThrowable(_ as AIGuard.AIGuardAbortError )
195199 }
196200
201+ receivedMeta. messages == suite. messages
202+ if (suite. tags) {
203+ receivedMeta. attack_categories == suite. tags
204+ }
197205 assertRequest(request, suite. messages)
198206 if (throwAbortError) {
199207 error instanceof AIGuard.AIGuardAbortError
@@ -444,6 +452,14 @@ class AIGuardInternalTests extends DDSpecification {
444452 0 * span. setTag(AIGuardInternal . TOOL_TAG , _)
445453 }
446454
455+ void ' map requires even number of params' () {
456+ when :
457+ AIGuardInternal . mapOf(' 1' , ' 2' , ' 3' )
458+
459+ then :
460+ thrown(IllegalArgumentException )
461+ }
462+
447463 private static assertTelemetry (final String metric , final String ...tags ) {
448464 final metrics = WafMetricCollector . get(). with {
449465 prepareMetrics()
@@ -497,22 +513,28 @@ class AIGuardInternalTests extends DDSpecification {
497513 private static class TestSuite {
498514 private final AIGuard.Action action
499515 private final String reason
516+ private final List<String > tags
500517 private final boolean blocking
501518 private final String description
502519 private final String target
503520 private final List<AIGuard.Message > messages
504521
505- TestSuite (AIGuard.Action action , String reason , boolean blocking , String description , String target , List<AIGuard.Message > messages ) {
522+ TestSuite (AIGuard.Action action , String reason , List< String > tags , boolean blocking , String description , String target , List<AIGuard.Message > messages ) {
506523 this . action = action
507524 this . reason = reason
525+ this . tags = tags
508526 this . blocking = blocking
509527 this . description = description
510528 this . target = target
511529 this . messages = messages
512530 }
513531
514532 static List<TestSuite > build () {
515- def actionValues = [[ALLOW , ' Go ahead' ], [DENY , ' Nope' ], [ABORT , ' Kill it with fire' ]]
533+ def actionValues = [
534+ [ALLOW , ' Go ahead' , []],
535+ [DENY , ' Nope' , [' deny_everything' , ' test_deny' ]],
536+ [ABORT , ' Kill it with fire' , [' alarm_tag' , ' abort_everything' ]]
537+ ]
516538 def blockingValues = [true , false ]
517539 def suiteValues = [
518540 [' tool call' , ' tool' , TOOL_CALL ],
@@ -521,7 +543,7 @@ class AIGuardInternalTests extends DDSpecification {
521543 ]
522544 return combinations([actionValues, blockingValues, suiteValues] as Iterable )
523545 .collect { action , blocking , suite ->
524- new TestSuite (action[0 ], action[1 ], blocking, suite[0 ], suite[1 ], suite[2 ])
546+ new TestSuite (action[0 ], action[1 ], action[ 2 ], blocking, suite[0 ], suite[1 ], suite[2 ])
525547 }
526548 }
527549
0 commit comments