-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrules_test.go
More file actions
40 lines (34 loc) · 974 Bytes
/
Copy pathrules_test.go
File metadata and controls
40 lines (34 loc) · 974 Bytes
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
package xssvalidator
import (
"errors"
"testing"
)
func TestBracketRule_Check(t *testing.T) {
b := BracketRule{}
err := b.Check("[A] this (is) a {song} [D] [Am] i am [Adim] Am [f] [Dmin] ()")
if !errors.Is(err, ErrBracketRule) {
t.Errorf("Error should be %s, instead of %s", ErrBracketRule, err)
}
err = b.Check("TestData")
if err != nil {
t.Errorf("Error should be nil, instead of %s", err)
}
}
func TestForbiddenKeywords_Check(t *testing.T) {
f := ForbiddenKeywords{}
err := f.Check("<script> alert(123) </script>")
if !errors.Is(err, ErrForbiddenKeywords) {
t.Errorf("Error should be %s, instead of %s", ErrForbiddenKeywords, err)
}
err = f.Check("alert prompt is my name")
if err != nil {
t.Errorf("Error should be nil, instead of %s", err)
}
}
func BenchmarkBracketRule_Check(b *testing.B) {
br := BracketRule{}
b.ReportAllocs()
for i := 0; i < b.N; i++ {
br.Check("[A] this (is) a {song} [D] [Am] i am [Adim] Am [f] [Dmin] ()")
}
}