-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathxss_test.go
49 lines (45 loc) · 1.14 KB
/
xss_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
package libinjection
import (
"testing"
)
var xssExamples = []string{
"<script>alert(1);</script>",
"><script>alert(1);</script>",
"x ><script>alert(1);</script>",
"' ><script>alert(1);</script>",
"\"><script>alert(1);</script>",
"red;</style><script>alert(1);</script>",
"red;}</style><script>alert(1);</script>",
"red;\"/><script>alert(1);</script>",
"');}</style><script>alert(1);</script>",
"onerror=alert(1)>",
"x onerror=alert(1);>",
"x' onerror=alert(1);>",
"x\" onerror=alert(1);>",
"<a href=\"javascript:alert(1)\">",
"<a href='javascript:alert(1)'>",
"<a href=javascript:alert(1)>",
"<a href = javascript:alert(1); >",
"<a href=\" javascript:alert(1);\" >",
"<a href=\"JAVASCRIPT:alert(1);\" >",
}
func TestIsXSS(t *testing.T) {
for _, example := range xssExamples {
t.Run(example, func(t *testing.T) {
if !IsXSS(example) {
t.Errorf("[%s] is not XSS", example)
}
})
}
}
func BenchmarkIsXSS(b *testing.B) {
for _, example := range xssExamples {
b.Run(example, func(b *testing.B) {
for i := 0; i < b.N; i++ {
if !IsXSSBenchmark(example) {
b.Errorf("[%s] is not XSS", example)
}
}
})
}
}