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
|
package cmd
import (
"strings"
"testing"
)
// redact must not reveal any secret material — only the non-secret prefix that
// identifies the credential type.
func TestRedactRevealsNoSecretMaterial(t *testing.T) {
const secret = "rickub_pat_S3CRETMATERIAL"
got := redact(secret)
if got != "rickub_pat_…" {
t.Errorf("redact = %q, want %q", got, "rickub_pat_…")
}
if rest := strings.TrimPrefix(secret, tokenPrefix); strings.Contains(got, rest[:1]) {
t.Errorf("redact leaked secret material: %q", got)
}
if got := redact("short"); got != "****" {
t.Errorf("redact(non-PAT) = %q, want ****", got)
}
if got := redact(""); got != "****" {
t.Errorf("redact(empty) = %q, want ****", got)
}
}
// A URL handed to the platform opener must be a plain web address: the opener
// launches whatever handler is registered for a scheme.
func TestCheckBrowserURLRejectsNonWebSchemes(t *testing.T) {
ok := []string{
"https://rickub.com/login/device?code=ABCD",
"http://localhost:3000/login/device",
}
for _, u := range ok {
if err := checkBrowserURL(u); err != nil {
t.Errorf("checkBrowserURL(%q) = %v, want nil", u, err)
}
}
bad := []string{
"file:///etc/passwd",
"javascript:alert(1)",
"data:text/html,<script>alert(1)</script>",
"ssh://evil.example/x",
"vscode://evil",
"/login/device",
"https://",
"",
"ht tp://bad",
}
for _, u := range bad {
if err := checkBrowserURL(u); err == nil {
t.Errorf("checkBrowserURL(%q) = nil, want an error", u)
}
}
}
|