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 64 65 66 67 68 69 70 71 72 73 74 75 76 77
|
package v4
import (
"testing"
)
func TestRuleCheckWhitelist(t *testing.T) {
w := allowList{
mapRule{
"Cache-Control": struct{}{},
},
}
if !w.IsValid("Cache-Control") {
t.Error("expected true value")
}
if w.IsValid("Cache-") {
t.Error("expected false value")
}
}
func TestRuleCheckBlacklist(t *testing.T) {
b := excludeList{
mapRule{
"Cache-Control": struct{}{},
},
}
if b.IsValid("Cache-Control") {
t.Error("expected false value")
}
if !b.IsValid("Cache-") {
t.Error("expected true value")
}
}
func TestRuleCheckPattern(t *testing.T) {
p := patterns{"X-Amz-Meta-"}
if !p.IsValid("X-Amz-Meta-") {
t.Error("expected true value")
}
if !p.IsValid("X-Amz-Meta-Star") {
t.Error("expected true value")
}
if p.IsValid("Cache-") {
t.Error("expected false value")
}
}
func TestRuleComplexWhitelist(t *testing.T) {
w := rules{
allowList{
mapRule{
"Cache-Control": struct{}{},
},
},
patterns{"X-Amz-Meta-"},
}
r := rules{
inclusiveRules{patterns{"X-Amz-"}, excludeList{w}},
}
if !r.IsValid("X-Amz-Blah") {
t.Error("expected true value")
}
if r.IsValid("X-Amz-Meta-") {
t.Error("expected false value")
}
if r.IsValid("X-Amz-Meta-Star") {
t.Error("expected false value")
}
if r.IsValid("Cache-Control") {
t.Error("expected false value")
}
}
|