mechanize 2.14.0 → 2.14.2

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.
Files changed (83) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +27 -1
  3. data/README.md +7 -0
  4. data/SECURITY.md +11 -0
  5. data/lib/mechanize/directory_saver.rb +2 -1
  6. data/lib/mechanize/file_saver.rb +2 -0
  7. data/lib/mechanize/http/agent.rb +83 -29
  8. data/lib/mechanize/parser.rb +33 -3
  9. data/lib/mechanize/test_case.rb +2 -9
  10. data/lib/mechanize/version.rb +1 -1
  11. data/lib/mechanize.rb +12 -2
  12. data/test/htdocs/frame_test.html +8 -6
  13. data/test/htdocs/relative/tc_relative_links.html +1 -1
  14. metadata +7 -174
  15. data/.autotest +0 -6
  16. data/.github/dependabot.yml +0 -11
  17. data/.github/workflows/ci.yml +0 -43
  18. data/.github/workflows/upstream.yml +0 -51
  19. data/.gitignore +0 -15
  20. data/.yardopts +0 -8
  21. data/Gemfile +0 -12
  22. data/Rakefile +0 -56
  23. data/examples/flickr_upload.rb +0 -22
  24. data/examples/latest_user_agents.rb +0 -100
  25. data/examples/mech-dump.rb +0 -5
  26. data/examples/proxy_req.rb +0 -7
  27. data/examples/rubygems.rb +0 -23
  28. data/examples/spider.rb +0 -22
  29. data/examples/wikipedia_links_to_philosophy.rb +0 -158
  30. data/mechanize.gemspec +0 -74
  31. data/test/data/htpasswd +0 -1
  32. data/test/data/server.crt +0 -16
  33. data/test/data/server.csr +0 -12
  34. data/test/data/server.key +0 -15
  35. data/test/data/server.pem +0 -15
  36. data/test/test_mechanize.rb +0 -1382
  37. data/test/test_mechanize_cookie.rb +0 -559
  38. data/test/test_mechanize_cookie_jar.rb +0 -615
  39. data/test/test_mechanize_directory_saver.rb +0 -60
  40. data/test/test_mechanize_download.rb +0 -102
  41. data/test/test_mechanize_element_not_found_error.rb +0 -16
  42. data/test/test_mechanize_file.rb +0 -118
  43. data/test/test_mechanize_file_connection.rb +0 -40
  44. data/test/test_mechanize_file_request.rb +0 -26
  45. data/test/test_mechanize_file_response.rb +0 -48
  46. data/test/test_mechanize_file_saver.rb +0 -22
  47. data/test/test_mechanize_form.rb +0 -1025
  48. data/test/test_mechanize_form_check_box.rb +0 -49
  49. data/test/test_mechanize_form_encoding.rb +0 -110
  50. data/test/test_mechanize_form_field.rb +0 -78
  51. data/test/test_mechanize_form_file_upload.rb +0 -21
  52. data/test/test_mechanize_form_image_button.rb +0 -13
  53. data/test/test_mechanize_form_keygen.rb +0 -34
  54. data/test/test_mechanize_form_multi_select_list.rb +0 -98
  55. data/test/test_mechanize_form_option.rb +0 -60
  56. data/test/test_mechanize_form_radio_button.rb +0 -96
  57. data/test/test_mechanize_form_select_list.rb +0 -81
  58. data/test/test_mechanize_form_textarea.rb +0 -53
  59. data/test/test_mechanize_headers.rb +0 -36
  60. data/test/test_mechanize_history.rb +0 -104
  61. data/test/test_mechanize_http_agent.rb +0 -1915
  62. data/test/test_mechanize_http_auth_challenge.rb +0 -64
  63. data/test/test_mechanize_http_auth_realm.rb +0 -56
  64. data/test/test_mechanize_http_auth_store.rb +0 -233
  65. data/test/test_mechanize_http_content_disposition_parser.rb +0 -167
  66. data/test/test_mechanize_http_www_authenticate_parser.rb +0 -204
  67. data/test/test_mechanize_image.rb +0 -9
  68. data/test/test_mechanize_link.rb +0 -171
  69. data/test/test_mechanize_page.rb +0 -295
  70. data/test/test_mechanize_page_encoding.rb +0 -215
  71. data/test/test_mechanize_page_frame.rb +0 -17
  72. data/test/test_mechanize_page_image.rb +0 -191
  73. data/test/test_mechanize_page_link.rb +0 -377
  74. data/test/test_mechanize_page_meta_refresh.rb +0 -151
  75. data/test/test_mechanize_parser.rb +0 -316
  76. data/test/test_mechanize_pluggable_parser.rb +0 -68
  77. data/test/test_mechanize_redirect_limit_reached_error.rb +0 -25
  78. data/test/test_mechanize_redirect_not_get_or_head_error.rb +0 -15
  79. data/test/test_mechanize_response_read_error.rb +0 -29
  80. data/test/test_mechanize_subclass.rb +0 -23
  81. data/test/test_mechanize_util.rb +0 -144
  82. data/test/test_mechanize_xml_file.rb +0 -30
  83. data/test/test_multi_select.rb +0 -120
@@ -1,559 +0,0 @@
1
- # frozen_string_literal: true
2
- require 'mechanize/test_case'
3
-
4
- module Enumerable
5
- def combine
6
- masks = inject([[], 1]){|(ar, m), e| [ar << m, m << 1 ] }[0]
7
- all = masks.inject(0){ |al, m| al|m }
8
-
9
- result = []
10
- for i in 1..all do
11
- tmp = []
12
- each_with_index do |e, idx|
13
- tmp << e unless (masks[idx] & i) == 0
14
- end
15
- result << tmp
16
- end
17
- result
18
- end
19
- end
20
-
21
- class TestMechanizeCookie < Mechanize::TestCase
22
- def assert_cookie_parse url, cookie_text, &block
23
- cookie = nil
24
-
25
- block ||= proc { |p_cookie| cookie = p_cookie }
26
-
27
- exp_re = /The call of Mechanize::Cookie.parse/
28
- assert_output "", exp_re do
29
- Mechanize::Cookie.parse(url, cookie_text, &block)
30
- end
31
-
32
- cookie
33
- end
34
-
35
- alias silently capture_io
36
-
37
- def test_parse_dates
38
- url = URI.parse('http://localhost/')
39
-
40
- yesterday = Time.now - 86400
41
-
42
- dates = [ "14 Apr 89 03:20:12",
43
- "14 Apr 89 03:20 GMT",
44
- "Fri, 17 Mar 89 4:01:33",
45
- "Fri, 17 Mar 89 4:01 GMT",
46
- "Mon Jan 16 16:12 PDT 1989",
47
- #"Mon Jan 16 16:12 +0130 1989",
48
- "6 May 1992 16:41-JST (Wednesday)",
49
- #"22-AUG-1993 10:59:12.82",
50
- "22-AUG-1993 10:59pm",
51
- "22-AUG-1993 12:59am",
52
- "22-AUG-1993 12:59 PM",
53
- #"Friday, August 04, 1995 3:54 PM",
54
- #"06/21/95 04:24:34 PM",
55
- #"20/06/95 21:07",
56
- #"95-06-08 19:32:48 EDT",
57
- ]
58
-
59
- dates.each do |date|
60
- cookie = "PREF=1; expires=#{date}"
61
- silently do
62
- Mechanize::Cookie.parse(url, cookie) { |c|
63
- assert c.expires, "Tried parsing: #{date}"
64
- assert_equal(true, c.expires < yesterday)
65
- }
66
- end
67
- end
68
- end
69
-
70
- def test_parse_empty
71
- cookie_str = 'a=b; ; c=d'
72
-
73
- uri = URI.parse 'http://example'
74
-
75
- assert_cookie_parse uri, cookie_str do |cookie|
76
- assert_equal 'a', cookie.name
77
- assert_equal 'b', cookie.value
78
- end
79
- end
80
-
81
- def test_parse_no_space
82
- cookie_str = "foo=bar;Expires=Sun, 06 Nov 2011 00:28:06 GMT;Path=/"
83
-
84
- uri = URI.parse 'http://example'
85
-
86
- assert_cookie_parse uri, cookie_str do |cookie|
87
- assert_equal 'foo', cookie.name
88
- assert_equal 'bar', cookie.value
89
- assert_equal '/', cookie.path
90
- assert_equal Time.at(1320539286), cookie.expires
91
- end
92
- end
93
-
94
- def test_parse_quoted
95
- cookie_str =
96
- "quoted=\"value\"; Expires=Sun, 06 Nov 2011 00:11:18 GMT; Path=/"
97
-
98
- uri = URI.parse 'http://example'
99
-
100
- assert_cookie_parse uri, cookie_str do |cookie|
101
- assert_equal 'quoted', cookie.name
102
- assert_equal 'value', cookie.value
103
- end
104
- end
105
-
106
- def test_parse_weird_cookie
107
- cookie = 'n/a, ASPSESSIONIDCSRRQDQR=FBLDGHPBNDJCPCGNCPAENELB; path=/'
108
- url = URI.parse('http://www.searchinnovation.com/')
109
- assert_cookie_parse url, cookie do |c|
110
- assert_equal('ASPSESSIONIDCSRRQDQR', c.name)
111
- assert_equal('FBLDGHPBNDJCPCGNCPAENELB', c.value)
112
- end
113
- end
114
-
115
- def test_double_semicolon
116
- double_semi = 'WSIDC=WEST;; domain=.williams-sonoma.com; path=/'
117
- url = URI.parse('http://williams-sonoma.com/')
118
- assert_cookie_parse url, double_semi do |cookie|
119
- assert_equal('WSIDC', cookie.name)
120
- assert_equal('WEST', cookie.value)
121
- end
122
- end
123
-
124
- def test_parse_bad_version
125
- 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;'
126
- url = URI.parse('http://localhost/')
127
-
128
- assert_cookie_parse url, bad_cookie do |cookie|
129
- assert_nil(cookie.version)
130
- end
131
- end
132
-
133
- def test_parse_bad_max_age
134
- bad_cookie = 'PRETANET=TGIAqbFXtt; Name=/PRETANET; Path=/; Max-Age=1.2; Content-type=text/html; Domain=192.168.6.196; expires=Friday, 13-November-2026 23:01:46 GMT;'
135
- url = URI.parse('http://localhost/')
136
-
137
- assert_cookie_parse url, bad_cookie do |cookie|
138
- assert_nil(cookie.max_age)
139
- end
140
- end
141
-
142
- def test_parse_date_fail
143
- url = URI.parse('http://localhost/')
144
-
145
- dates = [
146
- "20/06/95 21:07",
147
- ]
148
-
149
- silently do
150
- dates.each do |date|
151
- cookie = "PREF=1; expires=#{date}"
152
- Mechanize::Cookie.parse(url, cookie) { |c|
153
- assert_equal(true, c.expires.nil?)
154
- }
155
- end
156
- end
157
- end
158
-
159
- def test_parse_domain_dot
160
- url = URI.parse('http://host.example.com/')
161
-
162
- cookie_str = 'a=b; domain=.example.com'
163
-
164
- cookie = assert_cookie_parse url, cookie_str
165
-
166
- assert_equal 'example.com', cookie.domain
167
- assert cookie.for_domain?
168
- end
169
-
170
- def test_parse_domain_no_dot
171
- url = URI.parse('http://host.example.com/')
172
-
173
- cookie_str = 'a=b; domain=example.com'
174
-
175
- cookie = assert_cookie_parse url, cookie_str
176
-
177
- assert_equal 'example.com', cookie.domain
178
- assert cookie.for_domain?
179
- end
180
-
181
- def test_parse_domain_none
182
- url = URI.parse('http://example.com/')
183
-
184
- cookie_str = 'a=b;'
185
-
186
- cookie = assert_cookie_parse url, cookie_str
187
-
188
- assert_equal 'example.com', cookie.domain
189
- assert !cookie.for_domain?
190
- end
191
-
192
- def test_parse_max_age
193
- url = URI.parse('http://localhost/')
194
-
195
- date = 'Mon, 19 Feb 2012 19:26:04 GMT'
196
-
197
- cookie_text = "name=Akinori; expires=#{date}"
198
- cookie = assert_cookie_parse url, cookie_text
199
- assert_equal Time.at(1329679564), cookie.expires
200
-
201
- cookie_text = 'name=Akinori; max-age=3600'
202
- cookie = assert_cookie_parse url, cookie_text
203
- assert_in_delta Time.now + 3600, cookie.expires, 1
204
-
205
- # Max-Age has precedence over Expires
206
- cookie_text = "name=Akinori; max-age=3600; expires=#{date}"
207
- cookie = assert_cookie_parse url, cookie_text
208
-
209
- assert_in_delta Time.now + 3600, cookie.expires, 1
210
-
211
- cookie_text = "name=Akinori; expires=#{date}; max-age=3600"
212
- cookie = assert_cookie_parse url, cookie_text
213
-
214
- assert_in_delta Time.now + 3600, cookie.expires, 1
215
- end
216
-
217
- def test_parse_expires_session
218
- url = URI.parse('http://localhost/')
219
-
220
- [
221
- 'name=Akinori',
222
- 'name=Akinori; expires',
223
- 'name=Akinori; max-age',
224
- 'name=Akinori; expires=',
225
- 'name=Akinori; max-age=',
226
- ].each { |str|
227
- cookie = assert_cookie_parse url, str
228
- assert cookie.session, str
229
- }
230
-
231
- [
232
- 'name=Akinori; expires=Mon, 19 Feb 2012 19:26:04 GMT',
233
- 'name=Akinori; max-age=3600',
234
- ].each { |str|
235
- cookie = assert_cookie_parse url, str
236
- assert !cookie.session, str
237
- }
238
- end
239
-
240
- def test_parse_many
241
- url = URI 'http://localhost/'
242
- cookie_str =
243
- "name=Aaron; Domain=localhost; Expires=Sun, 06 Nov 2011 00:29:51 GMT; Path=/, " \
244
- "name=Aaron; Domain=localhost; Expires=Sun, 06 Nov 2011 00:29:51 GMT; Path=/, " \
245
- "name=Aaron; Domain=localhost; Expires=Sun, 06 Nov 2011 00:29:51 GMT; Path=/, " \
246
- "name=Aaron; Domain=localhost; Expires=Sun, 06 Nov 2011 00:29:51 GMT; Path=/; HttpOnly, " \
247
- "expired=doh; Expires=Fri, 04 Nov 2011 00:29:51 GMT; Path=/, " \
248
- "a_path=some_path; Expires=Sun, 06 Nov 2011 00:29:51 GMT; Path=/some_path, " \
249
- "no_path1=no_path; Expires=Sun, 06 Nov 2011 00:29:52 GMT, no_expires=nope; Path=/, " \
250
- "no_path2=no_path; Expires=Sun, 06 Nov 2011 00:29:52 GMT; no_expires=nope; Path, " \
251
- "no_path3=no_path; Expires=Sun, 06 Nov 2011 00:29:52 GMT; no_expires=nope; Path=, " \
252
- "no_domain1=no_domain; Expires=Sun, 06 Nov 2011 00:29:53 GMT; no_expires=nope, " \
253
- "no_domain2=no_domain; Expires=Sun, 06 Nov 2011 00:29:53 GMT; no_expires=nope; Domain, " \
254
- "no_domain3=no_domain; Expires=Sun, 06 Nov 2011 00:29:53 GMT; no_expires=nope; Domain="
255
-
256
- cookies = nil
257
- silently { cookies = Mechanize::Cookie.parse url, cookie_str }
258
- assert_equal 13, cookies.length
259
-
260
- name = cookies.find { |c| c.name == 'name' }
261
- assert_equal "Aaron", name.value
262
- assert_equal "/", name.path
263
- assert_equal Time.at(1320539391), name.expires
264
-
265
- a_path = cookies.find { |c| c.name == 'a_path' }
266
- assert_equal "some_path", a_path.value
267
- assert_equal "/some_path", a_path.path
268
- assert_equal Time.at(1320539391), a_path.expires
269
-
270
- no_expires = cookies.find { |c| c.name == 'no_expires' }
271
- assert_equal "nope", no_expires.value
272
- assert_equal "/", no_expires.path
273
- assert_nil no_expires.expires
274
-
275
- no_path_cookies = cookies.select { |c| c.value == 'no_path' }
276
- assert_equal 3, no_path_cookies.size
277
- no_path_cookies.each { |c|
278
- assert_equal "/", c.path, c.name
279
- assert_equal Time.at(1320539392), c.expires, c.name
280
- }
281
-
282
- no_domain_cookies = cookies.select { |c| c.value == 'no_domain' }
283
- assert_equal 3, no_domain_cookies.size
284
- no_domain_cookies.each { |c|
285
- assert !c.for_domain?, c.name
286
- assert_equal c.domain, url.host, c.name
287
- assert_equal Time.at(1320539393), c.expires, c.name
288
- }
289
-
290
- assert cookies.find { |c| c.name == 'expired' }
291
- end
292
-
293
- def test_parse_valid_cookie
294
- url = URI.parse('http://rubygems.org/')
295
- cookie_params = {}
296
- cookie_params['expires'] = 'expires=Sun, 27-Sep-2037 00:00:00 GMT'
297
- cookie_params['path'] = 'path=/'
298
- cookie_params['domain'] = 'domain=.rubygems.org'
299
- cookie_params['httponly'] = 'HttpOnly'
300
- cookie_value = '12345%7D=ASDFWEE345%3DASda'
301
-
302
- expires = Time.parse('Sun, 27-Sep-2037 00:00:00 GMT')
303
-
304
- cookie_params.keys.combine.each do |c|
305
- cookie_text = +"#{cookie_value}; "
306
- c.each_with_index do |key, idx|
307
- if idx == (c.length - 1)
308
- cookie_text << "#{cookie_params[key]}"
309
- else
310
- cookie_text << "#{cookie_params[key]}; "
311
- end
312
- end
313
-
314
- cookie = assert_cookie_parse url, cookie_text
315
-
316
- assert_equal('12345%7D=ASDFWEE345%3DASda', cookie.to_s)
317
- assert_equal('/', cookie.path)
318
-
319
- # if expires was set, make sure we parsed it
320
- if c.find { |k| k == 'expires' }
321
- assert_equal(expires, cookie.expires)
322
- else
323
- assert_nil(cookie.expires)
324
- end
325
- end
326
- end
327
-
328
- def test_parse_valid_cookie_empty_value
329
- url = URI.parse('http://rubygems.org/')
330
- cookie_params = {}
331
- cookie_params['expires'] = 'expires=Sun, 27-Sep-2037 00:00:00 GMT'
332
- cookie_params['path'] = 'path=/'
333
- cookie_params['domain'] = 'domain=.rubygems.org'
334
- cookie_params['httponly'] = 'HttpOnly'
335
- cookie_value = '12345%7D='
336
-
337
- expires = Time.parse('Sun, 27-Sep-2037 00:00:00 GMT')
338
-
339
- cookie_params.keys.combine.each do |c|
340
- cookie_text = +"#{cookie_value}; "
341
- c.each_with_index do |key, idx|
342
- if idx == (c.length - 1)
343
- cookie_text << "#{cookie_params[key]}"
344
- else
345
- cookie_text << "#{cookie_params[key]}; "
346
- end
347
- end
348
- cookie = assert_cookie_parse url, cookie_text
349
-
350
- assert_equal('12345%7D=', cookie.to_s)
351
- assert_equal('', cookie.value)
352
- assert_equal('/', cookie.path)
353
-
354
- # if expires was set, make sure we parsed it
355
- if c.find { |k| k == 'expires' }
356
- assert_equal(expires, cookie.expires)
357
- else
358
- assert_nil(cookie.expires)
359
- end
360
- end
361
- end
362
-
363
- # If no path was given, use the one from the URL
364
- def test_cookie_using_url_path
365
- url = URI.parse('http://rubygems.org/login.php')
366
- cookie_params = {}
367
- cookie_params['expires'] = 'expires=Sun, 27-Sep-2037 00:00:00 GMT'
368
- cookie_params['path'] = 'path=/'
369
- cookie_params['domain'] = 'domain=.rubygems.org'
370
- cookie_params['httponly'] = 'HttpOnly'
371
- cookie_value = '12345%7D=ASDFWEE345%3DASda'
372
-
373
- expires = Time.parse('Sun, 27-Sep-2037 00:00:00 GMT')
374
-
375
- cookie_params.keys.combine.each do |c|
376
- next if c.find { |k| k == 'path' }
377
- cookie_text = +"#{cookie_value}; "
378
- c.each_with_index do |key, idx|
379
- if idx == (c.length - 1)
380
- cookie_text << "#{cookie_params[key]}"
381
- else
382
- cookie_text << "#{cookie_params[key]}; "
383
- end
384
- end
385
-
386
- cookie = assert_cookie_parse url, cookie_text
387
-
388
- assert_equal('12345%7D=ASDFWEE345%3DASda', cookie.to_s)
389
- assert_equal('/', cookie.path)
390
-
391
- # if expires was set, make sure we parsed it
392
- if c.find { |k| k == 'expires' }
393
- assert_equal(expires, cookie.expires)
394
- else
395
- assert_nil(cookie.expires)
396
- end
397
- end
398
- end
399
-
400
- # Test using secure cookies
401
- def test_cookie_with_secure
402
- url = URI.parse('http://rubygems.org/')
403
- cookie_params = {}
404
- cookie_params['expires'] = 'expires=Sun, 27-Sep-2037 00:00:00 GMT'
405
- cookie_params['path'] = 'path=/'
406
- cookie_params['domain'] = 'domain=.rubygems.org'
407
- cookie_params['secure'] = 'secure'
408
- cookie_value = '12345%7D=ASDFWEE345%3DASda'
409
-
410
- expires = Time.parse('Sun, 27-Sep-2037 00:00:00 GMT')
411
-
412
- cookie_params.keys.combine.each do |c|
413
- next unless c.find { |k| k == 'secure' }
414
- cookie_text = +"#{cookie_value}; "
415
- c.each_with_index do |key, idx|
416
- if idx == (c.length - 1)
417
- cookie_text << "#{cookie_params[key]}"
418
- else
419
- cookie_text << "#{cookie_params[key]}; "
420
- end
421
- end
422
-
423
- cookie = assert_cookie_parse url, cookie_text
424
-
425
- assert_equal('12345%7D=ASDFWEE345%3DASda', cookie.to_s)
426
- assert_equal('/', cookie.path)
427
- assert_equal(true, cookie.secure)
428
-
429
- # if expires was set, make sure we parsed it
430
- if c.find { |k| k == 'expires' }
431
- assert_equal(expires, cookie.expires)
432
- else
433
- assert_nil(cookie.expires)
434
- end
435
- end
436
- end
437
-
438
- def test_parse_cookie_no_spaces
439
- url = URI.parse('http://rubygems.org/')
440
- cookie_params = {}
441
- cookie_params['expires'] = 'expires=Sun, 27-Sep-2037 00:00:00 GMT'
442
- cookie_params['path'] = 'path=/'
443
- cookie_params['domain'] = 'domain=.rubygems.org'
444
- cookie_params['httponly'] = 'HttpOnly'
445
- cookie_value = '12345%7D=ASDFWEE345%3DASda'
446
-
447
- expires = Time.parse('Sun, 27-Sep-2037 00:00:00 GMT')
448
-
449
- cookie_params.keys.combine.each do |c|
450
- cookie_text = +"#{cookie_value};"
451
- c.each_with_index do |key, idx|
452
- if idx == (c.length - 1)
453
- cookie_text << "#{cookie_params[key]}"
454
- else
455
- cookie_text << "#{cookie_params[key]};"
456
- end
457
- end
458
-
459
- cookie = assert_cookie_parse url, cookie_text
460
-
461
- assert_equal('12345%7D=ASDFWEE345%3DASda', cookie.to_s)
462
- assert_equal('/', cookie.path)
463
-
464
- # if expires was set, make sure we parsed it
465
- if c.find { |k| k == 'expires' }
466
- assert_equal(expires, cookie.expires)
467
- else
468
- assert_nil(cookie.expires)
469
- end
470
- end
471
- end
472
-
473
- def test_new
474
- cookie = Mechanize::Cookie.new('key', 'value')
475
- assert_equal 'key', cookie.name
476
- assert_equal 'value', cookie.value
477
- assert_nil cookie.expires
478
-
479
- # Minimum unit for the expires attribute is second
480
- expires = Time.at((Time.now + 3600).to_i)
481
-
482
- cookie = Mechanize::Cookie.new('key', 'value', :expires => expires.dup)
483
- assert_equal 'key', cookie.name
484
- assert_equal 'value', cookie.value
485
- assert_equal expires, cookie.expires
486
-
487
- cookie = Mechanize::Cookie.new(:value => 'value', :name => 'key', :expires => expires.dup)
488
- assert_equal 'key', cookie.name
489
- assert_equal 'value', cookie.value
490
- assert_equal expires, cookie.expires
491
- end
492
-
493
- def test_domain=
494
- url = URI.parse('http://host.dom.example.com:8080/')
495
-
496
- cookie_str = 'a=b; domain=Example.Com'
497
- cookie = assert_cookie_parse url, cookie_str
498
- assert 'example.com', cookie.domain
499
-
500
- cookie.domain = DomainName(url.host)
501
- assert 'host.dom.example.com', cookie.domain
502
-
503
- cookie.domain = 'Dom.example.com'
504
- assert 'dom.example.com', cookie.domain
505
-
506
- new_domain = Object.new.tap { |o|
507
- def o.to_str
508
- 'Example.com'
509
- end
510
- }
511
- cookie.domain = new_domain
512
- assert 'example.com', cookie.domain
513
-
514
- new_domain = Object.new.tap { |o|
515
- def o.to_str
516
- 'Example2.com'
517
- end
518
- }
519
- assert_output nil, /The call of Mechanize::Cookie#set_domain/ do
520
- cookie.set_domain(new_domain)
521
- end
522
- assert 'example2.com', cookie.domain
523
- end
524
-
525
- def test_cookie_httponly
526
- url = URI.parse('http://rubygems.org/')
527
- cookie_params = {}
528
- cookie_params['httponly'] = 'HttpOnly'
529
- cookie_value = '12345%7D=ASDFWEE345%3DASda'
530
-
531
- expires = Time.parse('Sun, 27-Sep-2037 00:00:00 GMT')
532
-
533
- cookie_params.keys.combine.each do |c|
534
- cookie_text = +"#{cookie_value}; "
535
- c.each_with_index do |key, idx|
536
- if idx == (c.length - 1)
537
- cookie_text << "#{cookie_params[key]}"
538
- else
539
- cookie_text << "#{cookie_params[key]}; "
540
- end
541
- end
542
-
543
- cookie = assert_cookie_parse url, cookie_text
544
-
545
- assert_equal(true, cookie.httponly)
546
-
547
-
548
- # if expires was set, make sure we parsed it
549
- if c.find { |k| k == 'expires' }
550
- assert_equal(expires, cookie.expires)
551
- else
552
- assert_nil(cookie.expires)
553
- end
554
- end
555
- end
556
-
557
-
558
- end
559
-