Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
gitpod-io
GitHub Repository: gitpod-io/gitpod
Path: blob/main/components/scrubber/example_test.go
2492 views
1
// Copyright (c) 2023 Gitpod GmbH. All rights reserved.
2
// Licensed under the GNU Affero General Public License (AGPL).
3
// See License.AGPL.txt in the project root for license information.
4
5
package scrubber
6
7
import (
8
"encoding/json"
9
"testing"
10
)
11
12
func TestScrub(t *testing.T) {
13
14
scrubber := Default
15
16
// log.WithFieldSensitive("workspaceID", "gitpodio-gitpod-uesaddev73c").Info("hello world")
17
scrubber.KeyValue("workspaceID", "gitpodio-gitpod-uesaddev73c") // -> [scrubbed:md5:ae3e415b124cdbac878e995cad169490]
18
19
var someJSONData = json.RawMessage(`{"email": "[email protected]", "username": "foobar", "orgID": "112233", "desc": "the email is [email protected]"}`)
20
scrubber.JSON(someJSONData) // -> `{"email": "[scrubbed:md5:e2e6d7a977f2ca2b3900e22c68655b30]", "username": "[scrubbed:md5:14758f1afd44c09b7992073ccf00b43d]", "orgID": "[scrubbed:md5:cc9d7e078ba46da002aba1cf665b0acf]", "desc": "the email is [scrubbed:email]"}`
21
22
var user = User{
23
Username: "foobar",
24
Email: "[email protected]",
25
AuthToken: "112233",
26
}
27
scrubber.Struct(&user) // -> {Username: "[scrubbed:md5:14758f1afd44c09b7992073ccf00b43d]", Email: "[scrubbed:md5:e2e6d7a977f2ca2b3900e22c68655b30]", AuthToken: "[scrubbed]"}
28
29
scrubber.Value("this may be an email: [email protected]") // -> "this may be an email: [scrubbed:md5:e2e6d7a977f2ca2b3900e22c68655b30:email]"
30
}
31
32
type User struct {
33
Username string
34
Email string
35
AuthToken string `scrub:"redact"`
36
}
37
38