forked from justinas/nosurf
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathignore_test.go
45 lines (36 loc) · 1017 Bytes
/
ignore_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
package nosurf
import (
"net/http"
"testing"
)
func TestIgnorePath(t *testing.T) {
// the handler doesn't matter here, let's use nil
hand := New(nil)
path := "/home"
exempt, _ := http.NewRequest("GET", path, nil)
hand.IgnorePath(path)
if !hand.IsIgnored(exempt) {
t.Errorf("%v is not exempt, but it should be", exempt.URL.Path)
}
other, _ := http.NewRequest("GET", "/faq", nil)
if hand.IsIgnored(other) {
t.Errorf("%v is exempt, but it shouldn't be", other.URL.Path)
}
}
func TestIgnoreGlob(t *testing.T) {
hand := New(nil)
glob := "/nail/*"
hand.IgnoreGlob(glob)
test, _ := http.NewRequest("GET", "/nail/foo", nil)
if !hand.IsIgnored(test) {
t.Errorf("%v should be exempt, but it isn't.", test)
}
test, _ = http.NewRequest("GET", "/nail/foo/bar", nil)
if hand.IsIgnored(test) {
t.Errorf("%v should not be exempt, but it is.", test)
}
test, _ = http.NewRequest("GET", "/not-nail/foo", nil)
if hand.IsIgnored(test) {
t.Errorf("%v should not be exempt, but it is.", test)
}
}