line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# $Id: Cookies.pm,v 1.7 2003/03/02 11:52:09 m_ilya Exp $ |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
package HTTP::WebTest::Plugin::Cookies; |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
=head1 NAME |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
HTTP::WebTest::Plugin::Cookies - Send and recieve cookies in tests |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
=head1 SYNOPSIS |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
Not Applicable |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
=head1 DESCRIPTION |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
This plugin provides means to control sending and recieve cookies in |
16
|
|
|
|
|
|
|
web test. |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
=cut |
19
|
|
|
|
|
|
|
|
20
|
10
|
|
|
10
|
|
57
|
use strict; |
|
10
|
|
|
|
|
30
|
|
|
10
|
|
|
|
|
385
|
|
21
|
|
|
|
|
|
|
|
22
|
10
|
|
|
10
|
|
54
|
use base qw(HTTP::WebTest::Plugin); |
|
10
|
|
|
|
|
22
|
|
|
10
|
|
|
|
|
795
|
|
23
|
|
|
|
|
|
|
|
24
|
10
|
|
|
10
|
|
56
|
use HTTP::Status; |
|
10
|
|
|
|
|
27
|
|
|
10
|
|
|
|
|
7204
|
|
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
=head1 TEST PARAMETERS |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
=for pod_merge copy params |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
=head2 accept_cookies |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
Option to accept cookies from the web server. |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
These cookies exist only while the program is executing and do not |
35
|
|
|
|
|
|
|
affect subsequent runs. These cookies do not affect your browser or |
36
|
|
|
|
|
|
|
any software other than the test program. These cookies are only |
37
|
|
|
|
|
|
|
accessible to other tests executed during test sequence execution. |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
See also the parameter. |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
=head3 Allowed values |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
C, C |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
=head3 Default value |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
C |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
=head2 send_cookies |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
Option to send cookies to web server. This applies to cookies |
52
|
|
|
|
|
|
|
received from the web server or cookies specified using the C |
53
|
|
|
|
|
|
|
test parameter. |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
This does NOT give the web server(s) access to cookies created with a |
56
|
|
|
|
|
|
|
browser or any user agent software other than this program. The |
57
|
|
|
|
|
|
|
cookies created while this program is running are only accessible to |
58
|
|
|
|
|
|
|
other tests in the same test sequence. |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
See also the parameter. |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
=head3 Allowed values |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
C, C |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
=head3 Default value |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
C |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
=head2 cookie |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
Synonym to C. |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
It is deprecated parameter and may be removed in future versions of |
75
|
|
|
|
|
|
|
L. |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
=head2 cookies |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
This is a list parameter that specifies cookies to send to the web |
80
|
|
|
|
|
|
|
server: |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
cookies = ( cookie1_spec |
83
|
|
|
|
|
|
|
cookie2_spec |
84
|
|
|
|
|
|
|
... |
85
|
|
|
|
|
|
|
cookieN_spec ) |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
Currently there are two ways to specify a cookie. |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
=over 4 |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
=item * Named style |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
A cookie is specified by a set of C value> pairs: |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
( |
96
|
|
|
|
|
|
|
param => value |
97
|
|
|
|
|
|
|
... |
98
|
|
|
|
|
|
|
) |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
List of all supported C value> pairs: |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
=over 4 |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
=item version => VERSION |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
Version number of cookie spec to use, usually 0. |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
=item name => NAME (REQUIRED) |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
Name of cookie. Cannot begin with a $ character. |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
=item value => VALUE (REQUIRED) |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
Value of cookie. |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
=item path => PATH (REQUIRED) |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
URL path name for which this cookie applies. Must begin with a / |
119
|
|
|
|
|
|
|
character. See also path_spec. |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
=item domain => DOMAIN (REQUIRED) |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
Domain for which cookie is valid. Must either contain two periods or |
124
|
|
|
|
|
|
|
be equal to C<.local>. |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
=item port => PORT |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
List of allowed port numbers that the cookie may be returned to. If |
129
|
|
|
|
|
|
|
not specified, cookie can be returned to any port. Must be specified |
130
|
|
|
|
|
|
|
using the format C or C where N is one or more |
131
|
|
|
|
|
|
|
digits. |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
=item path_spec => PATH_SPEC |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
Ignored if version is less than 1. Option to ignore the value of |
136
|
|
|
|
|
|
|
path. Default value is 0. |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
=over 4 |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
=item * 1 |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
Use the value of path. |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
=item * 0 |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
Ignore the specified value of path. |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
=back |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
=item secure => SECURE |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
Option to require secure protocols for cookie transmission. Default |
153
|
|
|
|
|
|
|
value is 0. |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
=over 4 |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
=item * 1 |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
Use only secure protocols to transmit this cookie. |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
=item * 0 |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
Secure protocols are not required for transmission. |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
=back |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
=item maxage => MAXAGE |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
Number of seconds until cookie expires. |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
=item discard => DISCARD |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
Option to discard cookie when the program finishes. Default is 0. |
174
|
|
|
|
|
|
|
(The cookie will be discarded regardless of the value of this |
175
|
|
|
|
|
|
|
element.) |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
=over 4 |
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
=item * 1 |
180
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
Discard cookie when the program finishes. |
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
=item * 0 |
184
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
Don't discard cookie. |
186
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
=back |
188
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
=item rest => NAME_VALUE_LIST |
190
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
Defines additional cookie attributes. |
192
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
Zero, one or several name/value pairs may be specified. The name |
194
|
|
|
|
|
|
|
parameters are words such as Comment or CommentURL and the value |
195
|
|
|
|
|
|
|
parameters are strings that may contain embedded blanks. |
196
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
=back |
198
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
Example (wtscript file): |
200
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
cookies = ( ( name => Cookie1 |
202
|
|
|
|
|
|
|
value => cookie value ) |
203
|
|
|
|
|
|
|
|
204
|
|
|
|
|
|
|
( name => Cookie2 |
205
|
|
|
|
|
|
|
value => cookie value |
206
|
|
|
|
|
|
|
path => / |
207
|
|
|
|
|
|
|
domain => .company.com ) ) |
208
|
|
|
|
|
|
|
|
209
|
|
|
|
|
|
|
( name => Cookie2 |
210
|
|
|
|
|
|
|
value => cookie value |
211
|
|
|
|
|
|
|
rest => ( Comment => this is a comment ) ) |
212
|
|
|
|
|
|
|
|
213
|
|
|
|
|
|
|
Example (Perl script): |
214
|
|
|
|
|
|
|
|
215
|
|
|
|
|
|
|
my $tests = [ |
216
|
|
|
|
|
|
|
... |
217
|
|
|
|
|
|
|
{ |
218
|
|
|
|
|
|
|
test_name => 'cookie', |
219
|
|
|
|
|
|
|
cookies => [ [ |
220
|
|
|
|
|
|
|
name => 'Cookie1', |
221
|
|
|
|
|
|
|
value => 'Value', |
222
|
|
|
|
|
|
|
], |
223
|
|
|
|
|
|
|
[ |
224
|
|
|
|
|
|
|
name => 'Cookie2', |
225
|
|
|
|
|
|
|
value => 'Value', |
226
|
|
|
|
|
|
|
path => '/', |
227
|
|
|
|
|
|
|
] ], |
228
|
|
|
|
|
|
|
... |
229
|
|
|
|
|
|
|
} |
230
|
|
|
|
|
|
|
... |
231
|
|
|
|
|
|
|
] |
232
|
|
|
|
|
|
|
|
233
|
|
|
|
|
|
|
=item * Row list style |
234
|
|
|
|
|
|
|
|
235
|
|
|
|
|
|
|
This style of cookie specification is deprecated and may be removed in |
236
|
|
|
|
|
|
|
future versions of L. |
237
|
|
|
|
|
|
|
|
238
|
|
|
|
|
|
|
Each cookie is specified by following list: |
239
|
|
|
|
|
|
|
|
240
|
|
|
|
|
|
|
( VERSION |
241
|
|
|
|
|
|
|
NAME |
242
|
|
|
|
|
|
|
VALUE |
243
|
|
|
|
|
|
|
PATH |
244
|
|
|
|
|
|
|
DOMAIN |
245
|
|
|
|
|
|
|
PORT |
246
|
|
|
|
|
|
|
PATH_SPEC |
247
|
|
|
|
|
|
|
SECURE |
248
|
|
|
|
|
|
|
MAXAGE |
249
|
|
|
|
|
|
|
DISCARD |
250
|
|
|
|
|
|
|
NAME1 |
251
|
|
|
|
|
|
|
VALUE1 |
252
|
|
|
|
|
|
|
NAME2 |
253
|
|
|
|
|
|
|
VALUE2 |
254
|
|
|
|
|
|
|
... |
255
|
|
|
|
|
|
|
) |
256
|
|
|
|
|
|
|
|
257
|
|
|
|
|
|
|
|
258
|
|
|
|
|
|
|
Any element not marked below as REQUIRED may be defaulted by |
259
|
|
|
|
|
|
|
specifying a null value or ''. |
260
|
|
|
|
|
|
|
|
261
|
|
|
|
|
|
|
=over 4 |
262
|
|
|
|
|
|
|
|
263
|
|
|
|
|
|
|
=item * VERSION (REQUIRED) |
264
|
|
|
|
|
|
|
|
265
|
|
|
|
|
|
|
Version number of cookie spec to use, usually 0. |
266
|
|
|
|
|
|
|
|
267
|
|
|
|
|
|
|
=item * NAME (REQUIRED) |
268
|
|
|
|
|
|
|
|
269
|
|
|
|
|
|
|
Name of cookie. Cannot begin with a $ character. |
270
|
|
|
|
|
|
|
|
271
|
|
|
|
|
|
|
=item * VALUE (REQUIRED) |
272
|
|
|
|
|
|
|
|
273
|
|
|
|
|
|
|
Value of cookie. |
274
|
|
|
|
|
|
|
|
275
|
|
|
|
|
|
|
=item * PATH (REQUIRED) |
276
|
|
|
|
|
|
|
|
277
|
|
|
|
|
|
|
URL path name for which this cookie applies. Must begin with a / |
278
|
|
|
|
|
|
|
character. See also path_spec. |
279
|
|
|
|
|
|
|
|
280
|
|
|
|
|
|
|
=item * DOMAIN (REQUIRED) |
281
|
|
|
|
|
|
|
|
282
|
|
|
|
|
|
|
Domain for which cookie is valid. Must either contain two periods or |
283
|
|
|
|
|
|
|
be equal to C<.local>. |
284
|
|
|
|
|
|
|
|
285
|
|
|
|
|
|
|
=item * PORT |
286
|
|
|
|
|
|
|
|
287
|
|
|
|
|
|
|
List of allowed port numbers that the cookie may be returned to. If |
288
|
|
|
|
|
|
|
not specified, cookie can be returned to any port. Must be specified |
289
|
|
|
|
|
|
|
using the format C or C where N is one or more |
290
|
|
|
|
|
|
|
digits. |
291
|
|
|
|
|
|
|
|
292
|
|
|
|
|
|
|
=item * PATH_SPEC |
293
|
|
|
|
|
|
|
|
294
|
|
|
|
|
|
|
Ignored if version is less than 1. Option to ignore the value of |
295
|
|
|
|
|
|
|
path. Default value is 0. |
296
|
|
|
|
|
|
|
|
297
|
|
|
|
|
|
|
=over 4 |
298
|
|
|
|
|
|
|
|
299
|
|
|
|
|
|
|
=item * 1 |
300
|
|
|
|
|
|
|
|
301
|
|
|
|
|
|
|
Use the value of path. |
302
|
|
|
|
|
|
|
|
303
|
|
|
|
|
|
|
=item * 0 |
304
|
|
|
|
|
|
|
|
305
|
|
|
|
|
|
|
Ignore the specified value of path. |
306
|
|
|
|
|
|
|
|
307
|
|
|
|
|
|
|
=back |
308
|
|
|
|
|
|
|
|
309
|
|
|
|
|
|
|
=item * SECURE |
310
|
|
|
|
|
|
|
|
311
|
|
|
|
|
|
|
Option to require secure protocols for cookie transmission. Default |
312
|
|
|
|
|
|
|
value is 0. |
313
|
|
|
|
|
|
|
|
314
|
|
|
|
|
|
|
=over 4 |
315
|
|
|
|
|
|
|
|
316
|
|
|
|
|
|
|
=item * 1 |
317
|
|
|
|
|
|
|
|
318
|
|
|
|
|
|
|
Use only secure protocols to transmit this cookie. |
319
|
|
|
|
|
|
|
|
320
|
|
|
|
|
|
|
=item * 0 |
321
|
|
|
|
|
|
|
|
322
|
|
|
|
|
|
|
Secure protocols are not required for transmission. |
323
|
|
|
|
|
|
|
|
324
|
|
|
|
|
|
|
=back |
325
|
|
|
|
|
|
|
|
326
|
|
|
|
|
|
|
=item * MAXAGE |
327
|
|
|
|
|
|
|
|
328
|
|
|
|
|
|
|
Number of seconds until cookie expires. |
329
|
|
|
|
|
|
|
|
330
|
|
|
|
|
|
|
=item * DISCARD |
331
|
|
|
|
|
|
|
|
332
|
|
|
|
|
|
|
Option to discard cookie when the program finishes. Default is 0. |
333
|
|
|
|
|
|
|
(The cookie will be discarded regardless of the value of this |
334
|
|
|
|
|
|
|
element.) |
335
|
|
|
|
|
|
|
|
336
|
|
|
|
|
|
|
=over 4 |
337
|
|
|
|
|
|
|
|
338
|
|
|
|
|
|
|
=item * 1 |
339
|
|
|
|
|
|
|
|
340
|
|
|
|
|
|
|
Discard cookie when the program finishes. |
341
|
|
|
|
|
|
|
|
342
|
|
|
|
|
|
|
=item * 0 |
343
|
|
|
|
|
|
|
|
344
|
|
|
|
|
|
|
Don't discard cookie. |
345
|
|
|
|
|
|
|
|
346
|
|
|
|
|
|
|
=back |
347
|
|
|
|
|
|
|
|
348
|
|
|
|
|
|
|
=item * name/value |
349
|
|
|
|
|
|
|
|
350
|
|
|
|
|
|
|
Zero, one or several name/value pairs may be specified. The name |
351
|
|
|
|
|
|
|
parameters are words such as Comment or CommentURL and the value |
352
|
|
|
|
|
|
|
parameters are strings that may contain embedded blanks. |
353
|
|
|
|
|
|
|
|
354
|
|
|
|
|
|
|
=back |
355
|
|
|
|
|
|
|
|
356
|
|
|
|
|
|
|
An example cookie would look like: |
357
|
|
|
|
|
|
|
|
358
|
|
|
|
|
|
|
cookies = ( ( 0 |
359
|
|
|
|
|
|
|
WebTest cookie #1 |
360
|
|
|
|
|
|
|
cookie value |
361
|
|
|
|
|
|
|
/ |
362
|
|
|
|
|
|
|
.mycompany.com |
363
|
|
|
|
|
|
|
'' |
364
|
|
|
|
|
|
|
0 |
365
|
|
|
|
|
|
|
0 |
366
|
|
|
|
|
|
|
200 |
367
|
|
|
|
|
|
|
1 |
368
|
|
|
|
|
|
|
) ) |
369
|
|
|
|
|
|
|
|
370
|
|
|
|
|
|
|
=back |
371
|
|
|
|
|
|
|
|
372
|
|
|
|
|
|
|
See RFC 2965 for details (ftp://ftp.isi.edu/in-notes/rfc2965.txt). |
373
|
|
|
|
|
|
|
|
374
|
|
|
|
|
|
|
=cut |
375
|
|
|
|
|
|
|
|
376
|
|
|
|
|
|
|
sub param_types { |
377
|
194
|
|
|
194
|
1
|
3417
|
return q(accept_cookies yesno |
378
|
|
|
|
|
|
|
send_cookies yesno |
379
|
|
|
|
|
|
|
cookie list |
380
|
|
|
|
|
|
|
cookies list); |
381
|
|
|
|
|
|
|
} |
382
|
|
|
|
|
|
|
|
383
|
10
|
|
|
10
|
|
84
|
use constant NCOOKIE_REFORMAT => 10; |
|
10
|
|
|
|
|
58
|
|
|
10
|
|
|
|
|
10286
|
|
384
|
|
|
|
|
|
|
|
385
|
|
|
|
|
|
|
sub prepare_request { |
386
|
194
|
|
|
194
|
0
|
333
|
my $self = shift; |
387
|
|
|
|
|
|
|
|
388
|
194
|
|
|
|
|
1022
|
$self->validate_params(qw(accept_cookies send_cookies |
389
|
|
|
|
|
|
|
cookies cookie)); |
390
|
|
|
|
|
|
|
|
391
|
194
|
|
|
|
|
6843
|
my $accept_cookies = $self->yesno_test_param('accept_cookies', 1); |
392
|
194
|
|
|
|
|
747
|
my $send_cookies = $self->yesno_test_param('send_cookies', 1); |
393
|
194
|
|
|
|
|
623
|
my $cookies = $self->test_param('cookies'); |
394
|
|
|
|
|
|
|
|
395
|
194
|
|
100
|
|
|
1110
|
$cookies ||= $self->test_param('cookie'); # alias for parameter |
396
|
194
|
100
|
|
|
|
619
|
$cookies = $self->transform_cookies($cookies) if defined $cookies; |
397
|
|
|
|
|
|
|
|
398
|
194
|
|
|
|
|
822
|
my $cookie_jar = $self->webtest->user_agent->cookie_jar; |
399
|
|
|
|
|
|
|
|
400
|
|
|
|
|
|
|
# configure cookie jar |
401
|
194
|
|
|
|
|
2599
|
$cookie_jar->accept_cookies($accept_cookies); |
402
|
194
|
|
|
|
|
1444
|
$cookie_jar->send_cookies($send_cookies); |
403
|
|
|
|
|
|
|
|
404
|
194
|
100
|
|
|
|
1064
|
if(defined $cookies) { |
405
|
6
|
|
|
|
|
15
|
for my $cookie (@$cookies) { |
406
|
12
|
|
|
|
|
232
|
$cookie_jar->set_cookie(@$cookie); |
407
|
|
|
|
|
|
|
} |
408
|
|
|
|
|
|
|
} |
409
|
|
|
|
|
|
|
} |
410
|
|
|
|
|
|
|
|
411
|
|
|
|
|
|
|
sub check_response { |
412
|
190
|
|
|
190
|
0
|
745
|
my $self = shift; |
413
|
|
|
|
|
|
|
|
414
|
|
|
|
|
|
|
# we don't check here anything - just some clean up |
415
|
190
|
|
|
|
|
1080
|
my $cookie_jar = $self->webtest->user_agent->cookie_jar; |
416
|
190
|
|
|
|
|
1758
|
delete $cookie_jar->{accept_cookies}; |
417
|
190
|
|
|
|
|
376
|
delete $cookie_jar->{send_cookies}; |
418
|
|
|
|
|
|
|
|
419
|
190
|
|
|
|
|
1384
|
return (); |
420
|
|
|
|
|
|
|
} |
421
|
|
|
|
|
|
|
|
422
|
|
|
|
|
|
|
# transform cookies to some canonic representation |
423
|
|
|
|
|
|
|
sub transform_cookies { |
424
|
7
|
|
|
7
|
0
|
15
|
my $self = shift; |
425
|
7
|
|
|
|
|
13
|
my $cookies = shift; |
426
|
|
|
|
|
|
|
|
427
|
|
|
|
|
|
|
# check if $cookies is array of arrays |
428
|
7
|
100
|
|
|
|
37
|
unless(ref($$cookies[0]) eq 'ARRAY') { |
429
|
1
|
|
|
|
|
8
|
return $self->transform_cookies([ $cookies ]); |
430
|
|
|
|
|
|
|
} |
431
|
|
|
|
|
|
|
|
432
|
6
|
|
|
|
|
14
|
my @cookies = (); |
433
|
|
|
|
|
|
|
|
434
|
6
|
|
|
|
|
21
|
for my $cookie (@$cookies) { |
435
|
|
|
|
|
|
|
# simple heuristic to distinguish deprecated format from new: |
436
|
|
|
|
|
|
|
# in new format $cookie->[0] cannot be a number while it is |
437
|
|
|
|
|
|
|
# expected for deprecated |
438
|
12
|
100
|
|
|
|
73
|
if($cookie->[0] =~ /^ \d* $/x) { |
439
|
7
|
|
|
|
|
26
|
$cookie = $self->transform_cookie_deprecated($cookie); |
440
|
|
|
|
|
|
|
} else { |
441
|
5
|
|
|
|
|
14
|
$cookie = $self->transform_cookie($cookie); |
442
|
|
|
|
|
|
|
} |
443
|
|
|
|
|
|
|
|
444
|
12
|
50
|
|
|
|
46
|
die "HTTP::WebTest: missing cookie name" |
445
|
|
|
|
|
|
|
unless defined $cookie->[1]; |
446
|
12
|
50
|
|
|
|
34
|
die "HTTP::WebTest: missing cookie path" |
447
|
|
|
|
|
|
|
unless defined $cookie->[3]; |
448
|
12
|
50
|
|
|
|
36
|
die "HTTP::WebTest: missing cookie domain" |
449
|
|
|
|
|
|
|
unless defined $cookie->[4]; |
450
|
|
|
|
|
|
|
|
451
|
12
|
|
|
|
|
33
|
push @cookies, $cookie; |
452
|
|
|
|
|
|
|
} |
453
|
|
|
|
|
|
|
|
454
|
6
|
|
|
|
|
17
|
return \@cookies; |
455
|
|
|
|
|
|
|
} |
456
|
|
|
|
|
|
|
|
457
|
|
|
|
|
|
|
# transform cookie to the canonic representation (a list expected by |
458
|
|
|
|
|
|
|
# HTTP::Cookie::set_cookie) |
459
|
|
|
|
|
|
|
sub transform_cookie { |
460
|
5
|
|
|
5
|
0
|
9
|
my $self = shift; |
461
|
5
|
|
|
|
|
9
|
my $cookie = shift; |
462
|
|
|
|
|
|
|
|
463
|
5
|
|
|
|
|
48
|
my %fields = ( version => 0, |
464
|
|
|
|
|
|
|
name => 1, |
465
|
|
|
|
|
|
|
value => 2, |
466
|
|
|
|
|
|
|
path => 3, |
467
|
|
|
|
|
|
|
domain => 4, |
468
|
|
|
|
|
|
|
port => 5, |
469
|
|
|
|
|
|
|
path_spec => 6, |
470
|
|
|
|
|
|
|
secure => 7, |
471
|
|
|
|
|
|
|
expires => 8, |
472
|
|
|
|
|
|
|
discard => 9, |
473
|
|
|
|
|
|
|
rest => 10 ); |
474
|
|
|
|
|
|
|
|
475
|
5
|
|
|
|
|
9
|
my @canonic = (); |
476
|
5
|
|
|
|
|
20
|
my %cookie = @$cookie; |
477
|
5
|
|
|
|
|
21
|
while(my($field, $value) = each %cookie) { |
478
|
21
|
|
|
|
|
68
|
$canonic[$fields{$field}] = $value; |
479
|
|
|
|
|
|
|
} |
480
|
|
|
|
|
|
|
|
481
|
|
|
|
|
|
|
# convert rest part from array ref to hash ref |
482
|
5
|
100
|
|
|
|
15
|
$canonic[10] = { @{$canonic[10]} } if defined $canonic[10]; |
|
1
|
|
|
|
|
4
|
|
483
|
|
|
|
|
|
|
|
484
|
5
|
|
|
|
|
24
|
return \@canonic; |
485
|
|
|
|
|
|
|
} |
486
|
|
|
|
|
|
|
|
487
|
|
|
|
|
|
|
# transform cookie specified using deprecated format to the canonic |
488
|
|
|
|
|
|
|
# representation (a list expected by HTTP::Cookie::set_cookie) |
489
|
|
|
|
|
|
|
sub transform_cookie_deprecated { |
490
|
7
|
|
|
7
|
0
|
11
|
my $self = shift; |
491
|
7
|
|
|
|
|
12
|
my $cookie = shift; |
492
|
|
|
|
|
|
|
|
493
|
|
|
|
|
|
|
# make a copy of cookie (missing fields are set to undef) |
494
|
7
|
|
|
|
|
35
|
my @canonic = @$cookie[0 .. NCOOKIE_REFORMAT - 1]; |
495
|
|
|
|
|
|
|
|
496
|
|
|
|
|
|
|
# replace '' with undef |
497
|
7
|
100
|
100
|
|
|
220
|
@canonic = map +(defined($_) and $_ eq '') ? (undef) : $_, |
498
|
|
|
|
|
|
|
@canonic; |
499
|
|
|
|
|
|
|
|
500
|
|
|
|
|
|
|
# collect all additional attributes (name, value pairs) |
501
|
7
|
|
|
|
|
35
|
my @extra = @$cookie[ NCOOKIE_REFORMAT .. @$cookie - 1]; |
502
|
7
|
|
|
|
|
22
|
push @canonic, { @extra }; |
503
|
|
|
|
|
|
|
|
504
|
7
|
|
|
|
|
25
|
return \@canonic; |
505
|
|
|
|
|
|
|
} |
506
|
|
|
|
|
|
|
|
507
|
|
|
|
|
|
|
=head1 COPYRIGHT |
508
|
|
|
|
|
|
|
|
509
|
|
|
|
|
|
|
Copyright (c) 2000-2001 Richard Anderson. All rights reserved. |
510
|
|
|
|
|
|
|
|
511
|
|
|
|
|
|
|
Copyright (c) 2001-2003 Ilya Martynov. All rights reserved. |
512
|
|
|
|
|
|
|
|
513
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify |
514
|
|
|
|
|
|
|
it under the same terms as Perl itself. |
515
|
|
|
|
|
|
|
|
516
|
|
|
|
|
|
|
=head1 SEE ALSO |
517
|
|
|
|
|
|
|
|
518
|
|
|
|
|
|
|
L |
519
|
|
|
|
|
|
|
|
520
|
|
|
|
|
|
|
L |
521
|
|
|
|
|
|
|
|
522
|
|
|
|
|
|
|
L |
523
|
|
|
|
|
|
|
|
524
|
|
|
|
|
|
|
L |
525
|
|
|
|
|
|
|
|
526
|
|
|
|
|
|
|
=cut |
527
|
|
|
|
|
|
|
|
528
|
|
|
|
|
|
|
1; |