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,1915 +0,0 @@
1
- # coding: utf-8
2
- # frozen_string_literal: true
3
-
4
- require 'mechanize/test_case'
5
- unless RUBY_PLATFORM == 'java'
6
- require 'brotli'
7
- require 'zstd-ruby'
8
- end
9
-
10
- class TestMechanizeHttpAgent < Mechanize::TestCase
11
-
12
- def setup
13
- super
14
-
15
- @agent = @mech.agent
16
-
17
- @uri = URI.parse 'http://example/'
18
-
19
- @req = Net::HTTP::Get.new '/'
20
- @res = Net::HTTPOK.allocate
21
- @res.instance_variable_set :@code, 200
22
- @res.instance_variable_set :@header, {}
23
-
24
- @headers = %w[accept accept-encoding user-agent]
25
- end
26
-
27
- def auth_realm uri, scheme, type
28
- base_uri = uri + '/'
29
- realm = Mechanize::HTTP::AuthRealm.new scheme, base_uri, 'r'
30
- @agent.authenticate_methods[base_uri][type] << realm
31
-
32
- realm
33
- end
34
-
35
- def skip_if_jruby_zlib
36
- if RUBY_ENGINE == 'jruby'
37
- meth = caller_locations(1,1).first.base_label
38
- skip "#{meth}: skipped because how Zlib handles error is different in JRuby"
39
- end
40
- end
41
-
42
- def test_agent_is_named
43
- assert_equal 'mechanize', Mechanize::HTTP::Agent.new.http.name
44
- assert_equal 'unique', Mechanize::HTTP::Agent.new('unique').http.name
45
- end
46
-
47
- def test_auto_io
48
- Tempfile.open 'input' do |input_io|
49
- input_io.binmode
50
- input_io.write '12345'
51
- input_io.rewind
52
-
53
- out_io = @agent.auto_io @NAME, 1024, input_io
54
-
55
- assert_equal '12345', out_io.string
56
-
57
- assert_equal Encoding::BINARY, out_io.string.encoding if
58
- Object.const_defined? :Encoding
59
- end
60
- end
61
-
62
- def test_auto_io_chunk
63
- Tempfile.open 'input' do |input_io|
64
- chunks = []
65
-
66
- input_io.binmode
67
- input_io.write '12345'
68
- input_io.rewind
69
-
70
- @agent.auto_io @NAME, 1, input_io do |chunk|
71
- chunks << chunk
72
- end
73
-
74
- assert_equal %w[1 2 3 4 5], chunks
75
- end
76
- end
77
-
78
- def test_auto_io_tempfile
79
- @agent.max_file_buffer = 3
80
-
81
- Tempfile.open 'input' do |input_io|
82
- input_io.binmode
83
- input_io.write '12345'
84
- input_io.rewind
85
-
86
- out_io = @agent.auto_io @NAME, 1, input_io
87
-
88
- result = out_io.read
89
- assert_equal '12345', result
90
-
91
- assert_equal Encoding::BINARY, result.encoding if
92
- Object.const_defined? :Encoding
93
- end
94
- end
95
-
96
- def test_auto_io_yield
97
- Tempfile.open 'input' do |input_io|
98
- input_io.binmode
99
- input_io.write '12345'
100
- input_io.rewind
101
-
102
- out_io = @agent.auto_io @NAME, 1024, input_io do |chunk|
103
- "x#{chunk}"
104
- end
105
-
106
- assert_equal 'x12345', out_io.string
107
- end
108
- end
109
-
110
- def test_certificate_equals
111
- cert_path = File.expand_path '../data/server.crt', __FILE__
112
- cert = OpenSSL::X509::Certificate.new File.read cert_path
113
-
114
- @agent.certificate = cert
115
-
116
- assert_equal cert.to_pem, @agent.certificate.to_pem
117
- end
118
-
119
- def test_certificate_equals_file
120
- cert_path = File.expand_path '../data/server.crt', __FILE__
121
-
122
- cert = OpenSSL::X509::Certificate.new File.read cert_path
123
-
124
- @agent.certificate = cert_path
125
-
126
- assert_equal cert.to_pem, @agent.certificate.to_pem
127
- end
128
-
129
- def test_connection_for_file
130
- uri = URI.parse 'file:///nonexistent'
131
- conn = @agent.connection_for uri
132
-
133
- assert_equal Mechanize::FileConnection.new, conn
134
- end
135
-
136
- def test_connection_for_http
137
- conn = @agent.connection_for @uri
138
-
139
- assert_equal @agent.http, conn
140
- end
141
-
142
- def test_disable_keep_alive
143
- @agent.disable_keep_alive @req
144
-
145
- refute @req['connection']
146
- end
147
-
148
- def test_disable_keep_alive_no
149
- @agent.keep_alive = false
150
-
151
- @agent.disable_keep_alive @req
152
-
153
- assert_equal 'close', @req['connection']
154
- end
155
-
156
- def test_enable_gzip
157
- @agent.enable_gzip @req
158
-
159
- assert_equal 'gzip,deflate,identity', @req['accept-encoding']
160
- end
161
-
162
- def test_enable_gzip_no
163
- @agent.gzip_enabled = false
164
-
165
- @agent.enable_gzip @req
166
-
167
- assert_equal 'identity', @req['accept-encoding']
168
- end
169
-
170
- def test_fetch_file_nonexistent
171
- in_tmpdir do
172
- nonexistent = File.join Dir.pwd, 'nonexistent'
173
-
174
- uri = URI.parse "file:///#{nonexistent}"
175
-
176
- e = assert_raises Mechanize::ResponseCodeError do
177
- @agent.fetch uri
178
- end
179
-
180
- assert_match "404 => Net::HTTPNotFound for #{uri}", e.message
181
- end
182
- end
183
-
184
- def test_fetch_file_plus
185
- Tempfile.open '++plus++' do |io|
186
- content = 'plusses +++'
187
- io.write content
188
- io.rewind
189
-
190
- uri = URI.parse "file://#{Mechanize::Util.uri_escape io.path}"
191
-
192
- page = @agent.fetch uri
193
-
194
- assert_equal content, page.body
195
- assert_kind_of Mechanize::File, page
196
- end
197
- end
198
-
199
- def test_fetch_file_space
200
- foo = File.expand_path("../htdocs/dir with spaces/foo.html", __FILE__)
201
-
202
- uri = URI.parse "file://#{Mechanize::Util.uri_escape foo}"
203
-
204
- page = @agent.fetch uri
205
-
206
- assert_equal File.read(foo), page.body.gsub(/\r\n/, "\n")
207
- assert_kind_of Mechanize::Page, page
208
- end
209
-
210
- def test_fetch_head_gzip
211
- uri = @uri + '/gzip?file=index.html'
212
-
213
- page = @agent.fetch uri, :head
214
-
215
- assert_kind_of Mechanize::Page, page
216
- end
217
-
218
- def test_fetch_hooks
219
- @agent.pre_connect_hooks << proc do |agent, request|
220
- assert_equal '/index.html', request.path
221
- assert_equal @agent, agent
222
- end
223
-
224
- @agent.post_connect_hooks << proc do |agent, uri, response, body|
225
- assert_equal @agent, agent
226
- assert_equal URI('http://example/index.html'), uri
227
- assert_equal '200', response.code
228
- assert_kind_of String, body
229
- end
230
-
231
- @agent.fetch URI 'http://example/index.html'
232
- end
233
-
234
- def test_fetch_ignore_bad_chunking
235
- @agent.ignore_bad_chunking = true
236
-
237
- file = @agent.fetch 'http://example/bad_chunking'
238
-
239
- assert_equal '0123456789', file.content
240
- end
241
-
242
- def test_fetch_post_connect_hook
243
- response = nil
244
- @agent.post_connect_hooks << lambda { |_, _, res, _| response = res }
245
-
246
- @agent.fetch 'http://localhost/'
247
-
248
- assert response
249
- end
250
-
251
- def test_fetch_redirect_header
252
- page = @agent.fetch('http://example/redirect', :get,
253
- 'X-Location' => '/http_headers',
254
- 'Range' => 'bytes=0-99999')
255
-
256
- assert_match 'range|bytes=0-999', page.body
257
- end
258
-
259
- def test_fetch_server_error
260
- e = assert_raises Mechanize::ResponseCodeError do
261
- @mech.get 'http://localhost/response_code?code=500'
262
- end
263
-
264
- assert_equal '500', e.response_code
265
- end
266
-
267
- def test_fetch_allowed_error_codes
268
- @agent.allowed_error_codes = ['500']
269
-
270
- page = @mech.get 'http://localhost/response_code?code=500'
271
-
272
- assert_equal '500', page.code
273
- end
274
-
275
- def test_fetch_allowed_error_codes_int
276
- @agent.allowed_error_codes = [500]
277
-
278
- page = @mech.get 'http://localhost/response_code?code=500'
279
-
280
- assert_equal '500', page.code
281
- end
282
-
283
- def test_get_meta_refresh_header_follow_self
284
- @agent.follow_meta_refresh = true
285
- @agent.follow_meta_refresh_self = true
286
-
287
- page = Mechanize::Page.new(@uri, nil, '', 200, @mech)
288
- @res.instance_variable_set :@header, 'refresh' => ['0']
289
-
290
- refresh = @agent.get_meta_refresh @res, @uri, page
291
-
292
- assert_equal [0.0, URI('http://example/')], refresh
293
- end
294
-
295
- def test_get_meta_refresh_header_no_follow
296
- page = Mechanize::Page.new(@uri, nil, '', 200, @mech)
297
- @res.instance_variable_set :@header, 'refresh' => ['0']
298
-
299
- refresh = @agent.get_meta_refresh @res, @uri, page
300
-
301
- assert_nil refresh
302
- end
303
-
304
- def test_get_meta_refresh_header_no_follow_self
305
- @agent.follow_meta_refresh = true
306
-
307
- page = Mechanize::Page.new(@uri, nil, '', 200, @mech)
308
- @res.instance_variable_set :@header, 'refresh' => ['0']
309
-
310
- refresh = @agent.get_meta_refresh @res, @uri, page
311
-
312
- assert_nil refresh
313
- end
314
-
315
- def test_get_meta_refresh_meta_follow_self
316
- @agent.follow_meta_refresh = true
317
- @agent.follow_meta_refresh_self = true
318
-
319
- body = <<-BODY
320
- <title></title>
321
- <meta http-equiv="refresh" content="0">
322
- BODY
323
-
324
- page = Mechanize::Page.new(@uri, nil, body, 200, @mech)
325
-
326
- refresh = @agent.get_meta_refresh @res, @uri, page
327
-
328
- assert_equal [0, nil], refresh
329
- end
330
-
331
- def test_get_meta_refresh_meta_no_follow
332
- body = <<-BODY
333
- <title></title>
334
- <meta http-equiv="refresh" content="0">
335
- BODY
336
-
337
- page = Mechanize::Page.new(@uri, nil, body, 200, @mech)
338
-
339
- refresh = @agent.get_meta_refresh @res, @uri, page
340
-
341
- assert_nil refresh
342
- end
343
-
344
- def test_get_meta_refresh_meta_no_follow_self
345
- @agent.follow_meta_refresh = true
346
-
347
- body = <<-BODY
348
- <title></title>
349
- <meta http-equiv="refresh" content="0">
350
- BODY
351
-
352
- page = Mechanize::Page.new(@uri, nil, body, 200, @mech)
353
-
354
- refresh = @agent.get_meta_refresh @res, @uri, page
355
-
356
- assert_nil refresh
357
- end
358
-
359
- def test_get_robots
360
- robotstxt = @agent.get_robots 'http://localhost/robots.txt'
361
- refute_equal '', robotstxt
362
-
363
- robotstxt = @agent.get_robots 'http://localhost/response_code?code=404'
364
- assert_equal '', robotstxt
365
- end
366
-
367
- def test_hook_content_encoding_response
368
- @mech.content_encoding_hooks << lambda{|agent, uri, response, response_body_io|
369
- response['content-encoding'] = 'gzip' if response['content-encoding'] == 'agzip'}
370
-
371
- @res.instance_variable_set :@header, 'content-encoding' => %w[agzip]
372
- body_io = StringIO.new 'part'
373
- @agent.hook_content_encoding @res, @uri, body_io
374
-
375
- assert_equal 'gzip', @res['content-encoding']
376
- end
377
-
378
- def test_http_request_file
379
- uri = URI.parse 'file:///nonexistent'
380
- request = @agent.http_request uri, :get
381
-
382
- assert_kind_of Mechanize::FileRequest, request
383
- assert_equal '/nonexistent', request.path
384
- end
385
-
386
- def test_http_request_get
387
- request = @agent.http_request @uri, :get
388
-
389
- assert_kind_of Net::HTTP::Get, request
390
- assert_equal '/', request.path
391
- end
392
-
393
- def test_http_request_post
394
- request = @agent.http_request @uri, :post
395
-
396
- assert_kind_of Net::HTTP::Post, request
397
- assert_equal '/', request.path
398
- end
399
-
400
- def test_idle_timeout_equals
401
- @agent.idle_timeout = 1
402
-
403
- assert_equal 1, @agent.http.idle_timeout
404
- end
405
-
406
- def test_inflate
407
- body_io = StringIO.new "x\x9C+H,*\x01\x00\x04?\x01\xB8"
408
-
409
- result = @agent.inflate body_io
410
-
411
- assert_equal 'part', result.read
412
- end
413
-
414
- def test_post_connect
415
- @agent.post_connect_hooks << proc { |agent, uri, response, body|
416
- assert_equal @agent, agent
417
- assert_equal @res, response
418
- assert_equal 'body', body
419
- throw :called
420
- }
421
-
422
- io = StringIO.new 'body'
423
-
424
- assert_throws :called do
425
- @agent.post_connect @uri, @res, io
426
- end
427
-
428
- assert_equal 0, io.pos
429
- end
430
-
431
- def test_pre_connect
432
- @agent.pre_connect_hooks << proc { |agent, request|
433
- assert_equal @agent, agent
434
- assert_equal @req, request
435
- throw :called
436
- }
437
-
438
- assert_throws :called do
439
- @agent.pre_connect @req
440
- end
441
- end
442
-
443
- def test_request_add_headers
444
- @agent.request_add_headers @req, 'Content-Length' => 300
445
-
446
- assert_equal '300', @req['content-length']
447
- end
448
-
449
- def test_request_add_headers_etag
450
- @agent.request_add_headers @req, :etag => '300'
451
-
452
- assert_equal '300', @req['etag']
453
- end
454
-
455
- def test_request_add_headers_if_modified_since
456
- @agent.request_add_headers @req, :if_modified_since => 'some_date'
457
-
458
- assert_equal 'some_date', @req['if-modified-since']
459
- end
460
-
461
- def test_request_add_headers_none
462
- @agent.request_add_headers @req
463
-
464
- assert_equal @headers, @req.to_hash.keys.sort
465
- end
466
-
467
- def test_request_add_headers_request_headers
468
- @agent.request_headers['X-Foo'] = 'bar'
469
-
470
- @agent.request_add_headers @req
471
-
472
- assert_equal @headers + %w[x-foo], @req.to_hash.keys.sort
473
- end
474
-
475
- def test_request_add_headers_symbol
476
- e = assert_raises ArgumentError do
477
- @agent.request_add_headers @req, :content_length => 300
478
- end
479
-
480
- assert_equal 'unknown header symbol content_length', e.message
481
- end
482
-
483
- def test_request_auth_basic
484
- @agent.add_auth @uri, 'user', 'password'
485
-
486
- auth_realm @uri, 'Basic', :basic
487
-
488
- @agent.request_auth @req, @uri
489
-
490
- assert_match %r%^Basic %, @req['Authorization']
491
- end
492
-
493
- def test_request_auth_digest
494
- @agent.add_auth @uri, 'user', 'password'
495
-
496
- realm = auth_realm @uri, 'Digest', :digest
497
- @agent.digest_challenges[realm] = 'Digest realm=r, qop="auth"'
498
-
499
- @agent.request_auth @req, @uri
500
-
501
- assert_match %r%^Digest %, @req['Authorization']
502
- assert_match %r%qop=auth%, @req['Authorization']
503
-
504
- @req['Authorization'] = nil
505
- @agent.request_auth @req, @uri
506
-
507
- assert_match %r%^Digest %, @req['Authorization']
508
- assert_match %r%qop=auth%, @req['Authorization']
509
- end
510
-
511
- def test_request_auth_iis_digest
512
- @agent.add_auth @uri, 'user', 'password'
513
-
514
- realm = auth_realm @uri, 'Digest', :digest
515
- @agent.digest_challenges[realm] = 'Digest realm=r, qop="auth"'
516
-
517
- @agent.request_auth @req, @uri
518
-
519
- assert_match %r%^Digest %, @req['Authorization']
520
- assert_match %r%qop=auth%, @req['Authorization']
521
- end
522
-
523
- def test_request_auth_none
524
- @agent.request_auth @req, @uri
525
-
526
- assert_nil @req['Authorization']
527
- end
528
-
529
- def test_request_cookies
530
- uri = URI.parse 'http://host.example.com'
531
- @agent.cookie_jar.parse 'hello=world domain=.example.com', uri
532
-
533
- @agent.request_cookies @req, uri
534
-
535
- assert_equal 'hello="world domain=.example.com"', @req['Cookie']
536
- end
537
-
538
- def test_request_cookies_many
539
- uri = URI.parse 'http://host.example.com'
540
- cookie_str = 'a=b domain=.example.com, c=d domain=.example.com'
541
- @agent.cookie_jar.parse cookie_str, uri
542
-
543
- @agent.request_cookies @req, uri
544
-
545
- expected_variant1 = /a="b domain=\.example\.com"; c="d domain=\.example\.com"/
546
- expected_variant2 = /c="d domain=\.example\.com"; a="b domain=\.example\.com"/
547
-
548
- assert_match(/^(#{expected_variant1}|#{expected_variant2})$/, @req['Cookie'])
549
- end
550
-
551
- def test_request_cookies_none
552
- @agent.request_cookies @req, @uri
553
-
554
- assert_nil @req['Cookie']
555
- end
556
-
557
- def test_request_cookies_wrong_domain
558
- uri = URI.parse 'http://host.example.com'
559
- @agent.cookie_jar.parse 'hello=world domain=.example.com', uri
560
-
561
- @agent.request_cookies @req, @uri
562
-
563
- assert_nil @req['Cookie']
564
- end
565
-
566
- def test_request_host
567
- @agent.request_host @req, @uri
568
-
569
- assert_equal 'example', @req['host']
570
- end
571
-
572
- def test_request_host_nonstandard
573
- @uri.port = 81
574
-
575
- @agent.request_host @req, @uri
576
-
577
- assert_equal 'example:81', @req['host']
578
- end
579
-
580
- def test_request_language_charset
581
- @agent.request_language_charset @req
582
-
583
- assert_equal('en-us,en;q=0.5', @req['accept-language'])
584
- assert_nil(@req['accept-charset'])
585
- end
586
-
587
- def test_request_referer
588
- referer = URI.parse 'http://old.example'
589
-
590
- @agent.request_referer @req, @uri, referer
591
-
592
- assert_equal 'http://old.example', @req['referer']
593
- end
594
-
595
- def test_request_referer_https
596
- uri = URI.parse 'https://example'
597
- referer = URI.parse 'https://old.example'
598
-
599
- @agent.request_referer @req, uri, referer
600
-
601
- assert_equal 'https://old.example', @req['referer']
602
- end
603
-
604
- def test_request_referer_https_downgrade
605
- referer = URI.parse 'https://old.example'
606
-
607
- @agent.request_referer @req, @uri, referer
608
-
609
- assert_nil @req['referer']
610
- end
611
-
612
- def test_request_referer_https_downgrade_case
613
- uri = URI.parse 'http://example'
614
- referer = URI.parse 'httpS://old.example'
615
-
616
- @agent.request_referer @req, uri, referer
617
-
618
- assert_nil @req['referer']
619
- end
620
-
621
- def test_request_referer_https_upgrade
622
- uri = URI.parse 'https://example'
623
- referer = URI.parse 'http://old.example'
624
-
625
- @agent.request_referer @req, uri, referer
626
-
627
- assert_equal 'http://old.example', @req['referer']
628
- end
629
-
630
- def test_request_referer_none
631
- @agent.request_referer @req, @uri, nil
632
-
633
- assert_nil @req['referer']
634
- end
635
-
636
- def test_request_referer_strip
637
- uri = URI.parse 'http://example.com/index.html'
638
-
639
- host_path = "old.example/page.html?q=x"
640
- referer = "http://#{host_path}"
641
-
642
- [
643
- "",
644
- "@",
645
- "user1@",
646
- ":@",
647
- "user1:@",
648
- ":password1@",
649
- "user1:password1@",
650
- ].each { |userinfo|
651
- ['', '#frag'].each { |frag|
652
- url = URI.parse "http://#{userinfo}#{host_path}#{frag}"
653
-
654
- @agent.request_referer @req, uri, url
655
-
656
- assert_equal referer, @req['referer'], url
657
- }
658
- }
659
- end
660
-
661
- def test_request_user_agent
662
- @agent.request_user_agent @req
663
-
664
- assert_match %r%^Mechanize/#{Mechanize::VERSION}%, @req['user-agent']
665
-
666
- ruby_version = if RUBY_PATCHLEVEL >= 0 then
667
- "#{RUBY_VERSION}p#{RUBY_PATCHLEVEL}"
668
- else
669
- "#{RUBY_VERSION}dev#{RUBY_REVISION}"
670
- end
671
-
672
- assert_match %r%Ruby/#{ruby_version}%, @req['user-agent']
673
- end
674
-
675
- def test_resolve_bad_uri
676
- e = assert_raises ArgumentError do
677
- @agent.resolve 'google'
678
- end
679
-
680
- assert_equal 'absolute URL needed (not google)', e.message
681
- end
682
-
683
- def test_resolve_uri_without_path
684
- e = assert_raises ArgumentError do
685
- @agent.resolve 'http:%5C%5Cfoo'
686
- end
687
-
688
- assert_equal 'hierarchical URL needed (not http:%5C%5Cfoo)', e.message
689
- end
690
-
691
- def test_resolve_utf8
692
- uri = 'http://example?q=ü'
693
-
694
- resolved = @agent.resolve uri
695
-
696
- assert_equal '/?q=%C3%BC', resolved.request_uri
697
- end
698
-
699
- def test_resolve_parameters_body
700
- input_params = { :q => 'hello' }
701
-
702
- uri, params = @agent.resolve_parameters @uri, :post, input_params
703
-
704
- assert_equal 'http://example/', uri.to_s
705
- assert_equal input_params, params
706
- end
707
-
708
- def test_resolve_parameters_query
709
- uri, params = @agent.resolve_parameters @uri, :get, :q => 'hello'
710
-
711
- assert_equal 'http://example/?q=hello', uri.to_s
712
- assert_nil params
713
- end
714
-
715
- def test_resolve_parameters_query_append
716
- input_params = { :q => 'hello' }
717
- @uri.query = 'a=b'
718
-
719
- uri, params = @agent.resolve_parameters @uri, :get, input_params
720
-
721
- assert_equal 'http://example/?a=b&q=hello', uri.to_s
722
- assert_nil params
723
- end
724
-
725
- def test_resolve_slashes
726
- page = Mechanize::Page.new URI('http://example/foo/'), nil, '', 200, @mech
727
- uri = '/bar/http://example/test/'
728
-
729
- resolved = @agent.resolve uri, page
730
-
731
- assert_equal 'http://example/bar/http://example/test/', resolved.to_s
732
- end
733
-
734
- def test_response_authenticate
735
- @agent.add_auth @uri, 'user', 'password'
736
-
737
- @res.instance_variable_set :@header, 'www-authenticate' => ['Basic realm=r']
738
-
739
- @agent.response_authenticate @res, nil, @uri, @req, {}, nil, nil
740
-
741
- base_uri = @uri + '/'
742
- realm = Mechanize::HTTP::AuthRealm.new 'Basic', base_uri, 'r'
743
- assert_equal [realm], @agent.authenticate_methods[base_uri][:basic]
744
- end
745
-
746
- def test_response_authenticate_digest
747
- @agent.add_auth @uri, 'user', 'password'
748
-
749
- @res.instance_variable_set(:@header,
750
- 'www-authenticate' => ['Digest realm=r'])
751
-
752
- @agent.response_authenticate @res, nil, @uri, @req, {}, nil, nil
753
-
754
- base_uri = @uri + '/'
755
- realm = Mechanize::HTTP::AuthRealm.new 'Digest', base_uri, 'r'
756
- assert_equal [realm], @agent.authenticate_methods[base_uri][:digest]
757
-
758
- challenge = Mechanize::HTTP::AuthChallenge.new('Digest',
759
- { 'realm' => 'r' },
760
- 'Digest realm=r')
761
-
762
- assert_equal challenge, @agent.digest_challenges[realm]
763
- end
764
-
765
- def test_response_authenticate_digest_iis
766
- @agent.add_auth @uri, 'user', 'password'
767
-
768
- @res.instance_variable_set(:@header,
769
- 'www-authenticate' => ['Digest realm=r'],
770
- 'server' => ['Microsoft-IIS'])
771
- @agent.response_authenticate @res, nil, @uri, @req, {}, nil, nil
772
-
773
- base_uri = @uri + '/'
774
- realm = Mechanize::HTTP::AuthRealm.new 'Digest', base_uri, 'r'
775
- assert_equal [realm], @agent.authenticate_methods[base_uri][:iis_digest]
776
- end
777
-
778
- def test_response_authenticate_multiple
779
- @agent.add_auth @uri, 'user', 'password'
780
-
781
- @res.instance_variable_set(:@header,
782
- 'www-authenticate' =>
783
- ['Basic realm=r, Digest realm=r'])
784
-
785
- @agent.response_authenticate @res, nil, @uri, @req, {}, nil, nil
786
-
787
- base_uri = @uri + '/'
788
- realm = Mechanize::HTTP::AuthRealm.new 'Digest', base_uri, 'r'
789
- assert_equal [realm], @agent.authenticate_methods[base_uri][:digest]
790
-
791
- assert_empty @agent.authenticate_methods[base_uri][:basic]
792
- end
793
-
794
- def test_response_authenticate_no_credentials
795
- @res.instance_variable_set :@header, 'www-authenticate' => ['Basic realm=r']
796
-
797
- e = assert_raises Mechanize::UnauthorizedError do
798
- @agent.response_authenticate @res, fake_page, @uri, @req, {}, nil, nil
799
- end
800
-
801
- assert_match 'no credentials', e.message
802
- assert_match 'available realms: r', e.message
803
- end
804
-
805
- def test_response_authenticate_no_www_authenticate
806
- @agent.add_auth @uri, 'user', 'password'
807
-
808
- denied_uri = URI('http://example/denied')
809
-
810
- denied = page denied_uri, 'text/html', '', 401
811
-
812
- e = assert_raises Mechanize::UnauthorizedError do
813
- @agent.response_authenticate @res, denied, @uri, @req, {}, nil, nil
814
- end
815
-
816
- assert_equal "401 => Net::HTTPUnauthorized for #{denied_uri} -- " \
817
- "WWW-Authenticate header missing in response",
818
- e.message
819
- end
820
-
821
- def test_response_authenticate_ntlm
822
- @uri += '/ntlm'
823
- @agent.add_auth @uri, 'user', 'password'
824
-
825
- @res.instance_variable_set(:@header,
826
- 'www-authenticate' => ['Negotiate, NTLM'])
827
-
828
- begin
829
- page = @agent.response_authenticate @res, nil, @uri, @req, {}, nil, nil
830
- rescue OpenSSL::Digest::DigestError
831
- skip "It looks like OpenSSL is not configured to support MD4"
832
- end
833
-
834
- assert_equal 'ok', page.body # lame test
835
- end
836
-
837
- def test_response_authenticate_unknown
838
- @agent.add_auth @uri, 'user', 'password'
839
-
840
- page = Mechanize::File.new nil, nil, nil, 401
841
- @res.instance_variable_set(:@header,
842
- 'www-authenticate' => ['Unknown realm=r'])
843
-
844
- assert_raises Mechanize::UnauthorizedError do
845
- @agent.response_authenticate @res, page, @uri, @req, nil, nil, nil
846
- end
847
- end
848
-
849
- def test_response_content_encoding_7_bit
850
- @res.instance_variable_set :@header, 'content-encoding' => %w[7bit]
851
-
852
- body = @agent.response_content_encoding @res, StringIO.new('part')
853
-
854
- assert_equal 'part', body.read
855
- end
856
-
857
- def test_response_content_encoding_deflate
858
- @res.instance_variable_set :@header, 'content-encoding' => %w[deflate]
859
- body_io = StringIO.new "x\x9C+H,*\x01\x00\x04?\x01\xB8"
860
-
861
- body = @agent.response_content_encoding @res, body_io
862
-
863
- assert_equal 'part', body.read
864
-
865
- assert body_io.closed?
866
- end
867
-
868
- def test_response_content_encoding_deflate_chunked
869
- @res.instance_variable_set :@header, 'content-encoding' => %w[deflate]
870
- body_io = StringIO.new "x\x9C+H,*\x01\x00\x04?\x01\xB8"
871
-
872
- body = @agent.response_content_encoding @res, body_io
873
-
874
- assert_equal 'part', body.read
875
- end
876
-
877
- def test_response_content_encoding_deflate_corrupt
878
- @res.instance_variable_set :@header, 'content-encoding' => %w[deflate]
879
- body_io = StringIO.new "x\x9C+H,*\x01\x00\x04?\x01" # missing 1 byte
880
-
881
- e = assert_raises Mechanize::Error do
882
- @agent.response_content_encoding @res, body_io
883
- end
884
-
885
- assert_match %r%error handling content-encoding deflate:%, e.message
886
- assert_match %r%Zlib%, e.message
887
-
888
- assert body_io.closed?
889
- end
890
-
891
- def test_response_content_encoding_deflate_empty
892
- @res.instance_variable_set :@header, 'content-encoding' => %w[deflate]
893
-
894
- body = @agent.response_content_encoding @res, StringIO.new
895
-
896
- assert_equal '', body.read
897
- end
898
-
899
- # IIS/6.0 ASP.NET/2.0.50727 does not wrap deflate with zlib, WTF?
900
- def test_response_content_encoding_deflate_no_zlib
901
- @res.instance_variable_set :@header, 'content-encoding' => %w[deflate]
902
-
903
- body = @agent.response_content_encoding @res, StringIO.new("+H,*\001\000")
904
-
905
- assert_equal 'part', body.read
906
- end
907
-
908
- def test_response_content_encoding_gzip
909
- @res.instance_variable_set :@header, 'content-encoding' => %w[gzip]
910
- body_io = StringIO.new \
911
- "\037\213\b\0002\002\225M\000\003+H,*\001\000\306p\017I\004\000\000\000"
912
-
913
- body = @agent.response_content_encoding @res, body_io
914
-
915
- assert_equal 'part', body.read
916
-
917
- assert body_io.closed?
918
- end
919
-
920
- def test_response_content_encoding_gzip_chunked
921
- def @res.content_length() nil end
922
- @res.instance_variable_set :@header, 'content-encoding' => %w[gzip]
923
- body_io = StringIO.new \
924
- "\037\213\b\0002\002\225M\000\003+H,*\001\000\306p\017I\004\000\000\000"
925
-
926
- body = @agent.response_content_encoding @res, body_io
927
-
928
- assert_equal 'part', body.read
929
- end
930
-
931
- def test_response_content_encoding_brotli_when_brotli_not_loaded
932
- skip("only test this on jruby which doesn't have brotli support") unless RUBY_ENGINE == 'jruby'
933
-
934
- @res.instance_variable_set :@header, 'content-encoding' => %w[br]
935
- body_io = StringIO.new("content doesn't matter for this test")
936
-
937
- e = assert_raises(Mechanize::Error) do
938
- @agent.response_content_encoding(@res, body_io)
939
- end
940
- assert_includes(e.message, "cannot deflate brotli-encoded response")
941
-
942
- assert(body_io.closed?)
943
- end
944
-
945
- def test_response_content_encoding_brotli
946
- skip("jruby does not have brotli support") if RUBY_ENGINE == 'jruby'
947
-
948
- @res.instance_variable_set :@header, 'content-encoding' => %w[br]
949
- body_io = StringIO.new(Brotli.deflate("this is compressed by brotli"))
950
-
951
- body = @agent.response_content_encoding(@res, body_io)
952
-
953
- assert_equal("this is compressed by brotli", body.read)
954
- assert(body_io.closed?)
955
- end
956
-
957
- def test_response_content_encoding_brotli_corrupt
958
- skip("jruby does not have brotli support") if RUBY_ENGINE == 'jruby'
959
-
960
- @res.instance_variable_set :@header, 'content-encoding' => %w[br]
961
- body_io = StringIO.new("not a brotli payload")
962
-
963
- e = assert_raises(Mechanize::Error) do
964
- @agent.response_content_encoding(@res, body_io)
965
- end
966
- assert_includes(e.message, "error inflating brotli-encoded response")
967
- assert_kind_of(Brotli::Error, e.cause)
968
- assert(body_io.closed?)
969
- end
970
-
971
- def test_response_content_encoding_zstd_when_zstd_not_loaded
972
- skip("only test this on jruby which doesn't have zstd support") unless RUBY_ENGINE == 'jruby'
973
-
974
- @res.instance_variable_set :@header, 'content-encoding' => %w[zstd]
975
- body_io = StringIO.new("content doesn't matter for this test")
976
-
977
- e = assert_raises(Mechanize::Error) do
978
- @agent.response_content_encoding(@res, body_io)
979
- end
980
- assert_includes(e.message, 'cannot deflate zstd-encoded response')
981
-
982
- assert(body_io.closed?)
983
- end
984
-
985
- def test_response_content_encoding_zstd
986
- skip('jruby does not have zstd support') if RUBY_ENGINE == 'jruby'
987
-
988
- @res.instance_variable_set :@header, 'content-encoding' => %w[zstd]
989
- body_io = StringIO.new(Zstd.compress('this is compressed by zstd'))
990
-
991
- body = @agent.response_content_encoding(@res, body_io)
992
-
993
- assert_equal('this is compressed by zstd', body.read)
994
- assert(body_io.closed?)
995
- end
996
-
997
- def test_response_content_encoding_zstd_corrupt
998
- skip('jruby does not have zstd support') if RUBY_ENGINE == 'jruby'
999
-
1000
- @res.instance_variable_set :@header, 'content-encoding' => %w[zstd]
1001
- body_io = StringIO.new('not a zstd payload')
1002
-
1003
- e = assert_raises(Mechanize::Error) do
1004
- @agent.response_content_encoding(@res, body_io)
1005
- end
1006
- assert_includes(e.message, 'error decompressing zstd-encoded response')
1007
- assert_kind_of(RuntimeError, e.cause)
1008
- assert(body_io.closed?)
1009
- end
1010
-
1011
- def test_response_content_encoding_gzip_corrupt
1012
- log = StringIO.new
1013
- logger = Logger.new log
1014
- @agent.context.log = logger
1015
-
1016
- @res.instance_variable_set :@header, 'content-encoding' => %w[gzip]
1017
- body_io = StringIO.new \
1018
- "\037\213\b\0002\002\225M\000\003+H,*\001"
1019
-
1020
- skip_if_jruby_zlib
1021
-
1022
- e = assert_raises Mechanize::Error do
1023
- @agent.response_content_encoding @res, body_io
1024
- end
1025
-
1026
- assert_match %r%error handling content-encoding gzip:%, e.message
1027
- assert_match %r%Zlib%, e.message
1028
-
1029
- assert_match %r%unable to gunzip response: unexpected end of file%,
1030
- log.string
1031
- assert_match %r%unable to inflate response: buffer error%,
1032
- log.string
1033
-
1034
- assert body_io.closed?
1035
- end
1036
-
1037
- def test_response_content_encoding_gzip_checksum_corrupt_crc
1038
- log = StringIO.new
1039
- logger = Logger.new log
1040
- @agent.context.log = logger
1041
-
1042
- @res.instance_variable_set :@header, 'content-encoding' => %w[gzip]
1043
- body_io = StringIO.new \
1044
- "\037\213\b\0002\002\225M\000\003+H,*\001\000\306p\017J\004\000\000\000"
1045
-
1046
- body = @agent.response_content_encoding @res, body_io
1047
-
1048
- assert_equal 'part', body.read
1049
-
1050
- assert body_io.closed?
1051
-
1052
- assert_match %r%invalid compressed data -- crc error%, log.string
1053
- rescue IOError
1054
- skip_if_jruby_zlib
1055
- raise
1056
- end
1057
-
1058
- def test_response_content_encoding_gzip_checksum_corrupt_length
1059
- log = StringIO.new
1060
- logger = Logger.new log
1061
- @agent.context.log = logger
1062
-
1063
- @res.instance_variable_set :@header, 'content-encoding' => %w[gzip]
1064
- body_io = StringIO.new \
1065
- "\037\213\b\0002\002\225M\000\003+H,*\001\000\306p\017I\005\000\000\000"
1066
-
1067
- @agent.response_content_encoding @res, body_io
1068
-
1069
- assert body_io.closed?
1070
-
1071
- assert_match %r%invalid compressed data -- length error%, log.string
1072
- rescue IOError
1073
- skip_if_jruby_zlib
1074
- raise
1075
- end
1076
-
1077
- def test_response_content_encoding_gzip_checksum_truncated
1078
- log = StringIO.new
1079
- logger = Logger.new log
1080
- @agent.context.log = logger
1081
-
1082
- @res.instance_variable_set :@header, 'content-encoding' => %w[gzip]
1083
- body_io = StringIO.new \
1084
- "\037\213\b\0002\002\225M\000\003+H,*\001\000\306p\017I\004\000\000"
1085
-
1086
- @agent.response_content_encoding @res, body_io
1087
-
1088
- assert body_io.closed?
1089
-
1090
- assert_match %r%unable to gunzip response: footer is not found%, log.string
1091
- rescue IOError
1092
- skip_if_jruby_zlib
1093
- raise
1094
- end
1095
-
1096
- def test_response_content_encoding_gzip_empty
1097
- @res.instance_variable_set :@header, 'content-encoding' => %w[gzip]
1098
-
1099
- body = @agent.response_content_encoding @res, StringIO.new
1100
-
1101
- assert_equal '', body.read
1102
- end
1103
-
1104
- def test_response_content_encoding_gzip_encoding_bad
1105
- @res.instance_variable_set(:@header,
1106
- 'content-encoding' => %w[gzip],
1107
- 'content-type' => 'text/html; charset=UTF-8')
1108
-
1109
- # "test\xB2"
1110
- body_io = StringIO.new \
1111
- "\037\213\b\000*+\314N\000\003+I-.\331\004\000x\016\003\376\005\000\000\000"
1112
-
1113
- body = @agent.response_content_encoding @res, body_io
1114
-
1115
- expected = +"test\xB2"
1116
- expected.force_encoding Encoding::BINARY if have_encoding?
1117
-
1118
- content = body.read
1119
- assert_equal expected, content
1120
- assert_equal Encoding::BINARY, content.encoding if have_encoding?
1121
- end
1122
-
1123
- def test_response_content_encoding_gzip_no_footer
1124
- @res.instance_variable_set :@header, 'content-encoding' => %w[gzip]
1125
- body_io = StringIO.new \
1126
- "\037\213\b\0002\002\225M\000\003+H,*\001\000"
1127
-
1128
- body = @agent.response_content_encoding @res, body_io
1129
-
1130
- assert_equal 'part', body.read
1131
-
1132
- assert body_io.closed?
1133
- rescue IOError
1134
- skip_if_jruby_zlib
1135
- raise
1136
- end
1137
-
1138
- def test_response_content_encoding_none
1139
- @res.instance_variable_set :@header, 'content-encoding' => %w[none]
1140
-
1141
- body = @agent.response_content_encoding @res, StringIO.new('part')
1142
-
1143
- assert_equal 'part', body.read
1144
- end
1145
-
1146
- def test_response_content_encoding_empty_string
1147
- @res.instance_variable_set :@header, 'content-encoding' => %w[]
1148
-
1149
- body = @agent.response_content_encoding @res, StringIO.new('part')
1150
-
1151
- assert_equal 'part', body.read
1152
- end
1153
-
1154
- def test_response_content_encoding_identity
1155
- @res.instance_variable_set :@header, 'content-encoding' => %w[identity]
1156
-
1157
- body = @agent.response_content_encoding @res, StringIO.new('part')
1158
-
1159
- assert_equal 'part', body.read
1160
- end
1161
-
1162
- def test_response_content_encoding_tempfile_7_bit
1163
- body_io = tempfile 'part'
1164
-
1165
- @res.instance_variable_set :@header, 'content-encoding' => %w[7bit]
1166
-
1167
- body = @agent.response_content_encoding @res, body_io
1168
-
1169
- assert_equal 'part', body.read
1170
- refute body_io.closed?
1171
- ensure
1172
- begin
1173
- body_io.close! if body_io and not body_io.closed?
1174
- rescue IOError
1175
- # HACK for ruby 1.8
1176
- end
1177
- end
1178
-
1179
- def test_response_content_encoding_tempfile_gzip
1180
- body_io = tempfile "x\x9C+H,*\x01\x00\x04?\x01\xB8"
1181
- @res.instance_variable_set :@header, 'content-encoding' => %w[deflate]
1182
-
1183
- body = @agent.response_content_encoding @res, body_io
1184
-
1185
- assert_equal 'part', body.read
1186
- assert body_io.closed?
1187
- ensure
1188
- body_io.close! if body_io and not body_io.closed?
1189
- end
1190
-
1191
- def test_response_content_encoding_unknown
1192
- @res.instance_variable_set :@header, 'content-encoding' => %w[unknown]
1193
- body = StringIO.new 'part'
1194
-
1195
- e = assert_raises Mechanize::Error do
1196
- @agent.response_content_encoding @res, body
1197
- end
1198
-
1199
- assert_equal 'unsupported content-encoding: unknown', e.message
1200
- end
1201
-
1202
- def test_response_content_encoding_x_gzip
1203
- @res.instance_variable_set :@header, 'content-encoding' => %w[x-gzip]
1204
- body_io = StringIO.new \
1205
- "\037\213\b\0002\002\225M\000\003+H,*\001\000\306p\017I\004\000\000\000"
1206
-
1207
- body = @agent.response_content_encoding @res, body_io
1208
-
1209
- assert_equal 'part', body.read
1210
- end
1211
-
1212
- def test_response_cookies
1213
- uri = URI.parse 'http://host.example.com'
1214
- cookie_str = 'a=b domain=.example.com'
1215
- @res.instance_variable_set(:@header,
1216
- 'set-cookie' => [cookie_str],
1217
- 'content-type' => %w[text/html])
1218
- page = Mechanize::Page.new uri, @res, '', 200, @mech
1219
-
1220
- @agent.response_cookies @res, uri, page
1221
-
1222
- assert_equal ['a="b domain=.example.com"'],
1223
- @agent.cookie_jar.cookies(uri).map { |c| c.to_s }
1224
- end
1225
-
1226
- def test_response_cookies_many
1227
- uri = URI.parse 'http://host.example.com'
1228
- cookie1 = 'a=b domain=.example.com'
1229
- cookie2 = 'c=d domain=.example.com'
1230
- cookies = [cookie1, cookie2]
1231
- @res.instance_variable_set(:@header,
1232
- 'set-cookie' => cookies,
1233
- 'content-type' => %w[text/html])
1234
- page = Mechanize::Page.new uri, @res, '', 200, @mech
1235
-
1236
- @agent.response_cookies @res, uri, page
1237
-
1238
- cookies_from_jar = @agent.cookie_jar.cookies(uri)
1239
-
1240
- assert_equal 2, cookies_from_jar.length
1241
- assert_equal [
1242
- 'a="b domain=.example.com"',
1243
- 'c="d domain=.example.com"',
1244
- ], cookies_from_jar.sort_by { |c| c.name }.map(&:to_s)
1245
- end
1246
-
1247
- def test_response_cookies_meta
1248
- uri = URI.parse 'http://host.example.com'
1249
- cookie_str = 'a=b domain=.example.com'
1250
-
1251
- body = <<-BODY
1252
- <head>
1253
- <meta http-equiv="Set-Cookie" content="#{cookie_str}">
1254
- </head>"
1255
- BODY
1256
-
1257
- @res.instance_variable_set(:@header,
1258
- 'content-type' => %w[text/html])
1259
- page = Mechanize::Page.new uri, @res, body, 200, @mech
1260
-
1261
- @agent.response_cookies @res, uri, page
1262
-
1263
- assert_equal ['a="b domain=.example.com"'],
1264
- @agent.cookie_jar.cookies(uri).map { |c| c.to_s }
1265
- end
1266
-
1267
- def test_response_cookies_meta_bogus
1268
- uri = URI.parse 'http://host.example.com'
1269
-
1270
- body = <<-BODY
1271
- <head>
1272
- <meta http-equiv="Set-Cookie">
1273
- </head>"
1274
- BODY
1275
-
1276
- @res.instance_variable_set(:@header,
1277
- 'content-type' => %w[text/html])
1278
- page = Mechanize::Page.new uri, @res, body, 200, @mech
1279
-
1280
- @agent.response_cookies @res, uri, page
1281
-
1282
- assert_empty @agent.cookie_jar.cookies(uri)
1283
- end
1284
-
1285
- def test_response_follow_meta_refresh
1286
- uri = URI.parse 'http://example/#id+1'
1287
-
1288
- body = <<-BODY
1289
- <title></title>
1290
- <meta http-equiv="refresh" content="0">
1291
- BODY
1292
-
1293
- page = Mechanize::Page.new(uri, nil, body, 200, @mech)
1294
-
1295
- @agent.follow_meta_refresh = true
1296
- @agent.follow_meta_refresh_self = true
1297
-
1298
- page = @agent.response_follow_meta_refresh @res, uri, page, 0
1299
-
1300
- assert_equal uri, page.uri
1301
- end
1302
-
1303
- def test_response_follow_meta_refresh_limit
1304
- uri = URI.parse 'http://example/#id+1'
1305
-
1306
- body = <<-BODY
1307
- <title></title>
1308
- <meta http-equiv="refresh" content="0">
1309
- BODY
1310
-
1311
- page = Mechanize::Page.new(uri, nil, body, 200, @mech)
1312
-
1313
- @agent.follow_meta_refresh = true
1314
- @agent.follow_meta_refresh_self = true
1315
-
1316
- assert_raises Mechanize::RedirectLimitReachedError do
1317
- @agent.response_follow_meta_refresh(@res, uri, page,
1318
- @agent.redirection_limit)
1319
- end
1320
- end
1321
-
1322
- def test_response_meta_refresh_with_insecure_url
1323
- uri = URI.parse 'http://example/#id+1'
1324
-
1325
- body = <<-BODY
1326
- <title></title>
1327
- <meta http-equiv="refresh" content="0; url=file:///dev/zero">
1328
- BODY
1329
-
1330
- page = Mechanize::Page.new(uri, nil, body, 200, @mech)
1331
-
1332
- @agent.follow_meta_refresh = true
1333
-
1334
- assert_raises Mechanize::Error do
1335
- @agent.response_follow_meta_refresh(@res, uri, page,
1336
- @agent.redirection_limit)
1337
- end
1338
- end
1339
-
1340
- def test_response_parse
1341
- body = '<title>hi</title>'
1342
- @res.instance_variable_set :@header, 'content-type' => %w[text/html]
1343
-
1344
- page = @agent.response_parse @res, body, @uri
1345
-
1346
- assert_instance_of Mechanize::Page, page
1347
- assert_equal @mech, page.mech
1348
- end
1349
-
1350
- def test_response_parse_content_type_case
1351
- body = '<title>hi</title>'
1352
- @res.instance_variable_set(:@header, 'content-type' => %w[text/HTML])
1353
-
1354
- page = @agent.response_parse @res, body, @uri
1355
-
1356
- assert_instance_of Mechanize::Page, page
1357
-
1358
- assert_equal 'text/HTML', page.content_type
1359
- end
1360
-
1361
- def test_response_parse_content_type_encoding
1362
- body = '<title>hi</title>'
1363
- @res.instance_variable_set(:@header,
1364
- 'content-type' =>
1365
- %w[text/html;charset=ISO-8859-1])
1366
-
1367
- page = @agent.response_parse @res, body, @uri
1368
-
1369
- assert_instance_of Mechanize::Page, page
1370
- assert_equal @mech, page.mech
1371
-
1372
- assert_equal 'ISO-8859-1', page.encoding
1373
- assert_equal 'ISO-8859-1', page.parser.encoding
1374
- end
1375
-
1376
- def test_response_parse_content_type_encoding_broken_iso_8859_1
1377
- body = '<title>hi</title>'
1378
- @res.instance_variable_set(:@header,
1379
- 'content-type' =>
1380
- %w[text/html; charset=ISO_8859-1])
1381
-
1382
- page = @agent.response_parse @res, body, @uri
1383
-
1384
- assert_instance_of Mechanize::Page, page
1385
- assert_equal 'ISO_8859-1', page.encoding
1386
- end
1387
-
1388
- def test_response_parse_content_type_encoding_broken_utf_8
1389
- body = '<title>hi</title>'
1390
- @res.instance_variable_set(:@header,
1391
- 'content-type' =>
1392
- %w[text/html; charset=UTF8])
1393
-
1394
- page = @agent.response_parse @res, body, @uri
1395
-
1396
- assert_instance_of Mechanize::Page, page
1397
-
1398
- # as of libxml 2.12.0, the result is dependent on how libiconv is built (which aliases are supported)
1399
- # if the alias "UTF8" is defined, then the result will be "UTF-8".
1400
- # if the alias "UTF8" is not defined, then the result will be "UTF8".
1401
- # note that this alias may be defined by Nokogiri itself in its EncodingHandler class.
1402
- assert_includes ["UTF8", "UTF-8"], page.encoding
1403
- assert_includes ["UTF8", "UTF-8"], page.parser.encoding
1404
- end
1405
-
1406
- def test_response_parse_content_type_encoding_garbage
1407
- body = '<title>hi</title>'
1408
- @res.instance_variable_set(:@header,
1409
- 'content-type' =>
1410
- %w[text/html; charset=garbage_charset])
1411
-
1412
- page = @agent.response_parse @res, body, @uri
1413
-
1414
- assert_instance_of Mechanize::Page, page
1415
- assert_equal @mech, page.mech
1416
- end
1417
-
1418
- def test_response_parse_content_type_encoding_semicolon
1419
- body = '<title>hi</title>'
1420
- @res.instance_variable_set(:@header,
1421
- 'content-type' =>
1422
- %w[text/html;charset=UTF-8;])
1423
-
1424
- page = @agent.response_parse @res, body, @uri
1425
-
1426
- assert_instance_of Mechanize::Page, page
1427
-
1428
- assert_equal 'UTF-8', page.encoding
1429
- end
1430
-
1431
- def test_response_read
1432
- def @res.read_body() yield 'part' end
1433
- def @res.content_length() 4 end
1434
-
1435
- io = @agent.response_read @res, @req, @uri
1436
-
1437
- body = io.read
1438
-
1439
- assert_equal 'part', body
1440
- assert_equal Encoding::BINARY, body.encoding
1441
- end
1442
-
1443
- def test_response_read_chunked_no_trailer
1444
- @res['Transfer-Encoding'] = 'chunked'
1445
- def @res.content_length() end
1446
- def @res.read_body
1447
- yield 'a' * 10
1448
- raise EOFError
1449
- end
1450
-
1451
- e = assert_raises Mechanize::ChunkedTerminationError do
1452
- @agent.response_read @res, @req, @uri
1453
- end
1454
-
1455
- assert_equal 'aaaaaaaaaa', e.body_io.read
1456
- end
1457
-
1458
- def test_response_read_content_length_head
1459
- req = Net::HTTP::Head.new '/'
1460
-
1461
- def @res.content_length() end
1462
- def @res.read_body() end
1463
-
1464
- io = @agent.response_read @res, req, @uri
1465
-
1466
- assert_equal '', io.read
1467
- end
1468
-
1469
- def test_response_read_content_length_mismatch
1470
- def @res.content_length() 5 end
1471
- def @res.read_body() yield 'part' end
1472
-
1473
- e = assert_raises Mechanize::ResponseReadError do
1474
- @agent.response_read @res, @req, @uri
1475
- end
1476
-
1477
- assert_equal 'Content-Length (5) does not match response body length (4)' \
1478
- ' (Mechanize::ResponseReadError)', e.message
1479
- end
1480
-
1481
- def test_response_read_content_length_redirect
1482
- res = Net::HTTPFound.allocate
1483
- def res.content_length() 5 end
1484
- def res.code() 302 end
1485
- def res.read_body() yield 'part' end
1486
- res.instance_variable_set :@header, {}
1487
-
1488
- io = @agent.response_read res, @req, @uri
1489
-
1490
- assert_equal 'part', io.read
1491
- end
1492
-
1493
- def test_response_read_error
1494
- def @res.read_body()
1495
- yield 'part'
1496
- raise Net::HTTP::Persistent::Error
1497
- end
1498
-
1499
- e = assert_raises Mechanize::ResponseReadError do
1500
- @agent.response_read @res, @req, @uri
1501
- end
1502
-
1503
- assert_equal @res, e.response
1504
- assert_equal 'part', e.body_io.read
1505
- assert_kind_of Net::HTTP::Persistent::Error, e.error
1506
- end
1507
-
1508
- def test_response_read_file
1509
- Tempfile.open 'pi.txt' do |tempfile|
1510
- tempfile.write "π\n"
1511
- tempfile.flush
1512
- tempfile.rewind
1513
-
1514
- uri = URI.parse "file://#{tempfile.path}"
1515
- req = Mechanize::FileRequest.new uri
1516
- res = Mechanize::FileResponse.new tempfile.path
1517
-
1518
- io = @agent.response_read res, req, uri
1519
-
1520
- expected = "π\n".dup.force_encoding(Encoding::BINARY)
1521
-
1522
- # Ruby 1.8.7 doesn't let us set the write mode of the tempfile to binary,
1523
- # so we should expect an inserted carriage return on some platforms
1524
- expected_with_carriage_return = "π\r\n".dup.force_encoding(Encoding::BINARY)
1525
-
1526
- body = io.read
1527
- assert_match(/^(#{expected}|#{expected_with_carriage_return})$/m, body)
1528
- assert_equal Encoding::BINARY, body.encoding
1529
- end
1530
- end
1531
-
1532
- def test_response_read_large
1533
- @agent.max_file_buffer = 10240
1534
-
1535
- def @res.read_body() yield 'a' * 10241 end
1536
- def @res.content_length() 10241 end
1537
-
1538
- io = @agent.response_read @res, @req, @uri
1539
-
1540
- assert_kind_of Tempfile, io
1541
- assert_equal 10241, io.stat.size
1542
- end
1543
-
1544
- def test_response_read_large_chunked
1545
- @agent.max_file_buffer = 10240
1546
-
1547
- def @res.read_body
1548
- 11.times do yield 'a' * 1024 end
1549
- end
1550
- def @res.content_length() end
1551
-
1552
- io = @agent.response_read @res, @req, @uri
1553
-
1554
- assert_kind_of Tempfile, io
1555
- assert_equal 11264, io.stat.size
1556
- end
1557
-
1558
- def test_response_read_no_body
1559
- req = Net::HTTP::Options.new '/'
1560
-
1561
- def @res.content_length() end
1562
- def @res.read_body() end
1563
-
1564
- io = @agent.response_read @res, req, @uri
1565
-
1566
- assert_equal '', io.read
1567
- end
1568
-
1569
- def test_response_read_unknown_code
1570
- res = Net::HTTPUnknownResponse.allocate
1571
- res.instance_variable_set :@code, 9999
1572
- res.instance_variable_set :@header, {}
1573
- def res.read_body() yield 'part' end
1574
-
1575
- e = assert_raises Mechanize::ResponseCodeError do
1576
- @agent.response_read res, @req, @uri
1577
- end
1578
-
1579
- assert_equal res, e.page
1580
- end
1581
-
1582
- def test_response_redirect
1583
- @agent.redirect_ok = true
1584
- referer = page 'http://example/referer'
1585
-
1586
- page = fake_page
1587
- page = @agent.response_redirect({ 'Location' => '/index.html' }, :get,
1588
- page, 0, {}, referer)
1589
-
1590
- assert_equal URI('http://fake.example/index.html'), page.uri
1591
-
1592
- assert_equal 'http://example/referer', requests.first['Referer']
1593
- end
1594
-
1595
- def test_response_redirect_header
1596
- @agent.redirect_ok = true
1597
- referer = page 'http://example/referer'
1598
-
1599
- headers = {
1600
- 'Range' => 'bytes=0-9999',
1601
- 'Content-Type' => 'application/x-www-form-urlencoded',
1602
- 'CONTENT-LENGTH' => '9999',
1603
- 'content-md5' => '14758f1afd44c09b7992073ccf00b43d',
1604
- }
1605
-
1606
- page = fake_page
1607
- page = @agent.response_redirect({ 'Location' => '/http_headers' }, :get,
1608
- page, 0, headers, referer)
1609
-
1610
- assert_equal URI('http://fake.example/http_headers'), page.uri
1611
-
1612
- assert_match 'range|bytes=0-9999', page.body
1613
- refute_match 'content-type|application/x-www-form-urlencoded', page.body
1614
- refute_match 'content-length|9999', page.body
1615
- refute_match 'content-md5|14758f1afd44c09b7992073ccf00b43d', page.body
1616
- end
1617
-
1618
- def test_response_redirect_malformed
1619
- @agent.redirect_ok = true
1620
- referer = page 'http://example/referer'
1621
-
1622
- page = fake_page
1623
- page = @agent.response_redirect({ 'Location' => '/index.html?q=あ' }, :get,
1624
- page, 0, {}, referer)
1625
-
1626
- assert_equal URI('http://fake.example/index.html?q=%E3%81%82'), page.uri
1627
-
1628
- assert_equal 'http://example/referer', requests.first['Referer']
1629
- end
1630
-
1631
- def test_response_redirect_insecure
1632
- @agent.redirect_ok = true
1633
- referer = page 'http://example/referer'
1634
-
1635
- assert_raises Mechanize::Error do
1636
- @agent.response_redirect({ 'Location' => 'file:///etc/passwd' }, :get,
1637
- fake_page, 0, {}, referer)
1638
- end
1639
- end
1640
-
1641
- def test_response_redirect_limit
1642
- @agent.redirect_ok = true
1643
- referer = page 'http://example/referer'
1644
-
1645
- assert_raises Mechanize::RedirectLimitReachedError do
1646
- @agent.response_redirect({ 'Location' => '/index.html' }, :get,
1647
- fake_page, @agent.redirection_limit, {}, referer)
1648
- end
1649
- end
1650
-
1651
- def test_response_redirect_to_cross_site_with_credential
1652
- @agent.redirect_ok = true
1653
-
1654
- headers = {
1655
- 'Range' => 'bytes=0-9999',
1656
- 'AUTHORIZATION' => 'Basic xxx',
1657
- 'cookie' => 'name=value',
1658
- }
1659
-
1660
- page = html_page ''
1661
- page = @agent.response_redirect({ 'Location' => 'http://trap/http_headers' }, :get,
1662
- page, 0, headers)
1663
-
1664
- refute_includes(headers.keys, "AUTHORIZATION")
1665
- refute_includes(headers.keys, "cookie")
1666
-
1667
- assert_match("range|bytes=0-9999", page.body)
1668
- refute_match("authorization|Basic xxx", page.body)
1669
- refute_match("cookie|name=value", page.body)
1670
- end
1671
-
1672
- def test_response_redirect_to_same_site_with_credential
1673
- @agent.redirect_ok = true
1674
-
1675
- headers = {
1676
- 'Range' => 'bytes=0-9999',
1677
- 'AUTHORIZATION' => 'Basic xxx',
1678
- 'cookie' => 'name=value',
1679
- }
1680
-
1681
- page = html_page ''
1682
- page = @agent.response_redirect({ 'Location' => '/http_headers' }, :get,
1683
- page, 0, headers)
1684
-
1685
- assert_includes(headers.keys, "AUTHORIZATION")
1686
- assert_includes(headers.keys, "cookie")
1687
-
1688
- assert_match("range|bytes=0-9999", page.body)
1689
- assert_match("authorization|Basic xxx", page.body)
1690
- assert_match("cookie|name=value", page.body)
1691
- end
1692
-
1693
- def test_response_redirect_to_same_site_diff_port_with_credential
1694
- @agent.redirect_ok = true
1695
-
1696
- headers = {
1697
- 'Range' => 'bytes=0-9999',
1698
- 'AUTHORIZATION' => 'Basic xxx',
1699
- 'cookie' => 'name=value',
1700
- }
1701
-
1702
- page = html_page ''
1703
- page = @agent.response_redirect({ 'Location' => 'http://example:81/http_headers' }, :get,
1704
- page, 0, headers)
1705
-
1706
- refute_includes(headers.keys, "AUTHORIZATION")
1707
- assert_includes(headers.keys, "cookie")
1708
-
1709
- assert_match("range|bytes=0-9999", page.body)
1710
- refute_match("authorization|Basic xxx", page.body)
1711
- assert_match("cookie|name=value", page.body)
1712
- end
1713
-
1714
- def test_response_redirect_not_ok
1715
- @agent.redirect_ok = false
1716
-
1717
- page = fake_page
1718
- page = @agent.response_redirect({ 'Location' => '/other' }, :get, page, 0,
1719
- {}, page)
1720
-
1721
- assert_equal URI('http://fake.example'), page.uri
1722
- end
1723
-
1724
- def test_response_redirect_permanent
1725
- @agent.redirect_ok = :permanent
1726
-
1727
- response = Net::HTTPMovedPermanently.allocate
1728
- response.instance_variable_set :@header, { 'location' => %w[/index.html] }
1729
-
1730
- page = fake_page
1731
- page = @agent.response_redirect response, :get, page, 0, {}, page
1732
-
1733
- assert_equal URI('http://fake.example/index.html'), page.uri
1734
- end
1735
-
1736
- def test_response_redirect_permanent_temporary
1737
- @agent.redirect_ok = :permanent
1738
-
1739
- response = Net::HTTPMovedTemporarily.allocate
1740
- response.instance_variable_set :@header, { 'location' => %w[/index.html] }
1741
-
1742
- page = fake_page
1743
- page = @agent.response_redirect response, :get, page, 0, {}, page
1744
-
1745
- assert_equal URI('http://fake.example/'), page.uri
1746
- end
1747
-
1748
- def test_retry_change_request_equals
1749
- unless Gem::Requirement.new("< 4.0.0").satisfied_by?(Gem::Version.new(Net::HTTP::Persistent::VERSION))
1750
- # see https://github.com/drbrain/net-http-persistent/pull/100
1751
- skip("net-http-persistent 4.0.0 and later does not support retry_change_requests")
1752
- end
1753
-
1754
- refute @agent.http.retry_change_requests
1755
-
1756
- @agent.retry_change_requests = true
1757
-
1758
- assert @agent.http.retry_change_requests
1759
- end
1760
-
1761
- def test_robots_allowed_eh
1762
- allowed = URI 'http://localhost/index.html'
1763
- disallowed = URI 'http://localhost/norobots.html'
1764
-
1765
- assert @agent.robots_allowed? allowed
1766
- refute @agent.robots_allowed? disallowed
1767
-
1768
- refute @agent.robots_disallowed? allowed
1769
- assert @agent.robots_disallowed? disallowed
1770
- end
1771
-
1772
- def test_robots_allowed_eh_noindex
1773
- @agent.robots = true
1774
-
1775
- noindex = URI 'http://localhost/noindex.html'
1776
-
1777
- assert @agent.robots_allowed? noindex
1778
-
1779
- assert_raises Mechanize::RobotsDisallowedError do
1780
- @agent.fetch noindex
1781
- end
1782
- end
1783
-
1784
- def test_robots_infinite_loop
1785
- @agent.robots = true
1786
- @agent.redirect_ok = true
1787
-
1788
- assert_raises Mechanize::RobotsDisallowedError do
1789
- @agent.fetch URI('http://301/norobots.html')
1790
- end
1791
-
1792
- @agent.fetch URI('http://301/robots.html')
1793
- end
1794
-
1795
- def test_set_proxy
1796
- @agent.set_proxy 'www.example.com', 9001, 'joe', 'lol'
1797
-
1798
- assert_equal @agent.proxy_uri.host, 'www.example.com'
1799
- assert_equal @agent.proxy_uri.port, 9001
1800
- assert_equal @agent.proxy_uri.user, 'joe'
1801
- assert_equal @agent.proxy_uri.password, 'lol'
1802
- end
1803
-
1804
- def test_set_proxy_port_string
1805
- @agent.set_proxy 'www.example.com', '9001', 'joe', 'lol'
1806
-
1807
- assert_equal @agent.proxy_uri.host, 'www.example.com'
1808
- assert_equal @agent.proxy_uri.port, 9001
1809
- assert_equal @agent.proxy_uri.user, 'joe'
1810
- assert_equal @agent.proxy_uri.password, 'lol'
1811
- end
1812
-
1813
- def test_set_proxy_service_name
1814
- @agent.set_proxy 'www.example.com', 'http', 'joe', 'lol'
1815
-
1816
- assert_equal @agent.proxy_uri.host, 'www.example.com'
1817
- assert_equal @agent.proxy_uri.port, 80
1818
- assert_equal @agent.proxy_uri.user, 'joe'
1819
- assert_equal @agent.proxy_uri.password, 'lol'
1820
- end
1821
-
1822
- def test_set_proxy_service_name_bad
1823
- e = assert_raises ArgumentError do
1824
- @agent.set_proxy 'www.example.com', 'nonexistent service', 'joe', 'lol'
1825
- end
1826
-
1827
- assert_equal 'invalid value for port: "nonexistent service"', e.message
1828
- end
1829
-
1830
- def test_set_proxy_with_scheme
1831
- @agent.set_proxy 'http://www.example.com', 9001, 'joe', 'lol'
1832
-
1833
- assert_equal @agent.proxy_uri.host, 'www.example.com'
1834
- assert_equal @agent.proxy_uri.port, 9001
1835
- assert_equal @agent.proxy_uri.user, 'joe'
1836
- assert_equal @agent.proxy_uri.password, 'lol'
1837
- end
1838
-
1839
- def test_set_proxy_url
1840
- @agent.set_proxy 'http://joe:lol@www.example.com:9001'
1841
-
1842
- assert_equal @agent.proxy_uri.host, 'www.example.com'
1843
- assert_equal @agent.proxy_uri.port, 9001
1844
- assert_equal @agent.proxy_uri.user, 'joe'
1845
- assert_equal @agent.proxy_uri.password, 'lol'
1846
- end
1847
-
1848
- def test_set_proxy_uri
1849
- @agent.set_proxy URI('http://joe:lol@www.example.com:9001')
1850
-
1851
- assert_equal @agent.proxy_uri.host, 'www.example.com'
1852
- assert_equal @agent.proxy_uri.port, 9001
1853
- assert_equal @agent.proxy_uri.user, 'joe'
1854
- assert_equal @agent.proxy_uri.password, 'lol'
1855
- end
1856
-
1857
- def test_set_proxy_url_and_credentials
1858
- @agent.set_proxy 'http://www.example.com:9001', nil, 'joe', 'lol'
1859
-
1860
- assert_equal @agent.proxy_uri.host, 'www.example.com'
1861
- assert_equal @agent.proxy_uri.port, 9001
1862
- assert_equal @agent.proxy_uri.user, 'joe'
1863
- assert_equal @agent.proxy_uri.password, 'lol'
1864
- end
1865
-
1866
- def test_setting_agent_name
1867
- mech = Mechanize.new 'user-set-name'
1868
- assert_equal 'user-set-name', mech.agent.http.name
1869
- end
1870
-
1871
- def test_ssl
1872
- in_tmpdir do
1873
- store = OpenSSL::X509::Store.new
1874
- @agent.ca_file = '.'
1875
- @agent.cert_store = store
1876
- @agent.certificate = ssl_certificate
1877
- @agent.private_key = ssl_private_key
1878
- @agent.ssl_version = 'SSLv3'
1879
- @agent.verify_callback = proc { |ok, context| }
1880
-
1881
- http = @agent.http
1882
-
1883
- assert_equal '.', http.ca_file
1884
- assert_equal store, http.cert_store
1885
- assert_equal ssl_certificate, http.certificate
1886
- assert_equal ssl_private_key, http.private_key
1887
- assert_equal 'SSLv3', http.ssl_version
1888
- assert_equal OpenSSL::SSL::VERIFY_PEER, http.verify_mode
1889
- assert http.verify_callback
1890
- end
1891
- end
1892
-
1893
- def test_use_tempfile_eh
1894
- refute @agent.use_tempfile? nil
1895
-
1896
- @agent.max_file_buffer = 1
1897
-
1898
- refute @agent.use_tempfile? 0
1899
- assert @agent.use_tempfile? 1
1900
-
1901
- @agent.max_file_buffer = nil
1902
-
1903
- refute @agent.use_tempfile? 1
1904
- end
1905
-
1906
- def test_verify_none_equals
1907
- @agent.verify_mode = OpenSSL::SSL::VERIFY_NONE
1908
-
1909
- http = @agent.http
1910
-
1911
- assert_equal OpenSSL::SSL::VERIFY_NONE, http.verify_mode
1912
- end
1913
-
1914
- end
1915
-