diff options
author | Kévin Dunglas <dunglas@gmail.com> | 2021-11-23 17:40:20 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-11-23 09:40:20 -0700 |
commit | 8887adb027982e844965b4707b8595cee5845d54 (patch) | |
tree | 00c61101dae9d248356512beed7b149000c25986 /modules/logging/filters_test.go | |
parent | bcac2beee7e419f8cdab2ed16f388d1af282a46b (diff) |
logging: add a filter for cookies (#4425)
* feat(logging): add a filter for cookies
* Improve godoc and add validation
Diffstat (limited to 'modules/logging/filters_test.go')
-rw-r--r-- | modules/logging/filters_test.go | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/modules/logging/filters_test.go b/modules/logging/filters_test.go index 883a138..6871bea 100644 --- a/modules/logging/filters_test.go +++ b/modules/logging/filters_test.go @@ -39,3 +39,31 @@ func TestValidateQueryFilter(t *testing.T) { t.Fatalf("unknown action type must be invalid") } } + +func TestCookieFilter(t *testing.T) { + f := CookieFilter{[]cookieFilterAction{ + {replaceAction, "foo", "REDACTED"}, + {deleteAction, "bar", ""}, + }} + + out := f.Filter(zapcore.Field{String: "foo=a; foo=b; bar=c; bar=d; baz=e"}) + if out.String != "foo=REDACTED; foo=REDACTED; baz=e" { + t.Fatalf("cookies have not been filtered: %s", out.String) + } +} + +func TestValidateCookieFilter(t *testing.T) { + f := CookieFilter{[]cookieFilterAction{ + {}, + }} + if f.Validate() == nil { + t.Fatalf("empty action type must be invalid") + } + + f = CookieFilter{[]cookieFilterAction{ + {Type: "foo"}, + }} + if f.Validate() == nil { + t.Fatalf("unknown action type must be invalid") + } +} |