Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
gitpod-io
GitHub Repository: gitpod-io/gitpod
Path: blob/main/components/scrubber/sanitisation_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
"testing"
9
10
"github.com/google/go-cmp/cmp"
11
)
12
13
func TestSanitiser(t *testing.T) {
14
tests := []struct {
15
Name string
16
Func Sanitisatiser
17
Opts []SanitiserOption
18
Expectation string
19
Input string
20
}{
21
{Func: SanitiseRedact, Name: "redact empty string", Expectation: "[redacted]"},
22
{Func: SanitiseRedact, Name: "redact sensitive string", Input: "[email protected]", Expectation: "[redacted]"},
23
{Func: SanitiseRedact, Name: "redact key name", Opts: []SanitiserOption{SanitiseWithKeyName("foo")}, Input: "[email protected]", Expectation: "[redacted:foo]"},
24
{Func: SanitiseHash, Name: "hash empty string", Expectation: "[redacted:md5:d41d8cd98f00b204e9800998ecf8427e]"},
25
{Func: SanitiseHash, Name: "hash sensitive string", Input: "[email protected]", Expectation: "[redacted:md5:f3ada405ce890b6f8204094deb12d8a8]"},
26
{Func: SanitiseHash, Name: "hash key name", Opts: []SanitiserOption{SanitiseWithKeyName("foo")}, Input: "[email protected]", Expectation: "[redacted:md5:f3ada405ce890b6f8204094deb12d8a8:foo]"},
27
{Func: SanitiseHashURLPathSegments, Name: "hash contextURL", Input: "https://github.com/gitpod-io/gitpod/pull/19402", Expectation: "[redacted:md5:3097fca9b1ec8942c4305e550ef1b50a]/[redacted:md5:308cb0f82b8a4966a32f7c360315c160]/[redacted:md5:5bc8d0354fba47db774b70d2a9161bbb]/pull/19402"},
28
{Func: SanitiseHashURLPathSegments, Name: "hash contextURL with query", Input: "https://github.com/gitpod-io/gitpod/pull/19402?foo=bar&foo=baz", Expectation: "[redacted:md5:3097fca9b1ec8942c4305e550ef1b50a]/[redacted:md5:308cb0f82b8a4966a32f7c360315c160]/[redacted:md5:5bc8d0354fba47db774b70d2a9161bbb]/pull/19402?[redacted:md5:d76c5fb536a9f4866aed3c0d7a0d0f76]"},
29
{Func: SanitiseHashURLPathSegments, Name: "hash contextURL with BBS user repo", Input: "https://bitbucket.gitpod-dev.com/users/gitpod/repos/repotest/browse", Expectation: "[redacted:md5:454c2006e527428ce0fbb2222edfb5c5]/users/[redacted:md5:5bc8d0354fba47db774b70d2a9161bbb]/repos/[redacted:md5:3c3f61c49fd93e84a73e33f6194586cd]/browse"},
30
{Func: SanitiseHashURLPathSegments, Name: "hash contextURL with BBS project PR", Input: "https://bitbucket.gitpod-dev.com/projects/TES/repos/2k-repos-0/pull-requests/1/overview", Expectation: "[redacted:md5:454c2006e527428ce0fbb2222edfb5c5]/projects/[redacted:md5:08e789053de980e0f1ac70a61125a17d]/repos/[redacted:md5:14571b57e21a5c26b9e81fe6216e27d1]/pull-requests/1/[redacted:md5:bce059749d61c1c247c303d0118d0d53]"},
31
{Func: SanitiseHashURLPathSegments, Name: "hash contextURL with BBS branch", Input: "https://bitbucket.gitpod-dev.com/projects/TES/repos/2k-repos-0/branches?base=test", Expectation: "[redacted:md5:454c2006e527428ce0fbb2222edfb5c5]/projects/[redacted:md5:08e789053de980e0f1ac70a61125a17d]/repos/[redacted:md5:14571b57e21a5c26b9e81fe6216e27d1]/branches?[redacted:md5:0135e6beb2a6deb4f0668facc47bce76]"},
32
{Func: SanitiseHashURLPathSegments, Name: "GitLab Git URL", Input: "https://gitlab.com/acme-corp/web/frontend/services/deployment-manager.git", Expectation: "[redacted:md5:8c3e227c86409b1e3e734e711a77fd6c]/[redacted:md5:7c879ad6a7611d94b34c1911910257c9]/[redacted:md5:2567a5ec9705eb7ac2c984033e06189d]/[redacted:md5:aca33b9c046b2a50b8c3c54cc0380de8]/[redacted:md5:10cd395cf71c18328c863c08e78f3fd0]/[redacted:md5:d890bc8f5f32a034527f9be94624af58]"},
33
}
34
35
for _, test := range tests {
36
t.Run(test.Name, func(t *testing.T) {
37
act := test.Func(test.Input, test.Opts...)
38
39
if diff := cmp.Diff(test.Expectation, act); diff != "" {
40
t.Errorf("act: %s", act)
41
t.Errorf("sanitiser mismatch (-want +got):\n%s", diff)
42
}
43
})
44
}
45
}
46
47