-
Notifications
You must be signed in to change notification settings - Fork 0
/
test1_test.go
180 lines (154 loc) · 7.2 KB
/
test1_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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
package binarycookies
import (
"bytes"
"testing"
)
var _test1 = []byte{
0x63, 0x6f, 0x6f, 0x6b, 0x00, 0x00, 0x00, 0x0b, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x01, 0x92,
0x00, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x0c,
0x00, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x0c,
0x00, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x01, 0x00, 0x04, 0x00, 0x00, 0x00, 0x1c, 0x00, 0x00, 0x00, 0x79, 0x00, 0x00, 0x00,
0xdc, 0x00, 0x00, 0x00, 0x37, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x5d, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x38, 0x00, 0x00, 0x00,
0x4c, 0x00, 0x00, 0x00, 0x55, 0x00, 0x00, 0x00, 0x57, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x67, 0x74, 0x83, 0xbb, 0x41, 0x00, 0x00, 0x00, 0xe7,
0x22, 0x82, 0xbb, 0x41, 0x75, 0x72, 0x6c, 0x65, 0x63, 0x68, 0x6f, 0x2e, 0x61, 0x70, 0x70, 0x73,
0x70, 0x6f, 0x74, 0x2e, 0x63, 0x6f, 0x6d, 0x00, 0x68, 0x74, 0x74, 0x70, 0x4f, 0x6e, 0x6c, 0x79,
0x00, 0x2f, 0x00, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x00, 0x63, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x38, 0x00, 0x00, 0x00, 0x4c, 0x00, 0x00,
0x00, 0x5b, 0x00, 0x00, 0x00, 0x5d, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x67, 0x74, 0x83, 0xbb, 0x41, 0x00, 0x00, 0x00, 0xe7, 0x22, 0x82, 0xbb,
0x41, 0x75, 0x72, 0x6c, 0x65, 0x63, 0x68, 0x6f, 0x2e, 0x61, 0x70, 0x70, 0x73, 0x70, 0x6f, 0x74,
0x2e, 0x63, 0x6f, 0x6d, 0x00, 0x68, 0x74, 0x74, 0x70, 0x4f, 0x6e, 0x6c, 0x79, 0x53, 0x65, 0x63,
0x75, 0x72, 0x65, 0x00, 0x2f, 0x00, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x00, 0x5b, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x38, 0x00, 0x00, 0x00,
0x4c, 0x00, 0x00, 0x00, 0x53, 0x00, 0x00, 0x00, 0x55, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x67, 0x74, 0x83, 0xbb, 0x41, 0x00, 0x00, 0x00, 0xe7,
0x22, 0x82, 0xbb, 0x41, 0x75, 0x72, 0x6c, 0x65, 0x63, 0x68, 0x6f, 0x2e, 0x61, 0x70, 0x70, 0x73,
0x70, 0x6f, 0x74, 0x2e, 0x63, 0x6f, 0x6d, 0x00, 0x6e, 0x6f, 0x72, 0x6d, 0x61, 0x6c, 0x00, 0x2f,
0x00, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x00, 0x5b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x38, 0x00, 0x00, 0x00, 0x4c, 0x00, 0x00, 0x00, 0x53,
0x00, 0x00, 0x00, 0x55, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x67, 0x74, 0x83, 0xbb, 0x41, 0x00, 0x00, 0x00, 0xe7, 0x22, 0x82, 0xbb, 0x41, 0x75,
0x72, 0x6c, 0x65, 0x63, 0x68, 0x6f, 0x2e, 0x61, 0x70, 0x70, 0x73, 0x70, 0x6f, 0x74, 0x2e, 0x63,
0x6f, 0x6d, 0x00, 0x73, 0x65, 0x63, 0x75, 0x72, 0x65, 0x00, 0x2f, 0x00, 0x76, 0x61, 0x6c, 0x75,
0x65, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x16, 0x33, 0x07, 0x17, 0x20, 0x05, 0x00, 0x00, 0x00, 0x4b, 0x62, 0x70, 0x6c, 0x69, 0x73, 0x74,
0x30, 0x30, 0xd1, 0x01, 0x02, 0x5f, 0x10, 0x18, 0x4e, 0x53, 0x48, 0x54, 0x54, 0x50, 0x43, 0x6f,
0x6f, 0x6b, 0x69, 0x65, 0x41, 0x63, 0x63, 0x65, 0x70, 0x74, 0x50, 0x6f, 0x6c, 0x69, 0x63, 0x79,
0x10, 0x02, 0x08, 0x0b, 0x26, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x28,
}
func Test1DecodeSize(t *testing.T) {
cook := New(bytes.NewReader(_test1))
if _, err := cook.Decode(); err != nil {
t.Fatal(err)
}
expected := uint32(11)
if cook.size != expected {
t.Fatalf("incorrect number of pages\n- %d\n+ %d", expected, cook.size)
}
}
func Test1DecodePage(t *testing.T) {
cook := New(bytes.NewReader(_test1))
if _, err := cook.Decode(); err != nil {
t.Fatal(err)
}
expected := []uint32{12, 402, 12, 12, 12, 12, 12, 12, 12, 12, 12}
if len(cook.page) != len(expected) {
t.Fatalf("invalid page offsets\n- %#v\n+ %#v", expected, cook.page)
}
for idx, offset := range expected {
if cook.page[idx] != offset {
t.Fatalf("invalid page offsets\n- %#v\n+ %#v\n! check index #%d", expected, cook.page, idx)
}
}
}
func Test1DecodeChecksum(t *testing.T) {
cook := New(bytes.NewReader(_test1))
if _, err := cook.Decode(); err != nil {
t.Fatal(err)
}
expected := []byte{0x0, 0x0, 0x16, 0x33, 0x7, 0x17, 0x20, 0x5}
if !bytes.Equal(cook.checksum, expected) {
t.Fatalf("incorrect file checksum\n- %#v\n+ %#v", expected, cook.checksum)
}
}
func Test1DecodePage0(t *testing.T) {
checkCookiePage(t, _test1, 0, Page{Length: 0, Offsets: []uint32{}, Cookies: []Cookie{}})
}
func Test1DecodePage1(t *testing.T) {
checkCookiePage(t, _test1, 1, Page{
Length: 4,
Offsets: []uint32{28, 121, 220, 311},
Cookies: []Cookie{
{
Size: 93,
HttpOnly: true,
Domain: []byte(`urlecho.appspot.com`),
Name: []byte(`httpOnly`),
Path: []byte(`/`),
Value: []byte(`value`),
},
{
Size: 99,
Secure: true,
HttpOnly: true,
Domain: []byte(`urlecho.appspot.com`),
Name: []byte(`httpOnlySecure`),
Path: []byte(`/`),
Value: []byte(`value`),
},
{
Size: 91,
Domain: []byte(`urlecho.appspot.com`),
Name: []byte(`normal`),
Path: []byte(`/`),
Value: []byte(`value`),
},
{
Size: 91,
Secure: true,
Domain: []byte(`urlecho.appspot.com`),
Name: []byte(`secure`),
Path: []byte(`/`),
Value: []byte(`value`),
},
},
})
}
func Test1DecodePage2(t *testing.T) {
checkCookiePage(t, _test1, 2, Page{Length: 0, Offsets: []uint32{}, Cookies: []Cookie{}})
}
func Test1DecodePage3(t *testing.T) {
checkCookiePage(t, _test1, 3, Page{Length: 0, Offsets: []uint32{}, Cookies: []Cookie{}})
}
func Test1DecodePage4(t *testing.T) {
checkCookiePage(t, _test1, 4, Page{Length: 0, Offsets: []uint32{}, Cookies: []Cookie{}})
}
func Test1DecodePage5(t *testing.T) {
checkCookiePage(t, _test1, 5, Page{Length: 0, Offsets: []uint32{}, Cookies: []Cookie{}})
}
func Test1DecodePage6(t *testing.T) {
checkCookiePage(t, _test1, 6, Page{Length: 0, Offsets: []uint32{}, Cookies: []Cookie{}})
}
func Test1DecodePage7(t *testing.T) {
checkCookiePage(t, _test1, 7, Page{Length: 0, Offsets: []uint32{}, Cookies: []Cookie{}})
}
func Test1DecodePage8(t *testing.T) {
checkCookiePage(t, _test1, 8, Page{Length: 0, Offsets: []uint32{}, Cookies: []Cookie{}})
}
func Test1DecodePage9(t *testing.T) {
checkCookiePage(t, _test1, 9, Page{Length: 0, Offsets: []uint32{}, Cookies: []Cookie{}})
}
func Test1DecodePage10(t *testing.T) {
checkCookiePage(t, _test1, 10, Page{Length: 0, Offsets: []uint32{}, Cookies: []Cookie{}})
}