Skip to content

Commit 03b6346

Browse files
committed
Update FuzzConfig to use constructed arguments
Rather than generating hundreds of un-used malformed configs, build the arguments from the component parts, fuzzing each part separately.
1 parent 68f6057 commit 03b6346

File tree

1 file changed

+12
-15
lines changed

1 file changed

+12
-15
lines changed

internal/component/loki/secretfilter/secretfilter_test.go

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -647,10 +647,9 @@ func FuzzProcessEntry(f *testing.F) {
647647
}
648648

649649
func FuzzConfig(f *testing.F) {
650-
for _, testConf := range testConfigs {
651-
for _, testLog := range testLogs {
652-
f.Add(testConf, testLog.log)
653-
}
650+
for _, testLog := range testLogs {
651+
f.Add("", false, uint(0), "", "", testLog.log) // zero values
652+
f.Add("REDACTED", true, uint(4), "aws,gcp", "abc.*&.*foobar.*", testLog.log) // sane values
654653
}
655654
opts := component.Options{
656655
Logger: util.TestLogger(f),
@@ -659,18 +658,16 @@ func FuzzConfig(f *testing.F) {
659658
}
660659
ch1 := loki.NewLogsReceiver()
661660

662-
f.Fuzz(func(t *testing.T, config string, log string) {
663-
var args Arguments
664-
err := syntax.Unmarshal([]byte(config), &args)
665-
if err != nil {
666-
// ignore parsing errors, as we aren't fuzz testing the Alloy config parser
667-
return
668-
}
669-
if args.GitleaksConfig != "" {
670-
return // Skip the configs that use a custom gitleaks config file
661+
f.Fuzz(func(t *testing.T, redact string, generic bool, partial uint, types string, allow string, log string) {
662+
args := Arguments{
663+
ForwardTo: []loki.LogsReceiver{ch1}, // not fuzzed
664+
Types: strings.Split(types, ","),
665+
RedactWith: redact,
666+
IncludeGeneric: generic,
667+
AllowList: strings.Split(allow, "&"), // a character that has no special meaning in go regexp and doesn't appear in the gitleaks regexes
668+
PartialMask: partial,
669+
GitleaksConfig: "", // not fuzzed in this test
671670
}
672-
673-
args.ForwardTo = []loki.LogsReceiver{ch1}
674671
c, err := New(opts, args)
675672
if err != nil {
676673
// ignore regex parsing errors

0 commit comments

Comments
 (0)