@@ -356,6 +356,94 @@ public void testObfuscated() {
356
356
assertEquals ("A" , result .getVariation ().getValue ().stringValue ());
357
357
}
358
358
359
+ @ Test
360
+ public void testObfuscatedExtraLogging () {
361
+ // Test that extraLogging is properly deobfuscated when isConfigObfuscated is true
362
+
363
+ Map <String , Variation > variations = createVariations ("a" );
364
+
365
+ // Create extraLogging with obfuscated keys and values
366
+ Map <String , String > obfuscatedExtraLogging = new HashMap <>();
367
+ obfuscatedExtraLogging .put (base64Encode ("testKey" ), base64Encode ("testValue" ));
368
+ obfuscatedExtraLogging .put (base64Encode ("anotherKey" ), base64Encode ("anotherValue" ));
369
+
370
+ List <Split > splits = new ArrayList <>();
371
+ splits .add (new Split ("a" , null , obfuscatedExtraLogging ));
372
+
373
+ List <Allocation > allocations = createAllocations ("test" , splits );
374
+
375
+ // Create the base flag
376
+ FlagConfig flag = createFlag (getMD5Hex ("flag" ), true , variations , allocations );
377
+
378
+ // Encode the variations (following the same pattern as the main obfuscated test)
379
+ Map <String , Variation > encodedVariations = new HashMap <>();
380
+ for (Map .Entry <String , Variation > variationEntry : variations .entrySet ()) {
381
+ String encodedVariationKey = base64Encode (variationEntry .getKey ());
382
+ Variation variationToEncode = variationEntry .getValue ();
383
+ Variation newVariation =
384
+ new Variation (
385
+ encodedVariationKey ,
386
+ EppoValue .valueOf (base64Encode (variationToEncode .getValue ().stringValue ())));
387
+ encodedVariations .put (encodedVariationKey , newVariation );
388
+ }
389
+
390
+ // Encode the allocations
391
+ List <Allocation > encodedAllocations =
392
+ allocations .stream ()
393
+ .map (
394
+ allocationToEncode -> {
395
+ allocationToEncode .setKey (base64Encode (allocationToEncode .getKey ()));
396
+ List <Split > encodedSplits =
397
+ allocationToEncode .getSplits ().stream ()
398
+ .map (
399
+ splitToEncode ->
400
+ new Split (
401
+ base64Encode (splitToEncode .getVariationKey ()),
402
+ splitToEncode .getShards (),
403
+ splitToEncode .getExtraLogging ()))
404
+ .collect (Collectors .toList ());
405
+ return new Allocation (
406
+ allocationToEncode .getKey (),
407
+ allocationToEncode .getRules (),
408
+ allocationToEncode .getStartAt (),
409
+ allocationToEncode .getEndAt (),
410
+ encodedSplits ,
411
+ allocationToEncode .doLog ());
412
+ })
413
+ .collect (Collectors .toList ());
414
+
415
+ // Create the obfuscated flag
416
+ FlagConfig obfuscatedFlag =
417
+ new FlagConfig (
418
+ flag .getKey (),
419
+ flag .isEnabled (),
420
+ flag .getTotalShards (),
421
+ flag .getVariationType (),
422
+ encodedVariations ,
423
+ encodedAllocations );
424
+
425
+ // Test with obfuscated config
426
+ FlagEvaluationResult result =
427
+ FlagEvaluator .evaluateFlag (obfuscatedFlag , "flag" , "subject" , new Attributes (), true );
428
+
429
+ // Verify that extraLogging is deobfuscated
430
+ Map <String , String > extraLogging = result .getExtraLogging ();
431
+ assertNotNull (extraLogging );
432
+ assertEquals ("testValue" , extraLogging .get ("testKey" ));
433
+ assertEquals ("anotherValue" , extraLogging .get ("anotherKey" ));
434
+ assertEquals (2 , extraLogging .size ());
435
+
436
+ // Test with non-obfuscated config to ensure no deobfuscation happens
437
+ result = FlagEvaluator .evaluateFlag (obfuscatedFlag , "flag" , "subject" , new Attributes (), false );
438
+
439
+ // Verify that extraLogging remains obfuscated
440
+ extraLogging = result .getExtraLogging ();
441
+ assertNotNull (extraLogging );
442
+ assertEquals (base64Encode ("testValue" ), extraLogging .get (base64Encode ("testKey" )));
443
+ assertEquals (base64Encode ("anotherValue" ), extraLogging .get (base64Encode ("anotherKey" )));
444
+ assertEquals (2 , extraLogging .size ());
445
+ }
446
+
359
447
private Map <String , Variation > createVariations (String key ) {
360
448
return createVariations (key , null , null );
361
449
}
0 commit comments