Skip to content

allow doesn't match when url is https and includes path, because Addressable::URI#to_s includes port in the string #977

Description

@henrahmagix

When WebMock.disallow_net_connect! is called with:

WebMock.disallow_net_connect!(allow: ['https://github.com/mozilla/geckodriver/releases/latest'])

it fails to allow requests to that url because the uri that comes into net_connect_explicit_allowed? is an Addressable::URI, who's #to_s method returns a string with the port in.

For example:

require 'webmock'
allowed = "https://github.com/mozilla/geckodriver/releases/latest"
uri = WebMock::Util::URI.normalize_uri(allowed)
puts uri.class
# Addressable::URI
puts uri.to_s
# https://github.com:443/mozilla/geckodriver/releases/latest

puts allowed == uri.to_s ||
      allowed == uri.host ||
      allowed == "#{uri.host}:#{uri.port}" ||
      allowed == "#{uri.scheme}://#{uri.host}:#{uri.port}" ||
      allowed == "#{uri.scheme}://#{uri.host}" && uri.port == uri.default_port
# false

FYI such requests happen automatically in capybara/selenium-webdriver/webdrivers when using firefox driver.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions