diff options
author | Kévin Dunglas <dunglas@gmail.com> | 2021-11-23 10:01:43 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-11-23 04:01:43 -0500 |
commit | bcac2beee7e419f8cdab2ed16f388d1af282a46b (patch) | |
tree | c8f3ca5424b3648cbfff4bd12f3d41ba77b70879 /modules/logging/filters_test.go | |
parent | 1e10f6f725189a371a923a329084f1c3f608ae38 (diff) |
logging: add a filter for query parameters (#4424)
Co-authored-by: Matt Holt <mholt@users.noreply.github.com>
Co-authored-by: Francis Lavoie <lavofr@gmail.com>
Diffstat (limited to 'modules/logging/filters_test.go')
-rw-r--r-- | modules/logging/filters_test.go | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/modules/logging/filters_test.go b/modules/logging/filters_test.go new file mode 100644 index 0000000..883a138 --- /dev/null +++ b/modules/logging/filters_test.go @@ -0,0 +1,41 @@ +package logging + +import ( + "testing" + + "go.uber.org/zap/zapcore" +) + +func TestQueryFilter(t *testing.T) { + f := QueryFilter{[]queryFilterAction{ + {replaceAction, "foo", "REDACTED"}, + {replaceAction, "notexist", "REDACTED"}, + {deleteAction, "bar", ""}, + {deleteAction, "notexist", ""}, + }} + + if f.Validate() != nil { + t.Fatalf("the filter must be valid") + } + + out := f.Filter(zapcore.Field{String: "/path?foo=a&foo=b&bar=c&bar=d&baz=e"}) + if out.String != "/path?baz=e&foo=REDACTED&foo=REDACTED" { + t.Fatalf("query parameters have not been filtered: %s", out.String) + } +} + +func TestValidateQueryFilter(t *testing.T) { + f := QueryFilter{[]queryFilterAction{ + {}, + }} + if f.Validate() == nil { + t.Fatalf("empty action type must be invalid") + } + + f = QueryFilter{[]queryFilterAction{ + {Type: "foo"}, + }} + if f.Validate() == nil { + t.Fatalf("unknown action type must be invalid") + } +} |