forked from hashicorp/go-getter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
url_test.go
95 lines (92 loc) · 1.92 KB
/
url_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
package getter
import (
"net/url"
"testing"
)
func TestRedactURL(t *testing.T) {
cases := []struct {
name string
url *url.URL
want string
}{
{
name: "non-blank Password",
url: &url.URL{
Scheme: "http",
Host: "host.tld",
Path: "this:that",
User: url.UserPassword("user", "password"),
},
want: "http://user:[email protected]/this:that",
},
{
name: "blank Password",
url: &url.URL{
Scheme: "http",
Host: "host.tld",
Path: "this:that",
User: url.User("user"),
},
want: "http://[email protected]/this:that",
},
{
name: "nil User",
url: &url.URL{
Scheme: "http",
Host: "host.tld",
Path: "this:that",
User: url.UserPassword("", "password"),
},
want: "http://:[email protected]/this:that",
},
{
name: "blank Username, blank Password",
url: &url.URL{
Scheme: "http",
Host: "host.tld",
Path: "this:that",
},
want: "http://host.tld/this:that",
},
{
name: "empty URL",
url: &url.URL{},
want: "",
},
{
name: "nil URL",
url: nil,
want: "",
},
{
name: "non-blank SSH key in URL query parameter",
url: &url.URL{
Scheme: "ssh",
User: url.User("git"),
Host: "github.com",
Path: "hashicorp/go-getter-test-private.git",
RawQuery: "sshkey=LS0tLS1CRUdJTiBPUE",
},
want: "ssh://[email protected]/hashicorp/go-getter-test-private.git?sshkey=redacted",
},
{
name: "blank SSH key in URL query parameter",
url: &url.URL{
Scheme: "ssh",
User: url.User("git"),
Host: "github.com",
Path: "hashicorp/go-getter-test-private.git",
RawQuery: "sshkey=",
},
want: "ssh://[email protected]/hashicorp/go-getter-test-private.git?sshkey=",
},
}
for _, tt := range cases {
t := t
t.Run(tt.name, func(t *testing.T) {
if g, w := RedactURL(tt.url), tt.want; g != w {
t.Fatalf("got: %q\nwant: %q", g, w)
}
})
}
}