@@ -306,6 +306,132 @@ func TestLoadServerLimits(t *testing.T) {
306
306
307
307
}
308
308
309
+ func TestConfigRedact(t *testing.T) {
310
+
311
+ testcases := []struct {
312
+ name string
313
+ inputCfg *Config
314
+ redactedCfg *Config
315
+ }{
316
+ {
317
+ name: "do not modify empty APM secrets",
318
+ inputCfg: &Config{
319
+ Inputs: []Input{
320
+ {
321
+ Type: "fleet-server",
322
+ Server: Server{
323
+ Instrumentation: Instrumentation{
324
+ SecretToken: "",
325
+ APIKey: "",
326
+ },
327
+ },
328
+ },
329
+ },
330
+ },
331
+ redactedCfg: &Config{
332
+ Inputs: []Input{
333
+ {
334
+ Server: Server{
335
+ Instrumentation: Instrumentation{
336
+ SecretToken: "",
337
+ APIKey: "",
338
+ },
339
+ },
340
+ },
341
+ },
342
+ },
343
+ },
344
+ {
345
+ name: "redact APM secret token",
346
+ inputCfg: &Config{
347
+ Inputs: []Input{
348
+ {
349
+ Type: "fleet-server",
350
+ Server: Server{
351
+ Instrumentation: Instrumentation{
352
+ SecretToken: "secret value that noone should know",
353
+ },
354
+ },
355
+ },
356
+ },
357
+ },
358
+ redactedCfg: &Config{
359
+ Inputs: []Input{
360
+ {
361
+ Server: Server{
362
+ Instrumentation: Instrumentation{
363
+ SecretToken: kRedacted,
364
+ },
365
+ },
366
+ },
367
+ },
368
+ },
369
+ },
370
+ {
371
+ name: "redact APM API key",
372
+ inputCfg: &Config{
373
+ Inputs: []Input{
374
+ {
375
+ Type: "fleet-server",
376
+ Server: Server{
377
+ Instrumentation: Instrumentation{
378
+ APIKey: "secret value that noone should know",
379
+ },
380
+ },
381
+ },
382
+ },
383
+ },
384
+ redactedCfg: &Config{
385
+ Inputs: []Input{
386
+ {
387
+ Server: Server{
388
+ Instrumentation: Instrumentation{
389
+ APIKey: kRedacted,
390
+ },
391
+ },
392
+ },
393
+ },
394
+ },
395
+ },
396
+ {
397
+ name: "redact both APM API key and secret token",
398
+ inputCfg: &Config{
399
+ Inputs: []Input{
400
+ {
401
+ Type: "fleet-server",
402
+ Server: Server{
403
+ Instrumentation: Instrumentation{
404
+ APIKey: "secret value that noone should know",
405
+ SecretToken: "another value that noone should know",
406
+ },
407
+ },
408
+ },
409
+ },
410
+ },
411
+ redactedCfg: &Config{
412
+ Inputs: []Input{
413
+ {
414
+ Server: Server{
415
+ Instrumentation: Instrumentation{
416
+ APIKey: kRedacted,
417
+ SecretToken: kRedacted,
418
+ },
419
+ },
420
+ },
421
+ },
422
+ },
423
+ },
424
+ }
425
+
426
+ for _, tt := range testcases {
427
+ t.Run(tt.name, func(t *testing.T) {
428
+ require.NotNil(t, tt.inputCfg, "input config cannot be nil")
429
+ actualRedacted := tt.inputCfg.Redact()
430
+ assert.Equal(t, tt.redactedCfg, actualRedacted)
431
+ })
432
+ }
433
+ }
434
+
309
435
// Stub out the defaults so that the above is easier to maintain
310
436
311
437
func defaultCache() Cache {
0 commit comments