diff options
author | Kévin Dunglas <dunglas@gmail.com> | 2021-12-02 21:51:37 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-12-02 13:51:37 -0700 |
commit | a1b417c832b4ab3dab9eaa9690e1d07672a949b8 (patch) | |
tree | 24323a894ac9b8b59c9701887e324fa81d5c2caa /modules/logging/filters_test.go | |
parent | 5bf0adad8748e96e10529d5fc5777afc9236a7b5 (diff) |
logging: add support for hashing data (#4434)
* logging: add support for hashing data
* Update modules/logging/filters.go
Co-authored-by: wiese <wiese@users.noreply.github.com>
* Update modules/logging/filters.go
Co-authored-by: wiese <wiese@users.noreply.github.com>
Co-authored-by: wiese <wiese@users.noreply.github.com>
Diffstat (limited to 'modules/logging/filters_test.go')
-rw-r--r-- | modules/logging/filters_test.go | 19 |
1 files changed, 15 insertions, 4 deletions
diff --git a/modules/logging/filters_test.go b/modules/logging/filters_test.go index 99289c3..ecf1d87 100644 --- a/modules/logging/filters_test.go +++ b/modules/logging/filters_test.go @@ -13,14 +13,15 @@ func TestQueryFilter(t *testing.T) { {replaceAction, "notexist", "REDACTED"}, {deleteAction, "bar", ""}, {deleteAction, "notexist", ""}, + {hashAction, "hash", ""}, }} 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" { + out := f.Filter(zapcore.Field{String: "/path?foo=a&foo=b&bar=c&bar=d&baz=e&hash=hashed"}) + if out.String != "/path?baz=e&foo=REDACTED&foo=REDACTED&hash=e3b0c442" { t.Fatalf("query parameters have not been filtered: %s", out.String) } } @@ -45,10 +46,11 @@ func TestCookieFilter(t *testing.T) { f := CookieFilter{[]cookieFilterAction{ {replaceAction, "foo", "REDACTED"}, {deleteAction, "bar", ""}, + {hashAction, "hash", ""}, }} - 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" { + out := f.Filter(zapcore.Field{String: "foo=a; foo=b; bar=c; bar=d; baz=e; hash=hashed"}) + if out.String != "foo=REDACTED; foo=REDACTED; baz=e; hash=1a06df82" { t.Fatalf("cookies have not been filtered: %s", out.String) } } @@ -78,3 +80,12 @@ func TestRegexpFilter(t *testing.T) { t.Fatalf("field has not been filtered: %s", out.String) } } + +func TestHashFilter(t *testing.T) { + f := HashFilter{} + + out := f.Filter(zapcore.Field{String: "foo"}) + if out.String != "2c26b46b" { + t.Fatalf("field has not been filtered: %s", out.String) + } +} |