| 1 |
package v4 |
| 2 |
|
| 3 |
import ( |
| 4 |
"testing" |
| 5 |
) |
| 6 |
|
| 7 |
func TestRuleCheckWhitelist(t *testing.T) { |
| 8 |
w := allowList{ |
| 9 |
mapRule{ |
| 10 |
"Cache-Control": struct{}{}, |
| 11 |
}, |
| 12 |
} |
| 13 |
|
| 14 |
if !w.IsValid("Cache-Control") { |
| 15 |
t.Error("expected true value") |
| 16 |
} |
| 17 |
if w.IsValid("Cache-") { |
| 18 |
t.Error("expected false value") |
| 19 |
} |
| 20 |
} |
| 21 |
|
| 22 |
func TestRuleCheckBlacklist(t *testing.T) { |
| 23 |
b := excludeList{ |
| 24 |
mapRule{ |
| 25 |
"Cache-Control": struct{}{}, |
| 26 |
}, |
| 27 |
} |
| 28 |
|
| 29 |
if b.IsValid("Cache-Control") { |
| 30 |
t.Error("expected false value") |
| 31 |
} |
| 32 |
if !b.IsValid("Cache-") { |
| 33 |
t.Error("expected true value") |
| 34 |
} |
| 35 |
} |
| 36 |
|
| 37 |
func TestRuleCheckPattern(t *testing.T) { |
| 38 |
p := patterns{"X-Amz-Meta-"} |
| 39 |
|
| 40 |
if !p.IsValid("X-Amz-Meta-") { |
| 41 |
t.Error("expected true value") |
| 42 |
} |
| 43 |
if !p.IsValid("X-Amz-Meta-Star") { |
| 44 |
t.Error("expected true value") |
| 45 |
} |
| 46 |
if p.IsValid("Cache-") { |
| 47 |
t.Error("expected false value") |
| 48 |
} |
| 49 |
} |
| 50 |
|
| 51 |
func TestRuleComplexWhitelist(t *testing.T) { |
| 52 |
w := rules{ |
| 53 |
allowList{ |
| 54 |
mapRule{ |
| 55 |
"Cache-Control": struct{}{}, |
| 56 |
}, |
| 57 |
}, |
| 58 |
patterns{"X-Amz-Meta-"}, |
| 59 |
} |
| 60 |
|
| 61 |
r := rules{ |
| 62 |
inclusiveRules{patterns{"X-Amz-"}, excludeList{w}}, |
| 63 |
} |
| 64 |
|
| 65 |
if !r.IsValid("X-Amz-Blah") { |
| 66 |
t.Error("expected true value") |
| 67 |
} |
| 68 |
if r.IsValid("X-Amz-Meta-") { |
| 69 |
t.Error("expected false value") |
| 70 |
} |
| 71 |
if r.IsValid("X-Amz-Meta-Star") { |
| 72 |
t.Error("expected false value") |
| 73 |
} |
| 74 |
if r.IsValid("Cache-Control") { |
| 75 |
t.Error("expected false value") |
| 76 |
} |
| 77 |
} |