-
Notifications
You must be signed in to change notification settings - Fork 3
/
x-frame-options_test.go
55 lines (46 loc) · 1.3 KB
/
x-frame-options_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
package helmet
import "testing"
func TestXFrameOptions_String(t *testing.T) {
t.Parallel()
testCases := []struct {
name string
xFrameOptions XFrameOptions
expectedHeader string
}{
{name: "Empty", xFrameOptions: "", expectedHeader: ""},
{name: "None", xFrameOptions: XFrameOptionsDeny, expectedHeader: "DENY"},
{name: "Master Only", xFrameOptions: XFrameOptionsSameOrigin, expectedHeader: "SAMEORIGIN"},
}
for _, tc := range testCases {
tc := tc
t.Run(tc.name, func(t *testing.T) {
t.Parallel()
header := tc.xFrameOptions.String()
if header != tc.expectedHeader {
t.Errorf("Expected: %s\tActual: %s\n", tc.expectedHeader, header)
}
})
}
}
func TestFrameOptions_Empty(t *testing.T) {
t.Parallel()
testCases := []struct {
name string
xFrameOptions XFrameOptions
expectedEmpty bool
}{
{name: "Empty", xFrameOptions: "", expectedEmpty: true},
{name: "Deny", xFrameOptions: XFrameOptionsDeny, expectedEmpty: false},
{name: "Same Origin", xFrameOptions: XFrameOptionsSameOrigin, expectedEmpty: false},
}
for _, tc := range testCases {
tc := tc
t.Run(tc.name, func(t *testing.T) {
t.Parallel()
exists := tc.xFrameOptions.Empty()
if exists != tc.expectedEmpty {
t.Errorf("Expected: %t\tActual: %t\n", tc.expectedEmpty, exists)
}
})
}
}