Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Webmock fails when making ::Net::HTTP request to ipv6 address #806

Comments

@arkadiyt
Copy link
Contributor

Repro case:

  require 'webmock/rspec'
  
  it 'tests webmock' do
    uri = URI('http://[2606:4700:30::681c:88e]/path')
    Net::HTTP.start(uri.hostname, uri.port) do |http|
      http.request(Net::HTTP::Get.new(uri))
    end
  end

gives me (the extra stacktrace parts are because I'm running it on an existing project):

     Failure/Error: http.request(Net::HTTP::Get.new(uri))

     Addressable::URI::InvalidURIError:
       Invalid port number: "88e"
     # ./vendor/bundle/ruby/2.5.0/gems/addressable-2.5.2/lib/addressable/uri.rb:1373:in `port='
     # ./vendor/bundle/ruby/2.5.0/gems/addressable-2.5.2/lib/addressable/uri.rb:1251:in `authority='
     # ./vendor/bundle/ruby/2.5.0/gems/addressable-2.5.2/lib/addressable/uri.rb:805:in `block in initialize'
     # ./vendor/bundle/ruby/2.5.0/gems/addressable-2.5.2/lib/addressable/uri.rb:2355:in `defer_validation'
     # ./vendor/bundle/ruby/2.5.0/gems/addressable-2.5.2/lib/addressable/uri.rb:796:in `initialize'
     # ./vendor/bundle/ruby/2.5.0/gems/addressable-2.5.2/lib/addressable/uri.rb:2131:in `new'
     # ./vendor/bundle/ruby/2.5.0/gems/addressable-2.5.2/lib/addressable/uri.rb:2131:in `normalize'
     # ./vendor/bundle/ruby/2.5.0/gems/webmock-3.5.1/lib/webmock/util/uri.rb:20:in `block in <class:URI>'
     # ./vendor/bundle/ruby/2.5.0/gems/webmock-3.5.1/lib/webmock/util/uri.rb:33:in `normalize_uri'
     # ./vendor/bundle/ruby/2.5.0/gems/webmock-3.5.1/lib/webmock/request_signature.rb:10:in `initialize'
     # ./vendor/bundle/ruby/2.5.0/gems/webmock-3.5.1/lib/webmock/http_lib_adapters/net_http.rb:325:in `new'
     # ./vendor/bundle/ruby/2.5.0/gems/webmock-3.5.1/lib/webmock/http_lib_adapters/net_http.rb:325:in `request_signature_from_request'
     # ./vendor/bundle/ruby/2.5.0/gems/webmock-3.5.1/lib/webmock/http_lib_adapters/net_http.rb:75:in `request'
     # ./spec/bounty-targets/hackenproof_spec.rb:16:in `block (3 levels) in <top (required)>'
     # ./vendor/bundle/ruby/2.5.0/gems/webmock-3.5.1/lib/webmock/http_lib_adapters/net_http.rb:123:in `start_without_connect'
     # ./vendor/bundle/ruby/2.5.0/gems/webmock-3.5.1/lib/webmock/http_lib_adapters/net_http.rb:150:in `start'
     # /Users/arkadiyt/.rvm/rubies/ruby-2.5.0/lib/ruby/2.5.0/net/http.rb:609:in `start'
     # ./spec/bounty-targets/hackenproof_spec.rb:14:in `block (2 levels) in <top (required)>'
     # ./vendor/bundle/ruby/2.5.0/gems/rspec-core-3.8.0/lib/rspec/core/example.rb:254:in `instance_exec'
     # ./vendor/bundle/ruby/2.5.0/gems/rspec-core-3.8.0/lib/rspec/core/example.rb:254:in `block in run'
     # ./vendor/bundle/ruby/2.5.0/gems/rspec-core-3.8.0/lib/rspec/core/example.rb:500:in `block in with_around_and_singleton_context_hooks'
     # ./vendor/bundle/ruby/2.5.0/gems/rspec-core-3.8.0/lib/rspec/core/example.rb:457:in `block in with_around_example_hooks'
     # ./vendor/bundle/ruby/2.5.0/gems/rspec-core-3.8.0/lib/rspec/core/hooks.rb:464:in `block in run'
     # ./vendor/bundle/ruby/2.5.0/gems/rspec-core-3.8.0/lib/rspec/core/hooks.rb:602:in `run_around_example_hooks_for'
     # ./vendor/bundle/ruby/2.5.0/gems/rspec-core-3.8.0/lib/rspec/core/hooks.rb:464:in `run'
     # ./vendor/bundle/ruby/2.5.0/gems/rspec-core-3.8.0/lib/rspec/core/example.rb:457:in `with_around_example_hooks'
     # ./vendor/bundle/ruby/2.5.0/gems/rspec-core-3.8.0/lib/rspec/core/example.rb:500:in `with_around_and_singleton_context_hooks'
     # ./vendor/bundle/ruby/2.5.0/gems/rspec-core-3.8.0/lib/rspec/core/example.rb:251:in `run'
     # ./vendor/bundle/ruby/2.5.0/gems/rspec-core-3.8.0/lib/rspec/core/example_group.rb:629:in `block in run_examples'
     # ./vendor/bundle/ruby/2.5.0/gems/rspec-core-3.8.0/lib/rspec/core/example_group.rb:625:in `map'
     # ./vendor/bundle/ruby/2.5.0/gems/rspec-core-3.8.0/lib/rspec/core/example_group.rb:625:in `run_examples'
     # ./vendor/bundle/ruby/2.5.0/gems/rspec-core-3.8.0/lib/rspec/core/example_group.rb:591:in `run'
     # ./vendor/bundle/ruby/2.5.0/gems/rspec-core-3.8.0/lib/rspec/core/runner.rb:116:in `block (3 levels) in run_specs'
     # ./vendor/bundle/ruby/2.5.0/gems/rspec-core-3.8.0/lib/rspec/core/runner.rb:116:in `map'
     # ./vendor/bundle/ruby/2.5.0/gems/rspec-core-3.8.0/lib/rspec/core/runner.rb:116:in `block (2 levels) in run_specs'
     # ./vendor/bundle/ruby/2.5.0/gems/rspec-core-3.8.0/lib/rspec/core/configuration.rb:1989:in `with_suite_hooks'
     # ./vendor/bundle/ruby/2.5.0/gems/rspec-core-3.8.0/lib/rspec/core/runner.rb:111:in `block in run_specs'
     # ./vendor/bundle/ruby/2.5.0/gems/rspec-core-3.8.0/lib/rspec/core/reporter.rb:74:in `report'
     # ./vendor/bundle/ruby/2.5.0/gems/rspec-core-3.8.0/lib/rspec/core/runner.rb:110:in `run_specs'
     # ./vendor/bundle/ruby/2.5.0/gems/rspec-core-3.8.0/lib/rspec/core/runner.rb:87:in `run'
     # ./vendor/bundle/ruby/2.5.0/gems/rspec-core-3.8.0/lib/rspec/core/runner.rb:71:in `run'
     # ./vendor/bundle/ruby/2.5.0/gems/rspec-core-3.8.0/lib/rspec/core/runner.rb:45:in `invoke'
     # ./vendor/bundle/ruby/2.5.0/gems/rspec-core-3.8.0/exe/rspec:4:in `<top (required)>'
     # ./vendor/bundle/ruby/2.5.0/bin/rspec:23:in `load'
     # ./vendor/bundle/ruby/2.5.0/bin/rspec:23:in `<top (required)>'
     # /Users/arkadiyt/.rvm/gems/ruby-2.5.0/gems/bundler-1.16.1/lib/bundler/cli/exec.rb:75:in `load'
     # /Users/arkadiyt/.rvm/gems/ruby-2.5.0/gems/bundler-1.16.1/lib/bundler/cli/exec.rb:75:in `kernel_load'
     # /Users/arkadiyt/.rvm/gems/ruby-2.5.0/gems/bundler-1.16.1/lib/bundler/cli/exec.rb:28:in `run'
     # /Users/arkadiyt/.rvm/gems/ruby-2.5.0/gems/bundler-1.16.1/lib/bundler/cli.rb:424:in `exec'
     # /Users/arkadiyt/.rvm/gems/ruby-2.5.0/gems/bundler-1.16.1/lib/bundler/vendor/thor/lib/thor/command.rb:27:in `run'
     # /Users/arkadiyt/.rvm/gems/ruby-2.5.0/gems/bundler-1.16.1/lib/bundler/vendor/thor/lib/thor/invocation.rb:126:in `invoke_command'
     # /Users/arkadiyt/.rvm/gems/ruby-2.5.0/gems/bundler-1.16.1/lib/bundler/vendor/thor/lib/thor.rb:387:in `dispatch'
     # /Users/arkadiyt/.rvm/gems/ruby-2.5.0/gems/bundler-1.16.1/lib/bundler/cli.rb:27:in `dispatch'
     # /Users/arkadiyt/.rvm/gems/ruby-2.5.0/gems/bundler-1.16.1/lib/bundler/vendor/thor/lib/thor/base.rb:466:in `start'
     # /Users/arkadiyt/.rvm/gems/ruby-2.5.0/gems/bundler-1.16.1/lib/bundler/cli.rb:18:in `start'
     # /Users/arkadiyt/.rvm/gems/ruby-2.5.0/gems/bundler-1.16.1/exe/bundle:30:in `block in <top (required)>'
     # /Users/arkadiyt/.rvm/gems/ruby-2.5.0/gems/bundler-1.16.1/lib/bundler/friendly_errors.rb:122:in `with_friendly_errors'
     # /Users/arkadiyt/.rvm/gems/ruby-2.5.0/gems/bundler-1.16.1/exe/bundle:22:in `<top (required)>'
     # /Users/arkadiyt/.rvm/gems/ruby-2.5.0/bin/bundle:23:in `load'
     # /Users/arkadiyt/.rvm/gems/ruby-2.5.0/bin/bundle:23:in `<main>'
     # /Users/arkadiyt/.rvm/gems/ruby-2.5.0/bin/ruby_executable_hooks:15:in `eval'
     # /Users/arkadiyt/.rvm/gems/ruby-2.5.0/bin/ruby_executable_hooks:15:in `<main>'

This is on webmock 3.5.1 and ruby 2.5.0p0 (2017-12-25 revision 61468) [x86_64-darwin17]

@JohannaHartmann
Copy link
Contributor

We had the same issue with IPv6 addresses. We would be happy to provide a patch.

@bblimke
Copy link
Owner

bblimke commented Feb 26, 2021

@JohannaHartmann a patch would be very much appreciated :)

JohannaHartmann added a commit to JohannaHartmann/webmock that referenced this issue Mar 4, 2021
JohannaHartmann added a commit to JohannaHartmann/webmock that referenced this issue Mar 4, 2021
JohannaHartmann added a commit to JohannaHartmann/webmock that referenced this issue Mar 4, 2021
JohannaHartmann added a commit to JohannaHartmann/webmock that referenced this issue Mar 4, 2021
@bblimke bblimke closed this as completed in 3f7e7e5 Mar 5, 2021
bblimke added a commit that referenced this issue Mar 5, 2021
Fix: Handle IPv6 hostname correctly (closes #806)
This was referenced Mar 8, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment