-
Notifications
You must be signed in to change notification settings - Fork 107
/
Copy pathanalyzer_test.go
63 lines (51 loc) · 1.29 KB
/
analyzer_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
package jsluice
import "testing"
func TestAnalyzerBasicURLs(t *testing.T) {
a := NewAnalyzer([]byte(`
function foo(){
document.location = "/logout"
}
`))
urls := a.GetURLs()
if len(urls) < 1 {
t.Errorf("Expected at least 1 URL; got %d", len(urls))
}
if urls[0].URL != "/logout" {
t.Errorf("Expected first URL to be '/logout'; got %s", urls[0].URL)
}
}
func TestAnalyzerBasicSecrets(t *testing.T) {
a := NewAnalyzer([]byte(`
function foo(){
return {
awsKey: "AKIAIOSFODNN7EXAMPLE",
secret: "wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY"
}
}
`))
secrets := a.GetSecrets()
if len(secrets) != 1 {
t.Errorf("Expected exactly 1 secret; got %d", len(secrets))
}
if secrets[0].Kind != "AWSAccessKey" {
t.Errorf("Expected first secret kind to be AWSAccessKey; got %s", secrets[0].Kind)
}
}
func TestIsProbablyHTML(t *testing.T) {
cases := []struct {
in []byte
expected bool
}{
{[]byte("var foo = bar"), false},
{[]byte(" \t\nvar foo = bar"), false},
{[]byte("lol this isn't even JavaScript"), false},
{[]byte("<!doctype html><html>"), true},
{[]byte(" \t\n<div><p>"), true},
}
for _, c := range cases {
actual := isProbablyHTML(c.in)
if actual != c.expected {
t.Errorf("want %t for isProbablyHTML(%q); have %t", c.expected, c.in, actual)
}
}
}