@@ -271,6 +271,92 @@ func TestRedactSummaryDebug(t *testing.T) {
271
271
}
272
272
}
273
273
274
+ func TestRedactSummaryDebugHashMD5 (t * testing.T ) {
275
+ testConfig := TestConfig {
276
+ config : & Config {
277
+ AllowedKeys : []string {"id" , "group" , "name" , "group.id" , "member (id)" , "token_some" , "api_key_some" , "email" },
278
+ BlockedValues : []string {"4[0-9]{12}(?:[0-9]{3})?" },
279
+ HashFunction : MD5 ,
280
+ IgnoredKeys : []string {"safe_attribute" },
281
+ BlockedKeyPatterns : []string {".*token.*" , ".*api_key.*" },
282
+ Summary : "debug" ,
283
+ },
284
+ allowed : map [string ]pcommon.Value {
285
+ "id" : pcommon .NewValueInt (5 ),
286
+ "group.id" : pcommon .NewValueStr ("some.valid.id" ),
287
+ "member (id)" : pcommon .NewValueStr ("some other valid id" ),
288
+ },
289
+ masked : map [string ]pcommon.Value {
290
+ "name" : pcommon .NewValueStr ("placeholder 4111111111111111" ),
291
+ },
292
+ ignored : map [string ]pcommon.Value {
293
+ "safe_attribute" : pcommon .NewValueStr ("harmless 4111111111111112" ),
294
+ },
295
+ redacted : map [string ]pcommon.Value {
296
+ "credit_card" : pcommon .NewValueStr ("4111111111111111" ),
297
+ },
298
+ blockedKeys : map [string ]pcommon.Value {
299
+ "token_some" : pcommon .NewValueStr ("tokenize" ),
300
+ "api_key_some" : pcommon .NewValueStr ("apinize" ),
301
+ },
302
+ allowedValues : map [string ]pcommon.Value {
303
+ "email" :
pcommon .
NewValueStr (
"[email protected] " ),
304
+ },
305
+ }
306
+
307
+ outTraces := runTest (t , testConfig )
308
+ outLogs := runLogsTest (t , testConfig )
309
+ outMetricsGauge := runMetricsTest (t , testConfig , pmetric .MetricTypeGauge )
310
+ outMetricsSum := runMetricsTest (t , testConfig , pmetric .MetricTypeSum )
311
+ outMetricsHistogram := runMetricsTest (t , testConfig , pmetric .MetricTypeHistogram )
312
+ outMetricsExponentialHistogram := runMetricsTest (t , testConfig , pmetric .MetricTypeExponentialHistogram )
313
+ outMetricsSummary := runMetricsTest (t , testConfig , pmetric .MetricTypeSummary )
314
+
315
+ attrs := []pcommon.Map {
316
+ outTraces .ResourceSpans ().At (0 ).ScopeSpans ().At (0 ).Spans ().At (0 ).Attributes (),
317
+ outLogs .ResourceLogs ().At (0 ).ScopeLogs ().At (0 ).LogRecords ().At (0 ).Attributes (),
318
+ outMetricsGauge .ResourceMetrics ().At (0 ).ScopeMetrics ().At (0 ).Metrics ().At (0 ).Gauge ().DataPoints ().At (0 ).Attributes (),
319
+ outMetricsSum .ResourceMetrics ().At (0 ).ScopeMetrics ().At (0 ).Metrics ().At (0 ).Sum ().DataPoints ().At (0 ).Attributes (),
320
+ outMetricsHistogram .ResourceMetrics ().At (0 ).ScopeMetrics ().At (0 ).Metrics ().At (0 ).Histogram ().DataPoints ().At (0 ).Attributes (),
321
+ outMetricsExponentialHistogram .ResourceMetrics ().At (0 ).ScopeMetrics ().At (0 ).Metrics ().At (0 ).ExponentialHistogram ().DataPoints ().At (0 ).Attributes (),
322
+ outMetricsSummary .ResourceMetrics ().At (0 ).ScopeMetrics ().At (0 ).Metrics ().At (0 ).Summary ().DataPoints ().At (0 ).Attributes (),
323
+ }
324
+
325
+ for _ , attr := range attrs {
326
+ deleted := make ([]string , 0 , len (testConfig .redacted ))
327
+ for k := range testConfig .redacted {
328
+ _ , ok := attr .Get (k )
329
+ assert .False (t , ok )
330
+ deleted = append (deleted , k )
331
+ }
332
+ maskedKeys , ok := attr .Get (redactedKeys )
333
+ assert .True (t , ok )
334
+ sort .Strings (deleted )
335
+ assert .Equal (t , strings .Join (deleted , "," ), maskedKeys .Str ())
336
+ maskedKeyCount , ok := attr .Get (redactedKeyCount )
337
+ assert .True (t , ok )
338
+ assert .Equal (t , int64 (len (deleted )), maskedKeyCount .Int ())
339
+
340
+ ignoredKeyCount , ok := attr .Get (ignoredKeyCount )
341
+ assert .True (t , ok )
342
+ assert .Equal (t , int64 (len (testConfig .ignored )), ignoredKeyCount .Int ())
343
+
344
+ blockedKeys := []string {"api_key_some" , "name" , "token_some" }
345
+ maskedValues , ok := attr .Get (maskedValues )
346
+ assert .True (t , ok )
347
+ assert .Equal (t , strings .Join (blockedKeys , "," ), maskedValues .Str ())
348
+ maskedValueCount , ok := attr .Get (maskedValueCount )
349
+ assert .True (t , ok )
350
+ assert .Equal (t , int64 (3 ), maskedValueCount .Int ())
351
+ value , _ := attr .Get ("name" )
352
+ assert .Equal (t , "placeholder 5910f4ea0062a0e29afd3dccc741e3ce" , value .Str ())
353
+ value , _ = attr .Get ("api_key_some" )
354
+ assert .Equal (t , "93a699237950bde9eb9d25c7ead025f3" , value .Str ())
355
+ value , _ = attr .Get ("token_some" )
356
+ assert .Equal (t , "77e9ef3680c5518785ef0121d3884c3d" , value .Str ())
357
+ }
358
+ }
359
+
274
360
// TestRedactSummaryInfo validates that the processor writes a verbose summary
275
361
// of any attributes it deleted to the new redaction.redacted.count span
276
362
// attribute (but not to redaction.redacted.keys) when set to the info level
0 commit comments