-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathx-permitted-cross-domain-policies_test.go
61 lines (52 loc) · 2.36 KB
/
x-permitted-cross-domain-policies_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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package helmet
import "testing"
func TestXPermittedCrossDomainPolicies_String(t *testing.T) {
t.Parallel()
testCases := []struct {
name string
xPermittedCrossDomainPolicies XPermittedCrossDomainPolicies
expectedHeader string
}{
{name: "Empty", xPermittedCrossDomainPolicies: "", expectedHeader: ""},
{name: "None", xPermittedCrossDomainPolicies: PermittedCrossDomainPoliciesNone, expectedHeader: "none"},
{name: "Master Only", xPermittedCrossDomainPolicies: PermittedCrossDomainPoliciesMasterOnly, expectedHeader: "master-only"},
{name: "By Content Type", xPermittedCrossDomainPolicies: PermittedCrossDomainPoliciesByContentType, expectedHeader: "by-content-type"},
{name: "By FTP Filename", xPermittedCrossDomainPolicies: PermittedCrossDomainPoliciesByFTPFilename, expectedHeader: "by-ftp-filename"},
{name: "All", xPermittedCrossDomainPolicies: PermittedCrossDomainPoliciesAll, expectedHeader: "all"},
}
for _, tc := range testCases {
tc := tc
t.Run(tc.name, func(t *testing.T) {
t.Parallel()
header := tc.xPermittedCrossDomainPolicies.String()
if header != tc.expectedHeader {
t.Errorf("Expected: %s\tActual: %s\n", tc.expectedHeader, header)
}
})
}
}
func TestXPermittedCrossDomainPolicies_Empty(t *testing.T) {
t.Parallel()
testCases := []struct {
name string
xPermittedCrossDomainPolicies XPermittedCrossDomainPolicies
expectedEmpty bool
}{
{name: "Empty", xPermittedCrossDomainPolicies: "", expectedEmpty: true},
{name: "None", xPermittedCrossDomainPolicies: PermittedCrossDomainPoliciesNone, expectedEmpty: false},
{name: "Master Only", xPermittedCrossDomainPolicies: PermittedCrossDomainPoliciesMasterOnly, expectedEmpty: false},
{name: "By Content Type", xPermittedCrossDomainPolicies: PermittedCrossDomainPoliciesByContentType, expectedEmpty: false},
{name: "By FTP Filename", xPermittedCrossDomainPolicies: PermittedCrossDomainPoliciesByFTPFilename, expectedEmpty: false},
{name: "All", xPermittedCrossDomainPolicies: PermittedCrossDomainPoliciesAll, expectedEmpty: false},
}
for _, tc := range testCases {
tc := tc
t.Run(tc.name, func(t *testing.T) {
t.Parallel()
exists := tc.xPermittedCrossDomainPolicies.Empty()
if exists != tc.expectedEmpty {
t.Errorf("Expected: %t\tActual: %t\n", tc.expectedEmpty, exists)
}
})
}
}