File: header_rules_test.go

package info (click to toggle)
golang-github-aws-aws-sdk-go 1.1.14%2Bdfsg-2~bpo8%2B1
  • links: PTS, VCS
  • area: main
  • in suites: jessie-backports
  • size: 25,052 kB
  • sloc: ruby: 193; makefile: 98
file content (57 lines) | stat: -rw-r--r-- 1,078 bytes parent folder | download | duplicates (3)
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
package v4

import (
	"testing"

	"github.com/stretchr/testify/assert"
)

func TestRuleCheckWhitelist(t *testing.T) {
	w := whitelist{
		mapRule{
			"Cache-Control": struct{}{},
		},
	}

	assert.True(t, w.IsValid("Cache-Control"))
	assert.False(t, w.IsValid("Cache-"))
}

func TestRuleCheckBlacklist(t *testing.T) {
	b := blacklist{
		mapRule{
			"Cache-Control": struct{}{},
		},
	}

	assert.False(t, b.IsValid("Cache-Control"))
	assert.True(t, b.IsValid("Cache-"))
}

func TestRuleCheckPattern(t *testing.T) {
	p := patterns{"X-Amz-Meta-"}

	assert.True(t, p.IsValid("X-Amz-Meta-"))
	assert.True(t, p.IsValid("X-Amz-Meta-Star"))
	assert.False(t, p.IsValid("Cache-"))
}

func TestRuleComplexWhitelist(t *testing.T) {
	w := rules{
		whitelist{
			mapRule{
				"Cache-Control": struct{}{},
			},
		},
		patterns{"X-Amz-Meta-"},
	}

	r := rules{
		inclusiveRules{patterns{"X-Amz-"}, blacklist{w}},
	}

	assert.True(t, r.IsValid("X-Amz-Blah"))
	assert.False(t, r.IsValid("X-Amz-Meta-"))
	assert.False(t, r.IsValid("X-Amz-Meta-Star"))
	assert.False(t, r.IsValid("Cache-Control"))
}