-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest2_test.go
204 lines (187 loc) · 9.17 KB
/
test2_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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
package binarycookies
import (
"bytes"
"testing"
)
var _test2 = []byte{
0x63, 0x6f, 0x6f, 0x6b, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x02, 0xda, 0x00, 0x00, 0x01, 0x2b,
0x00, 0x00, 0x01, 0x00, 0x07, 0x00, 0x00, 0x00, 0x28, 0x00, 0x00, 0x00, 0x99, 0x00, 0x00, 0x00,
0xe5, 0x00, 0x00, 0x00, 0x3c, 0x01, 0x00, 0x00, 0x9e, 0x01, 0x00, 0x00, 0x0b, 0x02, 0x00, 0x00,
0x82, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x71, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x38, 0x00, 0x00, 0x00, 0x43, 0x00, 0x00, 0x00,
0x4a, 0x00, 0x00, 0x00, 0x4c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0xf2, 0xbe, 0xec, 0xb8, 0x41, 0x00, 0x00, 0x00, 0x72, 0x8b, 0x0b, 0xb7, 0x41,
0x2e, 0x61, 0x70, 0x70, 0x6c, 0x65, 0x2e, 0x63, 0x6f, 0x6d, 0x00, 0x64, 0x73, 0x73, 0x69, 0x64,
0x32, 0x00, 0x2f, 0x00, 0x62, 0x32, 0x36, 0x37, 0x61, 0x63, 0x65, 0x66, 0x2d, 0x62, 0x39, 0x31,
0x65, 0x2d, 0x34, 0x61, 0x35, 0x65, 0x2d, 0x38, 0x66, 0x31, 0x35, 0x2d, 0x35, 0x34, 0x62, 0x65,
0x32, 0x63, 0x30, 0x33, 0x37, 0x62, 0x31, 0x63, 0x00, 0x4c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x38, 0x00, 0x00, 0x00, 0x43, 0x00, 0x00,
0x00, 0x48, 0x00, 0x00, 0x00, 0x4a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x72, 0xf2, 0xcd, 0xba, 0x41, 0x00, 0x00, 0x00, 0x72, 0x8b, 0x0b, 0xb7,
0x41, 0x2e, 0x61, 0x70, 0x70, 0x6c, 0x65, 0x2e, 0x63, 0x6f, 0x6d, 0x00, 0x70, 0x78, 0x72, 0x6f,
0x00, 0x2f, 0x00, 0x31, 0x00, 0x57, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x38, 0x00, 0x00, 0x00, 0x43, 0x00, 0x00, 0x00, 0x53, 0x00, 0x00,
0x00, 0x55, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x6f, 0xf2, 0xcd, 0xba, 0x41, 0x00, 0x00, 0x00, 0x70, 0x8b, 0x0b, 0xb7, 0x41, 0x2e, 0x61, 0x70,
0x70, 0x6c, 0x65, 0x2e, 0x63, 0x6f, 0x6d, 0x00, 0x73, 0x5f, 0x69, 0x6e, 0x76, 0x69, 0x73, 0x69,
0x74, 0x5f, 0x6e, 0x32, 0x5f, 0x75, 0x73, 0x00, 0x2f, 0x00, 0x33, 0x00, 0x62, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x38, 0x00, 0x00, 0x00,
0x43, 0x00, 0x00, 0x00, 0x50, 0x00, 0x00, 0x00, 0x52, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x6f, 0xf2, 0xcd, 0xba, 0x41, 0x00, 0x00, 0x00, 0x70,
0x8b, 0x0b, 0xb7, 0x41, 0x2e, 0x61, 0x70, 0x70, 0x6c, 0x65, 0x2e, 0x63, 0x6f, 0x6d, 0x00, 0x73,
0x5f, 0x70, 0x61, 0x74, 0x68, 0x4c, 0x65, 0x6e, 0x67, 0x74, 0x68, 0x00, 0x2f, 0x00, 0x68, 0x6f,
0x6d, 0x65, 0x70, 0x61, 0x67, 0x65, 0x25, 0x33, 0x44, 0x31, 0x25, 0x32, 0x43, 0x00, 0x6d, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x38, 0x00,
0x00, 0x00, 0x43, 0x00, 0x00, 0x00, 0x48, 0x00, 0x00, 0x00, 0x4a, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x71, 0xf2, 0xcd, 0xba, 0x41, 0x00, 0x00,
0x00, 0x72, 0x8b, 0x0b, 0xb7, 0x41, 0x2e, 0x61, 0x70, 0x70, 0x6c, 0x65, 0x2e, 0x63, 0x6f, 0x6d,
0x00, 0x73, 0x5f, 0x70, 0x76, 0x00, 0x2f, 0x00, 0x61, 0x70, 0x70, 0x6c, 0x65, 0x25, 0x32, 0x30,
0x2d, 0x25, 0x32, 0x30, 0x69, 0x6e, 0x64, 0x65, 0x78, 0x25, 0x32, 0x46, 0x74, 0x61, 0x62, 0x25,
0x32, 0x30, 0x25, 0x32, 0x38, 0x75, 0x73, 0x25, 0x32, 0x39, 0x00, 0x77, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x38, 0x00, 0x00, 0x00, 0x43,
0x00, 0x00, 0x00, 0x48, 0x00, 0x00, 0x00, 0x4a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc4, 0xf2, 0xcd, 0xba, 0x41, 0x00, 0x00, 0x00, 0xc4, 0x8b,
0x0b, 0xb7, 0x41, 0x2e, 0x61, 0x70, 0x70, 0x6c, 0x65, 0x2e, 0x63, 0x6f, 0x6d, 0x00, 0x73, 0x5f,
0x76, 0x69, 0x00, 0x2f, 0x00, 0x5b, 0x43, 0x53, 0x5d, 0x76, 0x31, 0x7c, 0x32, 0x38, 0x41, 0x44,
0x41, 0x39, 0x46, 0x37, 0x38, 0x35, 0x30, 0x31, 0x31, 0x33, 0x35, 0x36, 0x2d, 0x36, 0x30, 0x30,
0x30, 0x31, 0x36, 0x30, 0x32, 0x36, 0x30, 0x32, 0x44, 0x39, 0x30, 0x43, 0x31, 0x5b, 0x43, 0x45,
0x5d, 0x00, 0x58, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x38, 0x00, 0x00, 0x00, 0x43, 0x00, 0x00, 0x00, 0x50, 0x00, 0x00, 0x00, 0x52, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x6f, 0xf2, 0xcd,
0xba, 0x41, 0x00, 0x00, 0x00, 0x70, 0x8b, 0x0b, 0xb7, 0x41, 0x2e, 0x61, 0x70, 0x70, 0x6c, 0x65,
0x2e, 0x63, 0x6f, 0x6d, 0x00, 0x73, 0x5f, 0x76, 0x6e, 0x75, 0x6d, 0x5f, 0x6e, 0x32, 0x5f, 0x75,
0x73, 0x00, 0x2f, 0x00, 0x33, 0x25, 0x37, 0x43, 0x31, 0x00, 0x00, 0x00, 0x01, 0x00, 0x02, 0x00,
0x00, 0x00, 0x14, 0x00, 0x00, 0x00, 0xd9, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc5, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x38, 0x00,
0x00, 0x00, 0x49, 0x00, 0x00, 0x00, 0x53, 0x00, 0x00, 0x00, 0x55, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xcc, 0x92, 0x0b, 0xb7, 0x41, 0x00, 0x00,
0x00, 0xc4, 0x8b, 0x0b, 0xb7, 0x41, 0x2e, 0x73, 0x74, 0x6f, 0x72, 0x65, 0x2e, 0x61, 0x70, 0x70,
0x6c, 0x65, 0x2e, 0x63, 0x6f, 0x6d, 0x00, 0x61, 0x73, 0x6d, 0x65, 0x74, 0x72, 0x69, 0x63, 0x73,
0x00, 0x2f, 0x00, 0x25, 0x32, 0x35, 0x37, 0x42, 0x25, 0x32, 0x35, 0x32, 0x32, 0x73, 0x74, 0x6f,
0x72, 0x65, 0x25, 0x32, 0x35, 0x32, 0x32, 0x25, 0x32, 0x35, 0x33, 0x41, 0x25, 0x32, 0x35, 0x37,
0x42, 0x25, 0x32, 0x35, 0x32, 0x32, 0x73, 0x69, 0x64, 0x25, 0x32, 0x35, 0x32, 0x32, 0x25, 0x32,
0x35, 0x33, 0x41, 0x25, 0x32, 0x35, 0x32, 0x32, 0x77, 0x48, 0x46, 0x32, 0x46, 0x32, 0x50, 0x48,
0x43, 0x43, 0x43, 0x58, 0x37, 0x32, 0x4b, 0x44, 0x59, 0x25, 0x32, 0x35, 0x32, 0x32, 0x25, 0x32,
0x35, 0x32, 0x43, 0x25, 0x32, 0x35, 0x32, 0x32, 0x76, 0x68, 0x25, 0x32, 0x35, 0x32, 0x32, 0x25,
0x32, 0x35, 0x33, 0x41, 0x74, 0x72, 0x75, 0x65, 0x25, 0x32, 0x35, 0x37, 0x44, 0x25, 0x32, 0x35,
0x37, 0x44, 0x00, 0x52, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x38, 0x00, 0x00, 0x00, 0x49, 0x00, 0x00, 0x00, 0x4c, 0x00, 0x00, 0x00, 0x4e,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc6, 0x92,
0x0b, 0xb7, 0x41, 0x00, 0x00, 0x00, 0xbe, 0x8b, 0x0b, 0xb7, 0x41, 0x2e, 0x73, 0x74, 0x6f, 0x72,
0x65, 0x2e, 0x61, 0x70, 0x70, 0x6c, 0x65, 0x2e, 0x63, 0x6f, 0x6d, 0x00, 0x64, 0x63, 0x00, 0x2f,
0x00, 0x6e, 0x77, 0x6b, 0x00, 0x00, 0x00, 0x36, 0x69, 0x07, 0x17, 0x20, 0x05,
}
func Test2DecodeSize(t *testing.T) {
cook := New(bytes.NewReader(_test2))
if _, err := cook.Decode(); err != nil {
t.Fatal(err)
}
expected := uint32(2)
if cook.size != expected {
t.Fatalf("incorrect number of pages\n- %d\n+ %d", expected, cook.size)
}
}
func Test2DecodePage(t *testing.T) {
cook := New(bytes.NewReader(_test2))
if _, err := cook.Decode(); err != nil {
t.Fatal(err)
}
expected := []uint32{730, 299}
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 Test2DecodeChecksum(t *testing.T) {
cook := New(bytes.NewReader(_test2))
if _, err := cook.Decode(); err != nil {
t.Fatal(err)
}
expected := []byte{0x0, 0x0, 0x36, 0x69, 0x7, 0x17, 0x20, 0x5}
if !bytes.Equal(cook.checksum, expected) {
t.Fatalf("incorrect file checksum\n- %#v\n+ %#v", expected, cook.checksum)
}
}
func Test2DecodePage0(t *testing.T) {
checkCookiePage(t, _test2, 0, Page{
Length: 7,
Offsets: []uint32{40, 153, 229, 316, 414, 523, 642},
Cookies: []Cookie{
{
Size: 113,
Domain: []byte(`.apple.com`),
Name: []byte(`dssid2`),
Path: []byte(`/`),
Value: []byte(`b267acef-b91e-4a5e-8f15-54be2c037b1c`),
},
{
Size: 76,
Domain: []byte(`.apple.com`),
Name: []byte(`pxro`),
Path: []byte(`/`),
Value: []byte(`1`),
},
{
Size: 87,
Domain: []byte(`.apple.com`),
Name: []byte(`s_invisit_n2_us`),
Path: []byte(`/`),
Value: []byte(`3`),
},
{
Size: 98,
Domain: []byte(`.apple.com`),
Name: []byte(`s_pathLength`),
Path: []byte(`/`),
Value: []byte(`homepage%3D1%2C`),
},
{
Size: 109,
Domain: []byte(`.apple.com`),
Name: []byte(`s_pv`),
Path: []byte(`/`),
Value: []byte(`apple%20-%20index%2Ftab%20%28us%29`),
},
{
Size: 119,
Domain: []byte(`.apple.com`),
Name: []byte(`s_vi`),
Path: []byte(`/`),
Value: []byte(`[CS]v1|28ADA9F785011356-60001602602D90C1[CE]`),
},
{
Size: 88,
Domain: []byte(`.apple.com`),
Name: []byte(`s_vnum_n2_us`),
Path: []byte(`/`),
Value: []byte(`3%7C1`),
},
},
})
}
func Test2DecodePage1(t *testing.T) {
checkCookiePage(t, _test2, 1, Page{
Length: 2,
Offsets: []uint32{20, 217},
Cookies: []Cookie{
{
Size: 197,
Domain: []byte(`.store.apple.com`),
Name: []byte(`asmetrics`),
Path: []byte(`/`),
Value: []byte(`%257B%2522store%2522%253A%257B%2522sid%2522%253A%2522wHF2F2PHCCCX72KDY%2522%252C%2522vh%2522%253Atrue%257D%257D`),
},
{
Size: 82,
Domain: []byte(`.store.apple.com`),
Name: []byte(`dc`),
Path: []byte(`/`),
Value: []byte(`nwk`),
},
},
})
}