http-cookie 1.0.7 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,1157 +0,0 @@
1
- # -*- coding: utf-8 -*-
2
- # frozen_string_literal: false
3
- require File.expand_path('helper', File.dirname(__FILE__))
4
- require 'psych' if !defined?(YAML) && RUBY_VERSION == "1.9.2"
5
- require 'yaml'
6
-
7
- class TestHTTPCookie < Test::Unit::TestCase
8
- def setup
9
- httpdate = 'Sun, 27-Sep-2037 00:00:00 GMT'
10
-
11
- @cookie_params = {
12
- 'expires' => 'expires=%s' % httpdate,
13
- 'path' => 'path=/',
14
- 'domain' => 'domain=.rubyforge.org',
15
- 'httponly' => 'HttpOnly',
16
- }
17
-
18
- @expires = Time.parse(httpdate)
19
- end
20
-
21
- def test_parse_dates
22
- url = URI.parse('http://localhost/')
23
-
24
- yesterday = Time.now - 86400
25
-
26
- dates = [ "14 Apr 89 03:20:12",
27
- "14 Apr 89 03:20 GMT",
28
- "Fri, 17 Mar 89 4:01:33",
29
- "Fri, 17 Mar 89 4:01 GMT",
30
- "Mon Jan 16 16:12 PDT 1989",
31
- #"Mon Jan 16 16:12 +0130 1989",
32
- "6 May 1992 16:41-JST (Wednesday)",
33
- #"22-AUG-1993 10:59:12.82",
34
- "22-AUG-1993 10:59pm",
35
- "22-AUG-1993 12:59am",
36
- "22-AUG-1993 12:59 PM",
37
- #"Friday, August 04, 1995 3:54 PM",
38
- #"06/21/95 04:24:34 PM",
39
- #"20/06/95 21:07",
40
- #"95-06-08 19:32:48 EDT",
41
- ]
42
-
43
- dates.each do |date|
44
- cookie = "PREF=1; expires=#{date}"
45
- assert_equal 1, HTTP::Cookie.parse(cookie, url) { |c|
46
- assert c.expires, "Tried parsing: #{date}"
47
- assert_send [c.expires, :<, yesterday]
48
- }.size
49
- end
50
-
51
- [
52
- ["PREF=1; expires=Wed, 01 Jan 100 12:34:56 GMT", nil],
53
- ["PREF=1; expires=Sat, 01 Jan 1600 12:34:56 GMT", nil],
54
- ["PREF=1; expires=Tue, 01 Jan 69 12:34:56 GMT", 2069],
55
- ["PREF=1; expires=Thu, 01 Jan 70 12:34:56 GMT", 1970],
56
- ["PREF=1; expires=Wed, 01 Jan 20 12:34:56 GMT", 2020],
57
- ["PREF=1; expires=Sat, 01 Jan 2020 12:34:60 GMT", nil],
58
- ["PREF=1; expires=Sat, 01 Jan 2020 12:60:56 GMT", nil],
59
- ["PREF=1; expires=Sat, 01 Jan 2020 24:00:00 GMT", nil],
60
- ["PREF=1; expires=Sat, 32 Jan 2020 12:34:56 GMT", nil],
61
- ].each { |set_cookie, year|
62
- cookie, = HTTP::Cookie.parse(set_cookie, url)
63
- if year
64
- assert_equal year, cookie.expires.year, "#{set_cookie}: expires in #{year}"
65
- else
66
- assert_equal nil, cookie.expires, "#{set_cookie}: invalid expiry date"
67
- end
68
- }
69
- end
70
-
71
- def test_parse_empty
72
- cookie_str = 'a=b; ; c=d'
73
-
74
- uri = URI.parse 'http://example'
75
-
76
- assert_equal 1, HTTP::Cookie.parse(cookie_str, uri) { |cookie|
77
- assert_equal 'a', cookie.name
78
- assert_equal 'b', cookie.value
79
- }.size
80
- end
81
-
82
- def test_parse_no_space
83
- cookie_str = "foo=bar;Expires=Sun, 06 Nov 2011 00:28:06 GMT;Path=/"
84
-
85
- uri = URI.parse 'http://example'
86
-
87
- assert_equal 1, HTTP::Cookie.parse(cookie_str, uri) { |cookie|
88
- assert_equal 'foo', cookie.name
89
- assert_equal 'bar', cookie.value
90
- assert_equal '/', cookie.path
91
- assert_equal Time.at(1320539286), cookie.expires
92
- }.size
93
- end
94
-
95
- def test_parse_too_long_cookie
96
- uri = URI.parse 'http://example'
97
-
98
- cookie_str = "foo=#{'Cookie' * 680}; path=/ab/"
99
- assert_equal(HTTP::Cookie::MAX_LENGTH - 1, cookie_str.bytesize)
100
-
101
- assert_equal 1, HTTP::Cookie.parse(cookie_str, uri).size
102
-
103
- assert_equal 1, HTTP::Cookie.parse(cookie_str.sub(';', 'x;'), uri).size
104
-
105
- assert_equal 0, HTTP::Cookie.parse(cookie_str.sub(';', 'xx;'), uri).size
106
- end
107
-
108
- def test_parse_quoted
109
- cookie_str =
110
- "quoted=\"value\"; Expires=Sun, 06 Nov 2011 00:11:18 GMT; Path=/; comment=\"comment is \\\"comment\\\"\""
111
-
112
- uri = URI.parse 'http://example'
113
-
114
- assert_equal 1, HTTP::Cookie.parse(cookie_str, uri) { |cookie|
115
- assert_equal 'quoted', cookie.name
116
- assert_equal 'value', cookie.value
117
- }.size
118
- end
119
-
120
- def test_parse_no_nothing
121
- cookie = '; "", ;'
122
- url = URI.parse('http://www.example.com/')
123
- assert_equal 0, HTTP::Cookie.parse(cookie, url).size
124
- end
125
-
126
- def test_parse_no_name
127
- cookie = '=no-name; path=/'
128
- url = URI.parse('http://www.example.com/')
129
- assert_equal 0, HTTP::Cookie.parse(cookie, url).size
130
- end
131
-
132
- def test_parse_bad_name
133
- cookie = "a\001b=c"
134
- url = URI.parse('http://www.example.com/')
135
- assert_nothing_raised {
136
- assert_equal 0, HTTP::Cookie.parse(cookie, url).size
137
- }
138
- end
139
-
140
- def test_parse_bad_value
141
- cookie = "a=b\001c"
142
- url = URI.parse('http://www.example.com/')
143
- assert_nothing_raised {
144
- assert_equal 0, HTTP::Cookie.parse(cookie, url).size
145
- }
146
- end
147
-
148
- def test_parse_weird_cookie
149
- cookie = 'n/a, ASPSESSIONIDCSRRQDQR=FBLDGHPBNDJCPCGNCPAENELB; path=/'
150
- url = URI.parse('http://www.searchinnovation.com/')
151
- assert_equal 1, HTTP::Cookie.parse(cookie, url) { |c|
152
- assert_equal('ASPSESSIONIDCSRRQDQR', c.name)
153
- assert_equal('FBLDGHPBNDJCPCGNCPAENELB', c.value)
154
- }.size
155
- end
156
-
157
- def test_double_semicolon
158
- double_semi = 'WSIDC=WEST;; domain=.williams-sonoma.com; path=/'
159
- url = URI.parse('http://williams-sonoma.com/')
160
- assert_equal 1, HTTP::Cookie.parse(double_semi, url) { |cookie|
161
- assert_equal('WSIDC', cookie.name)
162
- assert_equal('WEST', cookie.value)
163
- }.size
164
- end
165
-
166
- def test_parse_bad_version
167
- bad_cookie = 'PRETANET=TGIAqbFXtt; Name=/PRETANET; Path=/; Version=1.2; Content-type=text/html; Domain=192.168.6.196; expires=Friday, 13-November-2026 23:01:46 GMT;'
168
- url = URI.parse('http://192.168.6.196/')
169
- # The version attribute is obsolete and simply ignored
170
- cookies = HTTP::Cookie.parse(bad_cookie, url)
171
- assert_equal 1, cookies.size
172
- end
173
-
174
- def test_parse_bad_max_age
175
- bad_cookie = 'PRETANET=TGIAqbFXtt; Name=/PRETANET; Path=/; Max-Age=forever; Content-type=text/html; Domain=192.168.6.196; expires=Friday, 13-November-2026 23:01:46 GMT;'
176
- url = URI.parse('http://192.168.6.196/')
177
- # A bad max-age is simply ignored
178
- cookies = HTTP::Cookie.parse(bad_cookie, url)
179
- assert_equal 1, cookies.size
180
- assert_equal nil, cookies.first.max_age
181
- end
182
-
183
- def test_parse_date_fail
184
- url = URI.parse('http://localhost/')
185
-
186
- dates = [
187
- "20/06/95 21:07",
188
- ]
189
-
190
- dates.each { |date|
191
- cookie = "PREF=1; expires=#{date}"
192
- assert_equal 1, HTTP::Cookie.parse(cookie, url) { |c|
193
- assert_equal(true, c.expires.nil?)
194
- }.size
195
- }
196
- end
197
-
198
- def test_parse_domain_dot
199
- url = URI.parse('http://host.example.com/')
200
-
201
- cookie_str = 'a=b; domain=.example.com'
202
-
203
- cookie = HTTP::Cookie.parse(cookie_str, url).first
204
-
205
- assert_equal 'example.com', cookie.domain
206
- assert cookie.for_domain?
207
- assert_equal '.example.com', cookie.dot_domain
208
- end
209
-
210
- def test_parse_domain_no_dot
211
- url = URI.parse('http://host.example.com/')
212
-
213
- cookie_str = 'a=b; domain=example.com'
214
-
215
- cookie = HTTP::Cookie.parse(cookie_str, url).first
216
-
217
- assert_equal 'example.com', cookie.domain
218
- assert cookie.for_domain?
219
- assert_equal '.example.com', cookie.dot_domain
220
- end
221
-
222
- def test_parse_public_suffix
223
- cookie = HTTP::Cookie.new('a', 'b', :domain => 'com')
224
- assert_equal('com', cookie.domain)
225
- assert_equal(false, cookie.for_domain?)
226
-
227
- cookie.origin = 'http://com/'
228
- assert_equal('com', cookie.domain)
229
- assert_equal(false, cookie.for_domain?)
230
-
231
- assert_raises(ArgumentError) {
232
- cookie.origin = 'http://example.com/'
233
- }
234
- end
235
-
236
- def test_parse_domain_none
237
- url = URI.parse('http://example.com/')
238
-
239
- cookie_str = 'a=b;'
240
-
241
- cookie = HTTP::Cookie.parse(cookie_str, url).first
242
-
243
- assert_equal 'example.com', cookie.domain
244
- assert !cookie.for_domain?
245
- assert_equal 'example.com', cookie.dot_domain
246
- end
247
-
248
- def test_parse_max_age
249
- url = URI.parse('http://localhost/')
250
-
251
- epoch, date = 4485353164, 'Fri, 19 Feb 2112 19:26:04 GMT'
252
- base = Time.at(1363014000)
253
-
254
- cookie = HTTP::Cookie.parse("name=Akinori; expires=#{date}", url).first
255
- assert_equal Time.at(epoch), cookie.expires
256
-
257
- cookie = HTTP::Cookie.parse('name=Akinori; max-age=3600', url).first
258
- assert_in_delta Time.now + 3600, cookie.expires, 1
259
- cookie = HTTP::Cookie.parse('name=Akinori; max-age=3600', url, :created_at => base).first
260
- assert_equal base + 3600, cookie.expires
261
-
262
- # Max-Age has precedence over Expires
263
- cookie = HTTP::Cookie.parse("name=Akinori; max-age=3600; expires=#{date}", url).first
264
- assert_in_delta Time.now + 3600, cookie.expires, 1
265
- cookie = HTTP::Cookie.parse("name=Akinori; max-age=3600; expires=#{date}", url, :created_at => base).first
266
- assert_equal base + 3600, cookie.expires
267
-
268
- cookie = HTTP::Cookie.parse("name=Akinori; expires=#{date}; max-age=3600", url).first
269
- assert_in_delta Time.now + 3600, cookie.expires, 1
270
- cookie = HTTP::Cookie.parse("name=Akinori; expires=#{date}; max-age=3600", url, :created_at => base).first
271
- assert_equal base + 3600, cookie.expires
272
- end
273
-
274
- def test_parse_expires_session
275
- url = URI.parse('http://localhost/')
276
-
277
- [
278
- 'name=Akinori',
279
- 'name=Akinori; expires',
280
- 'name=Akinori; max-age',
281
- 'name=Akinori; expires=',
282
- 'name=Akinori; max-age=',
283
- ].each { |str|
284
- cookie = HTTP::Cookie.parse(str, url).first
285
- assert cookie.session?, str
286
- }
287
-
288
- [
289
- 'name=Akinori; expires=Mon, 19 Feb 2012 19:26:04 GMT',
290
- 'name=Akinori; max-age=3600',
291
- ].each { |str|
292
- cookie = HTTP::Cookie.parse(str, url).first
293
- assert !cookie.session?, str
294
- }
295
- end
296
-
297
- def test_parse_many
298
- url = URI 'http://localhost/'
299
- cookie_str =
300
- "abc, " \
301
- "name=Aaron; Domain=localhost; Expires=Sun, 06 Nov 2011 00:29:51 GMT; Path=/, " \
302
- "name=Aaron; Domain=localhost; Expires=Sun, 06 Nov 2011 00:29:51 GMT; Path=/, " \
303
- "name=Aaron; Domain=localhost; Expires=Sun, 06 Nov 2011 00:29:51 GMT; Path=/, " \
304
- "name=Aaron; Domain=localhost; Expires=Sun, 06 Nov 2011 00:29:51 GMT; Path=/; HttpOnly, " \
305
- "expired=doh; Expires=Fri, 04 Nov 2011 00:29:51 GMT; Path=/, " \
306
- "a_path1=some_path; Expires=Sun, 06 Nov 2011 00:29:51 GMT; Path=/some_path, " \
307
- "a_path2=some_path; Expires=Sun, 06 Nov 2011 00:29:51 GMT; Path=/some_path[], " \
308
- "no_path1=no_path; Expires=Sun, 06 Nov 2011 00:29:52 GMT, no_expires=nope; Path=/, " \
309
- "no_path2=no_path; Expires=Sun, 06 Nov 2011 00:29:52 GMT; no_expires=nope; Path, " \
310
- "no_path3=no_path; Expires=Sun, 06 Nov 2011 00:29:52 GMT; no_expires=nope; Path=, " \
311
- "rel_path1=rel_path; Expires=Sun, 06 Nov 2011 00:29:52 GMT; no_expires=nope; Path=foo/bar, " \
312
- "rel_path1=rel_path; Expires=Sun, 06 Nov 2011 00:29:52 GMT; no_expires=nope; Path=foo, " \
313
- "no_domain1=no_domain; Expires=Sun, 06 Nov 2011 00:29:53 GMT; no_expires=nope, " \
314
- "no_domain2=no_domain; Expires=Sun, 06 Nov 2011 00:29:53 GMT; no_expires=nope; Domain, " \
315
- "no_domain3=no_domain; Expires=Sun, 06 Nov 2011 00:29:53 GMT; no_expires=nope; Domain="
316
-
317
- cookies = HTTP::Cookie.parse cookie_str, url
318
- assert_equal 16, cookies.length
319
-
320
- name = cookies.find { |c| c.name == 'name' }
321
- assert_equal "Aaron", name.value
322
- assert_equal "/", name.path
323
- assert_equal Time.at(1320539391), name.expires
324
-
325
- a_path1 = cookies.find { |c| c.name == 'a_path1' }
326
- assert_equal "some_path", a_path1.value
327
- assert_equal "/some_path", a_path1.path
328
- assert_equal Time.at(1320539391), a_path1.expires
329
-
330
- a_path2 = cookies.find { |c| c.name == 'a_path2' }
331
- assert_equal "some_path", a_path2.value
332
- assert_equal "/some_path[]", a_path2.path
333
- assert_equal Time.at(1320539391), a_path2.expires
334
-
335
- no_expires = cookies.find { |c| c.name == 'no_expires' }
336
- assert_equal "nope", no_expires.value
337
- assert_equal "/", no_expires.path
338
- assert_nil no_expires.expires
339
-
340
- no_path_cookies = cookies.select { |c| c.value == 'no_path' }
341
- assert_equal 3, no_path_cookies.size
342
- no_path_cookies.each { |c|
343
- assert_equal "/", c.path, c.name
344
- assert_equal Time.at(1320539392), c.expires, c.name
345
- }
346
-
347
- rel_path_cookies = cookies.select { |c| c.value == 'rel_path' }
348
- assert_equal 2, rel_path_cookies.size
349
- rel_path_cookies.each { |c|
350
- assert_equal "/", c.path, c.name
351
- assert_equal Time.at(1320539392), c.expires, c.name
352
- }
353
-
354
- no_domain_cookies = cookies.select { |c| c.value == 'no_domain' }
355
- assert_equal 3, no_domain_cookies.size
356
- no_domain_cookies.each { |c|
357
- assert !c.for_domain?, c.name
358
- assert_equal c.domain, url.host, c.name
359
- assert_equal Time.at(1320539393), c.expires, c.name
360
- }
361
-
362
- assert cookies.find { |c| c.name == 'expired' }
363
- end
364
-
365
- def test_parse_valid_cookie
366
- url = URI.parse('http://rubyforge.org/')
367
- cookie_params = @cookie_params
368
- cookie_value = '12345%7D=ASDFWEE345%3DASda'
369
-
370
- cookie_params.keys.combine.each do |keys|
371
- cookie_text = [cookie_value, *keys.map { |key| cookie_params[key] }].join('; ')
372
- cookie, = HTTP::Cookie.parse(cookie_text, url)
373
-
374
- assert_equal('12345%7D=ASDFWEE345%3DASda', cookie.to_s)
375
- assert_equal('/', cookie.path)
376
-
377
- assert_equal(keys.include?('expires') ? @expires : nil, cookie.expires)
378
- assert_equal(keys.include?('httponly'), cookie.httponly?)
379
- end
380
- end
381
-
382
- def test_parse_valid_cookie_empty_value
383
- url = URI.parse('http://rubyforge.org/')
384
- cookie_params = @cookie_params
385
- cookie_value = '12345%7D='
386
-
387
- cookie_params.keys.combine.each do |keys|
388
- cookie_text = [cookie_value, *keys.map { |key| cookie_params[key] }].join('; ')
389
- cookie, = HTTP::Cookie.parse(cookie_text, url)
390
-
391
- assert_equal('12345%7D=', cookie.to_s)
392
- assert_equal('', cookie.value)
393
- assert_equal('/', cookie.path)
394
-
395
- assert_equal(keys.include?('expires') ? @expires : nil, cookie.expires)
396
- assert_equal(keys.include?('httponly'), cookie.httponly?)
397
- end
398
- end
399
-
400
- # If no path was given, use the one from the URL
401
- def test_cookie_using_url_path
402
- url = URI.parse('http://rubyforge.org/login.php')
403
- cookie_params = @cookie_params
404
- cookie_value = '12345%7D=ASDFWEE345%3DASda'
405
-
406
- cookie_params.keys.combine.each do |keys|
407
- next if keys.include?('path')
408
- cookie_text = [cookie_value, *keys.map { |key| cookie_params[key] }].join('; ')
409
- cookie, = HTTP::Cookie.parse(cookie_text, url)
410
-
411
- assert_equal('12345%7D=ASDFWEE345%3DASda', cookie.to_s)
412
- assert_equal('/', cookie.path)
413
-
414
- assert_equal(keys.include?('expires') ? @expires : nil, cookie.expires)
415
- assert_equal(keys.include?('httponly'), cookie.httponly?)
416
- end
417
- end
418
-
419
- # Test using secure cookies
420
- def test_cookie_with_secure
421
- url = URI.parse('http://rubyforge.org/')
422
- cookie_params = @cookie_params.merge('secure' => 'secure')
423
- cookie_value = '12345%7D=ASDFWEE345%3DASda'
424
-
425
- cookie_params.keys.combine.each do |keys|
426
- next unless keys.include?('secure')
427
- cookie_text = [cookie_value, *keys.map { |key| cookie_params[key] }].join('; ')
428
- cookie, = HTTP::Cookie.parse(cookie_text, url)
429
-
430
- assert_equal('12345%7D=ASDFWEE345%3DASda', cookie.to_s)
431
- assert_equal('/', cookie.path)
432
- assert_equal(true, cookie.secure)
433
-
434
- assert_equal(keys.include?('expires') ? @expires : nil, cookie.expires)
435
- assert_equal(keys.include?('httponly'), cookie.httponly?)
436
- end
437
- end
438
-
439
- def test_cookie_value
440
- [
441
- ['foo="bar baz"', 'bar baz'],
442
- ['foo="bar\"; \"baz"', 'bar"; "baz'],
443
- ].each { |cookie_value, value|
444
- cookie = HTTP::Cookie.new('foo', value)
445
- assert_equal(cookie_value, cookie.cookie_value)
446
- }
447
-
448
- pairs = [
449
- ['Foo', 'value1'],
450
- ['Bar', 'value 2'],
451
- ['Baz', 'value3'],
452
- ['Bar', 'value"4'],
453
- ['Quux', 'x, value=5'],
454
- ]
455
-
456
- cookie_value = HTTP::Cookie.cookie_value(pairs.map { |name, value|
457
- HTTP::Cookie.new(:name => name, :value => value)
458
- })
459
-
460
- assert_equal 'Foo=value1; Bar="value 2"; Baz=value3; Bar="value\\"4"; Quux="x, value=5"', cookie_value
461
-
462
- hash = HTTP::Cookie.cookie_value_to_hash(cookie_value)
463
-
464
- assert_equal pairs.map(&:first).uniq.size, hash.size
465
-
466
- hash.each_pair { |name, value|
467
- _, pvalue = pairs.assoc(name)
468
- assert_equal pvalue, value
469
- }
470
-
471
- # Do not treat comma in a Cookie header value as separator; see CVE-2016-7401
472
- hash = HTTP::Cookie.cookie_value_to_hash('Quux=x, value=5; Foo=value1; Bar="value 2"; Baz=value3; Bar="value\\"4"')
473
-
474
- assert_equal pairs.map(&:first).uniq.size, hash.size
475
-
476
- hash.each_pair { |name, value|
477
- _, pvalue = pairs.assoc(name)
478
- assert_equal pvalue, value
479
- }
480
- end
481
-
482
- def test_set_cookie_value
483
- url = URI.parse('http://rubyforge.org/path/')
484
-
485
- [
486
- HTTP::Cookie.new('a', 'b', :domain => 'rubyforge.org', :path => '/path/'),
487
- HTTP::Cookie.new('a', 'b', :origin => url),
488
- ].each { |cookie|
489
- cookie.set_cookie_value
490
- }
491
-
492
- [
493
- HTTP::Cookie.new('a', 'b', :domain => 'rubyforge.org'),
494
- HTTP::Cookie.new('a', 'b', :for_domain => true, :path => '/path/'),
495
- ].each { |cookie|
496
- assert_raises(RuntimeError) {
497
- cookie.set_cookie_value
498
- }
499
- }
500
-
501
- ['foo=bar', 'foo="bar"', 'foo="ba\"r baz"'].each { |cookie_value|
502
- cookie_params = @cookie_params.merge('path' => '/path/', 'secure' => 'secure', 'max-age' => 'Max-Age=1000')
503
- date = Time.at(Time.now.to_i)
504
- cookie_params.keys.combine.each do |keys|
505
- cookie_text = [cookie_value, *keys.map { |key| cookie_params[key] }].join('; ')
506
- cookie, = HTTP::Cookie.parse(cookie_text, url, :created_at => date)
507
- cookie2, = HTTP::Cookie.parse(cookie.set_cookie_value, url, :created_at => date)
508
-
509
- assert_equal(cookie.name, cookie2.name)
510
- assert_equal(cookie.value, cookie2.value)
511
- assert_equal(cookie.domain, cookie2.domain)
512
- assert_equal(cookie.for_domain?, cookie2.for_domain?)
513
- assert_equal(cookie.path, cookie2.path)
514
- assert_equal(cookie.expires, cookie2.expires)
515
- if keys.include?('max-age')
516
- assert_equal(date + 1000, cookie2.expires)
517
- elsif keys.include?('expires')
518
- assert_equal(@expires, cookie2.expires)
519
- else
520
- assert_equal(nil, cookie2.expires)
521
- end
522
- assert_equal(cookie.secure?, cookie2.secure?)
523
- assert_equal(cookie.httponly?, cookie2.httponly?)
524
- end
525
- }
526
- end
527
-
528
- def test_parse_cookie_no_spaces
529
- url = URI.parse('http://rubyforge.org/')
530
- cookie_params = @cookie_params
531
- cookie_value = '12345%7D=ASDFWEE345%3DASda'
532
-
533
- cookie_params.keys.combine.each do |keys|
534
- cookie_text = [cookie_value, *keys.map { |key| cookie_params[key] }].join(';')
535
- cookie, = HTTP::Cookie.parse(cookie_text, url)
536
-
537
- assert_equal('12345%7D=ASDFWEE345%3DASda', cookie.to_s)
538
- assert_equal('/', cookie.path)
539
-
540
- assert_equal(keys.include?('expires') ? @expires : nil, cookie.expires)
541
- assert_equal(keys.include?('httponly'), cookie.httponly?)
542
- end
543
- end
544
-
545
- def test_new
546
- cookie = HTTP::Cookie.new('key', 'value')
547
- assert_equal 'key', cookie.name
548
- assert_equal 'value', cookie.value
549
- assert_equal nil, cookie.expires
550
- assert_raises(RuntimeError) {
551
- cookie.acceptable?
552
- }
553
-
554
- # Minimum unit for the expires attribute is second
555
- expires = Time.at((Time.now + 3600).to_i)
556
-
557
- cookie = HTTP::Cookie.new('key', 'value', :expires => expires.dup)
558
- assert_equal 'key', cookie.name
559
- assert_equal 'value', cookie.value
560
- assert_equal expires, cookie.expires
561
- assert_raises(RuntimeError) {
562
- cookie.acceptable?
563
- }
564
-
565
- # various keywords
566
- [
567
- ["Expires", /use downcased symbol/],
568
- ].each { |key, pattern|
569
- assert_warning(pattern, "warn of key: #{key.inspect}") {
570
- cookie = HTTP::Cookie.new(:value => 'value', :name => 'key', key => expires.dup)
571
- assert_equal 'key', cookie.name
572
- assert_equal 'value', cookie.value
573
- assert_equal expires, cookie.expires, "key: #{key.inspect}"
574
- }
575
- }
576
- [
577
- [:Expires, /unknown attribute name/],
578
- [:expires?, /unknown attribute name/],
579
- [[:expires], /invalid keyword/],
580
- ].each { |key, pattern|
581
- assert_warning(pattern, "warn of key: #{key.inspect}") {
582
- cookie = HTTP::Cookie.new(:value => 'value', :name => 'key', key => expires.dup)
583
- assert_equal 'key', cookie.name
584
- assert_equal 'value', cookie.value
585
- assert_equal nil, cookie.expires, "key: #{key.inspect}"
586
- }
587
- }
588
-
589
- cookie = HTTP::Cookie.new(:value => 'value', :name => 'key', :expires => expires.dup)
590
- assert_equal 'key', cookie.name
591
- assert_equal 'value', cookie.value
592
- assert_equal expires, cookie.expires
593
- assert_equal false, cookie.for_domain?
594
- assert_raises(RuntimeError) {
595
- # domain and path are missing
596
- cookie.acceptable?
597
- }
598
-
599
- cookie = HTTP::Cookie.new(:value => 'value', :name => 'key', :expires => expires.dup, :domain => '.example.com')
600
- assert_equal 'key', cookie.name
601
- assert_equal 'value', cookie.value
602
- assert_equal expires, cookie.expires
603
- assert_equal true, cookie.for_domain?
604
- assert_raises(RuntimeError) {
605
- # path is missing
606
- cookie.acceptable?
607
- }
608
-
609
- cookie = HTTP::Cookie.new(:value => 'value', :name => 'key', :expires => expires.dup, :domain => 'example.com', :for_domain => false)
610
- assert_equal 'key', cookie.name
611
- assert_equal 'value', cookie.value
612
- assert_equal expires, cookie.expires
613
- assert_equal false, cookie.for_domain?
614
- assert_raises(RuntimeError) {
615
- # path is missing
616
- cookie.acceptable?
617
- }
618
-
619
- cookie = HTTP::Cookie.new(:value => 'value', :name => 'key', :expires => expires.dup, :domain => 'example.org', :for_domain? => true)
620
- assert_equal 'key', cookie.name
621
- assert_equal 'value', cookie.value
622
- assert_equal expires, cookie.expires
623
- assert_equal 'example.org', cookie.domain
624
- assert_equal true, cookie.for_domain?
625
- assert_raises(RuntimeError) {
626
- # path is missing
627
- cookie.acceptable?
628
- }
629
-
630
- assert_raises(ArgumentError) { HTTP::Cookie.new() }
631
- assert_raises(ArgumentError) { HTTP::Cookie.new(:value => 'value') }
632
- assert_raises(ArgumentError) { HTTP::Cookie.new('', 'value') }
633
- assert_raises(ArgumentError) { HTTP::Cookie.new('key=key', 'value') }
634
- assert_raises(ArgumentError) { HTTP::Cookie.new("key\tkey", 'value') }
635
- assert_raises(ArgumentError) { HTTP::Cookie.new('key', 'value', 'something') }
636
- assert_raises(ArgumentError) { HTTP::Cookie.new('key', 'value', {}, 'something') }
637
-
638
- [
639
- HTTP::Cookie.new(:name => 'name'),
640
- HTTP::Cookie.new("key", nil, :for_domain => true),
641
- HTTP::Cookie.new("key", nil),
642
- HTTP::Cookie.new("key", :secure => true),
643
- HTTP::Cookie.new("key"),
644
- ].each { |cookie|
645
- assert_equal '', cookie.value
646
- assert_equal true, cookie.expired?
647
- }
648
-
649
- [
650
- HTTP::Cookie.new(:name => 'name', :max_age => 3600),
651
- HTTP::Cookie.new("key", nil, :expires => Time.now + 3600),
652
- HTTP::Cookie.new("key", :expires => Time.now + 3600),
653
- HTTP::Cookie.new("key", :expires => Time.now + 3600, :value => nil),
654
- ].each { |cookie|
655
- assert_equal '', cookie.value
656
- assert_equal false, cookie.expired?
657
- }
658
- end
659
-
660
- def cookie_values(options = {})
661
- {
662
- :name => 'Foo',
663
- :value => 'Bar',
664
- :path => '/',
665
- :expires => Time.now + (10 * 86400),
666
- :for_domain => true,
667
- :domain => 'rubyforge.org',
668
- :origin => 'http://rubyforge.org/'
669
- }.merge(options)
670
- end
671
-
672
- def test_bad_name
673
- [
674
- "a\tb", "a\vb", "a\rb", "a\nb", 'a b',
675
- "a\\b", 'a"b', # 'a:b', 'a/b', 'a[b]',
676
- 'a=b', 'a,b', 'a;b',
677
- ].each { |name|
678
- assert_raises(ArgumentError) {
679
- HTTP::Cookie.new(cookie_values(:name => name))
680
- }
681
- cookie = HTTP::Cookie.new(cookie_values)
682
- assert_raises(ArgumentError) {
683
- cookie.name = name
684
- }
685
- }
686
- end
687
-
688
- def test_bad_value
689
- [
690
- "a\tb", "a\vb", "a\rb", "a\nb",
691
- "a\\b", 'a"b', # 'a:b', 'a/b', 'a[b]',
692
- ].each { |name|
693
- assert_raises(ArgumentError) {
694
- HTTP::Cookie.new(cookie_values(:name => name))
695
- }
696
- cookie = HTTP::Cookie.new(cookie_values)
697
- assert_raises(ArgumentError) {
698
- cookie.name = name
699
- }
700
- }
701
- end
702
-
703
- def test_compare
704
- time = Time.now
705
- cookies = [
706
- { :created_at => time + 1 },
707
- { :created_at => time - 1 },
708
- { :created_at => time },
709
- { :created_at => time, :path => '/foo/bar/' },
710
- { :created_at => time, :path => '/foo/' },
711
- { :created_at => time, :path => '/foo' },
712
- ].map { |attrs| HTTP::Cookie.new(cookie_values(attrs)) }
713
-
714
- assert_equal([3, 4, 5, 1, 2, 0], cookies.sort.map { |i|
715
- cookies.find_index { |j| j.equal?(i) }
716
- })
717
- end
718
-
719
- def test_expiration
720
- cookie = HTTP::Cookie.new(cookie_values)
721
-
722
- assert_equal false, cookie.expired?
723
- assert_equal true, cookie.expired?(cookie.expires + 1)
724
- assert_equal false, cookie.expired?(cookie.expires - 1)
725
- cookie.expire!
726
- assert_equal true, cookie.expired?
727
- end
728
-
729
- def test_max_age=
730
- cookie = HTTP::Cookie.new(cookie_values)
731
- expires = cookie.expires
732
-
733
- assert_raises(ArgumentError) {
734
- cookie.max_age = "+1"
735
- }
736
- # make sure #expires is not destroyed
737
- assert_equal expires, cookie.expires
738
-
739
- assert_raises(ArgumentError) {
740
- cookie.max_age = "1.5"
741
- }
742
- # make sure #expires is not destroyed
743
- assert_equal expires, cookie.expires
744
-
745
- assert_raises(ArgumentError) {
746
- cookie.max_age = "1 day"
747
- }
748
- # make sure #expires is not destroyed
749
- assert_equal expires, cookie.expires
750
-
751
- assert_raises(TypeError) {
752
- cookie.max_age = [1]
753
- }
754
- # make sure #expires is not destroyed
755
- assert_equal expires, cookie.expires
756
-
757
- cookie.max_age = "12"
758
- assert_equal 12, cookie.max_age
759
-
760
- cookie.max_age = -3
761
- assert_equal(-3, cookie.max_age)
762
- end
763
-
764
- def test_session
765
- cookie = HTTP::Cookie.new(cookie_values)
766
-
767
- assert_equal false, cookie.session?
768
- assert_equal nil, cookie.max_age
769
-
770
- cookie.expires = nil
771
- assert_equal true, cookie.session?
772
- assert_equal nil, cookie.max_age
773
-
774
- cookie.expires = Time.now + 3600
775
- assert_equal false, cookie.session?
776
- assert_equal nil, cookie.max_age
777
-
778
- cookie.max_age = 3600
779
- assert_equal false, cookie.session?
780
- assert_equal cookie.created_at + 3600, cookie.expires
781
-
782
- cookie.max_age = nil
783
- assert_equal true, cookie.session?
784
- assert_equal nil, cookie.expires
785
- end
786
-
787
- def test_equal
788
- assert_not_equal(HTTP::Cookie.new(cookie_values),
789
- HTTP::Cookie.new(cookie_values(:value => 'bar')))
790
- end
791
-
792
- def test_new_tld_domain
793
- url = URI 'http://rubyforge.org/'
794
-
795
- tld_cookie1 = HTTP::Cookie.new(cookie_values(:domain => 'org', :origin => url))
796
- assert_equal false, tld_cookie1.for_domain?
797
- assert_equal 'org', tld_cookie1.domain
798
- assert_equal false, tld_cookie1.acceptable?
799
-
800
- tld_cookie2 = HTTP::Cookie.new(cookie_values(:domain => '.org', :origin => url))
801
- assert_equal false, tld_cookie1.for_domain?
802
- assert_equal 'org', tld_cookie2.domain
803
- assert_equal false, tld_cookie2.acceptable?
804
- end
805
-
806
- def test_new_tld_domain_from_tld
807
- url = URI 'http://org/'
808
-
809
- tld_cookie1 = HTTP::Cookie.new(cookie_values(:domain => 'org', :origin => url))
810
- assert_equal false, tld_cookie1.for_domain?
811
- assert_equal 'org', tld_cookie1.domain
812
- assert_equal true, tld_cookie1.acceptable?
813
-
814
- tld_cookie2 = HTTP::Cookie.new(cookie_values(:domain => '.org', :origin => url))
815
- assert_equal false, tld_cookie1.for_domain?
816
- assert_equal 'org', tld_cookie2.domain
817
- assert_equal true, tld_cookie2.acceptable?
818
- end
819
-
820
- def test_fall_back_rules_for_local_domains
821
- url = URI 'http://www.example.local'
822
-
823
- tld_cookie = HTTP::Cookie.new(cookie_values(:domain => '.local', :origin => url))
824
- assert_equal false, tld_cookie.acceptable?
825
-
826
- sld_cookie = HTTP::Cookie.new(cookie_values(:domain => '.example.local', :origin => url))
827
- assert_equal true, sld_cookie.acceptable?
828
- end
829
-
830
- def test_new_rejects_cookies_with_ipv4_address_subdomain
831
- url = URI 'http://192.168.0.1/'
832
-
833
- cookie = HTTP::Cookie.new(cookie_values(:domain => '.0.1', :origin => url))
834
- assert_equal false, cookie.acceptable?
835
- end
836
-
837
- def test_value
838
- cookie = HTTP::Cookie.new('name', 'value')
839
- assert_equal 'value', cookie.value
840
-
841
- cookie.value = 'new value'
842
- assert_equal 'new value', cookie.value
843
-
844
- assert_raises(ArgumentError) { cookie.value = "a\tb" }
845
- assert_raises(ArgumentError) { cookie.value = "a\nb" }
846
-
847
- assert_equal false, cookie.expired?
848
- cookie.value = nil
849
- assert_equal '', cookie.value
850
- assert_equal true, cookie.expired?
851
- end
852
-
853
- def test_path
854
- uri = URI.parse('http://example.com/foo/bar')
855
-
856
- assert_equal '/foo/bar', uri.path
857
-
858
- cookie_str = 'a=b'
859
- cookie = HTTP::Cookie.parse(cookie_str, uri).first
860
- assert '/foo/', cookie.path
861
-
862
- cookie_str = 'a=b; path=/foo'
863
- cookie = HTTP::Cookie.parse(cookie_str, uri).first
864
- assert '/foo', cookie.path
865
-
866
- uri = URI.parse('http://example.com')
867
-
868
- assert_equal '', uri.path
869
-
870
- cookie_str = 'a=b'
871
- cookie = HTTP::Cookie.parse(cookie_str, uri).first
872
- assert '/', cookie.path
873
-
874
- cookie_str = 'a=b; path=/foo'
875
- cookie = HTTP::Cookie.parse(cookie_str, uri).first
876
- assert '/foo', cookie.path
877
- end
878
-
879
- def test_domain_nil
880
- cookie = HTTP::Cookie.new('a', 'b')
881
- assert_raises(RuntimeError) {
882
- cookie.valid_for_uri?('http://example.com/')
883
- }
884
- end
885
-
886
- def test_domain=
887
- url = URI.parse('http://host.dom.example.com:8080/')
888
-
889
- cookie_str = 'a=b; domain=Example.Com'
890
- cookie = HTTP::Cookie.parse(cookie_str, url).first
891
- assert 'example.com', cookie.domain
892
-
893
- cookie.domain = DomainName(url.host)
894
- assert 'host.dom.example.com', cookie.domain
895
-
896
- cookie.domain = 'Dom.example.com'
897
- assert 'dom.example.com', cookie.domain
898
-
899
- cookie.domain = Object.new.tap { |o|
900
- def o.to_str
901
- 'Example.com'
902
- end
903
- }
904
- assert 'example.com', cookie.domain
905
-
906
- url = URI 'http://rubyforge.org/'
907
-
908
- [nil, '', '.'].each { |d|
909
- cookie = HTTP::Cookie.new('Foo', 'Bar', :path => '/')
910
- cookie.domain = d
911
- assert_equal nil, cookie.domain, "domain=#{d.inspect}"
912
- assert_equal nil, cookie.domain_name, "domain=#{d.inspect}"
913
- assert_raises(RuntimeError) {
914
- cookie.acceptable?
915
- }
916
-
917
- cookie = HTTP::Cookie.new('Foo', 'Bar', :path => '/')
918
- cookie.origin = url
919
- cookie.domain = d
920
- assert_equal url.host, cookie.domain, "domain=#{d.inspect}"
921
- assert_equal true, cookie.acceptable?, "domain=#{d.inspect}"
922
- }
923
- end
924
-
925
- def test_origin=
926
- url = URI.parse('http://example.com/path/')
927
-
928
- cookie = HTTP::Cookie.new('a', 'b')
929
- assert_raises(ArgumentError) {
930
- cookie.origin = 123
931
- }
932
- cookie.origin = url
933
- assert_equal '/path/', cookie.path
934
- assert_equal 'example.com', cookie.domain
935
- assert_equal false, cookie.for_domain
936
- assert_raises(ArgumentError) {
937
- # cannot change the origin once set
938
- cookie.origin = URI.parse('http://www.example.com/')
939
- }
940
-
941
- cookie = HTTP::Cookie.new('a', 'b', :domain => '.example.com', :path => '/')
942
- cookie.origin = url
943
- assert_equal '/', cookie.path
944
- assert_equal 'example.com', cookie.domain
945
- assert_equal true, cookie.for_domain
946
- assert_raises(ArgumentError) {
947
- # cannot change the origin once set
948
- cookie.origin = URI.parse('http://www.example.com/')
949
- }
950
-
951
- cookie = HTTP::Cookie.new('a', 'b')
952
- cookie.origin = HTTP::Cookie::URIParser.parse('http://example.com/path[]/')
953
- assert_equal '/path[]/', cookie.path
954
-
955
- cookie = HTTP::Cookie.new('a', 'b', :domain => '.example.com')
956
- cookie.origin = URI.parse('http://example.org/')
957
- assert_equal false, cookie.acceptable?
958
-
959
- cookie = HTTP::Cookie.new('a', 'b', :domain => '.example.com')
960
- cookie.origin = 'file:///tmp/test.html'
961
- assert_equal nil, cookie.path
962
-
963
- cookie = HTTP::Cookie.new('a', 'b', :domain => '.example.com', :path => '/')
964
- cookie.origin = 'file:///tmp/test.html'
965
- assert_equal false, cookie.acceptable?
966
- end
967
-
968
- def test_acceptable_from_uri?
969
- cookie = HTTP::Cookie.new(cookie_values(
970
- :domain => 'uk',
971
- :for_domain => true,
972
- :origin => nil))
973
- assert_equal false, cookie.for_domain?
974
- assert_equal true, cookie.acceptable_from_uri?('http://uk/')
975
- assert_equal false, cookie.acceptable_from_uri?('http://foo.uk/')
976
- end
977
-
978
- def test_valid_for_uri?
979
- {
980
- HTTP::Cookie.parse('a1=b',
981
- 'http://example.com/dir/file.html').first => {
982
- true => [
983
- 'http://example.com/dir/',
984
- 'http://example.com/dir/test.html',
985
- 'https://example.com/dir/',
986
- 'https://example.com/dir/test.html',
987
- ],
988
- false => [
989
- 'file:///dir/test.html',
990
- 'http://example.com/dir',
991
- 'http://example.com/dir2/test.html',
992
- 'http://www.example.com/dir/test.html',
993
- 'http://www.example.com/dir2/test.html',
994
- 'https://example.com/dir',
995
- 'https://example.com/dir2/test.html',
996
- 'https://www.example.com/dir/test.html',
997
- 'https://www.example.com/dir2/test.html',
998
- ]
999
- },
1000
- HTTP::Cookie.parse('a2=b; path=/dir2/',
1001
- 'http://example.com/dir/file.html').first => {
1002
- true => [
1003
- 'http://example.com/dir2/',
1004
- 'http://example.com/dir2/test.html',
1005
- 'https://example.com/dir2/',
1006
- 'https://example.com/dir2/test.html',
1007
- ],
1008
- false => [
1009
- 'file:///dir/test.html',
1010
- 'http://example.com/dir/test.html',
1011
- 'http://www.example.com/dir/test.html',
1012
- 'http://www.example.com/dir2',
1013
- 'http://www.example.com/dir2/test.html',
1014
- 'https://example.com/dir/test.html',
1015
- 'https://www.example.com/dir/test.html',
1016
- 'https://www.example.com/dir2',
1017
- 'https://www.example.com/dir2/test.html',
1018
- ]
1019
- },
1020
- HTTP::Cookie.parse('a3=b; domain=example.com; path=/dir2/',
1021
- URI('http://example.com/dir/file.html')).first => {
1022
- true => [
1023
- 'https://example.com/dir2/test.html',
1024
- 'http://example.com/dir2/test.html',
1025
- 'https://www.example.com/dir2/test.html',
1026
- 'http://www.example.com/dir2/test.html',
1027
- ],
1028
- false => [
1029
- 'https://example.com/dir/test.html',
1030
- 'http://example.com/dir/test.html',
1031
- 'https://www.example.com/dir/test.html',
1032
- 'http://www.example.com/dir/test.html',
1033
- 'file:///dir2/test.html',
1034
- ]
1035
- },
1036
- HTTP::Cookie.parse('a4=b; domain=example.com; path=/dir2[]/',
1037
- HTTP::Cookie::URIParser.parse('http://example.com/dir[]/file.html')).first => {
1038
- true => [
1039
- HTTP::Cookie::URIParser.parse('https://example.com/dir2[]/file.html'),
1040
- HTTP::Cookie::URIParser.parse('http://example.com/dir2[]/file.html'),
1041
- ],
1042
- false => [
1043
- HTTP::Cookie::URIParser.parse('https://example.com/dir[]/file.html'),
1044
- HTTP::Cookie::URIParser.parse('http://example.com/dir[]/file.html'),
1045
- 'file:///dir2/test.html',
1046
- ]
1047
- },
1048
- HTTP::Cookie.parse('a5=b; secure',
1049
- URI('https://example.com/dir/file.html')).first => {
1050
- true => [
1051
- 'https://example.com/dir/test.html',
1052
- ],
1053
- false => [
1054
- 'http://example.com/dir/test.html',
1055
- 'https://example.com/dir2/test.html',
1056
- 'http://example.com/dir2/test.html',
1057
- 'file:///dir2/test.html',
1058
- ]
1059
- },
1060
- HTTP::Cookie.parse('a6=b',
1061
- URI('https://example.com/')).first => {
1062
- true => [
1063
- 'https://example.com',
1064
- ],
1065
- false => [
1066
- 'file:///',
1067
- ]
1068
- },
1069
- HTTP::Cookie.parse('a7=b; path=/dir',
1070
- 'http://example.com/dir/file.html').first => {
1071
- true => [
1072
- 'http://example.com/dir',
1073
- 'http://example.com/dir/',
1074
- 'http://example.com/dir/test.html',
1075
- 'https://example.com/dir',
1076
- 'https://example.com/dir/',
1077
- 'https://example.com/dir/test.html',
1078
- ],
1079
- false => [
1080
- 'file:///dir/test.html',
1081
- 'http://example.com/dir2',
1082
- 'http://example.com/dir2/test.html',
1083
- 'http://www.example.com/dir/test.html',
1084
- 'http://www.example.com/dir2/test.html',
1085
- 'https://example.com/dir2',
1086
- 'https://example.com/dir2/test.html',
1087
- 'https://www.example.com/dir/test.html',
1088
- 'https://www.example.com/dir2/test.html',
1089
- ]
1090
- },
1091
- }.each { |cookie, hash|
1092
- hash.each { |expected, urls|
1093
- urls.each { |url|
1094
- assert_equal expected, cookie.valid_for_uri?(url), '%s: %s' % [cookie.name, url]
1095
- assert_equal expected, cookie.valid_for_uri?(HTTP::Cookie::URIParser.parse(url)), "%s: URI(%s)" % [cookie.name, url]
1096
- }
1097
- }
1098
- }
1099
- end
1100
-
1101
- if YAML.name == 'Psych' && Psych::VERSION >= '3.1'
1102
- private def load_yaml(yaml)
1103
- YAML.safe_load(yaml, :permitted_classes => %w[Time HTTP::Cookie Mechanize::Cookie DomainName], :aliases => true)
1104
- end
1105
- else
1106
- private def load_yaml(yaml)
1107
- YAML.load(yaml)
1108
- end
1109
- end
1110
-
1111
- def test_yaml_expires
1112
- require 'yaml'
1113
- cookie = HTTP::Cookie.new(cookie_values)
1114
-
1115
- assert_equal false, cookie.session?
1116
- assert_equal nil, cookie.max_age
1117
-
1118
- ycookie = load_yaml(cookie.to_yaml)
1119
- assert_equal false, ycookie.session?
1120
- assert_equal nil, ycookie.max_age
1121
- assert_in_delta cookie.expires, ycookie.expires, 1
1122
-
1123
- cookie.expires = nil
1124
- ycookie = load_yaml(cookie.to_yaml)
1125
- assert_equal true, ycookie.session?
1126
- assert_equal nil, ycookie.max_age
1127
-
1128
- cookie.expires = Time.now + 3600
1129
- ycookie = load_yaml(cookie.to_yaml)
1130
- assert_equal false, ycookie.session?
1131
- assert_equal nil, ycookie.max_age
1132
- assert_in_delta cookie.expires, ycookie.expires, 1
1133
-
1134
- cookie.max_age = 3600
1135
- ycookie = load_yaml(cookie.to_yaml)
1136
- assert_equal false, ycookie.session?
1137
- assert_in_delta cookie.created_at + 3600, ycookie.expires, 1
1138
-
1139
- cookie.max_age = nil
1140
- ycookie = load_yaml(cookie.to_yaml)
1141
- assert_equal true, ycookie.session?
1142
- assert_equal nil, ycookie.expires
1143
- end
1144
-
1145
- def test_s_path_match?
1146
- assert_equal true, HTTP::Cookie.path_match?('/admin/', '/admin/index')
1147
- assert_equal false, HTTP::Cookie.path_match?('/admin/', '/Admin/index')
1148
- assert_equal true, HTTP::Cookie.path_match?('/admin/', '/admin/')
1149
- assert_equal false, HTTP::Cookie.path_match?('/admin/', '/admin')
1150
-
1151
- assert_equal true, HTTP::Cookie.path_match?('/admin', '/admin')
1152
- assert_equal false, HTTP::Cookie.path_match?('/admin', '/Admin')
1153
- assert_equal false, HTTP::Cookie.path_match?('/admin', '/admins')
1154
- assert_equal true, HTTP::Cookie.path_match?('/admin', '/admin/')
1155
- assert_equal true, HTTP::Cookie.path_match?('/admin', '/admin/index')
1156
- end
1157
- end