webmock icon indicating copy to clipboard operation
webmock copied to clipboard

disable_net_connect `:allow` encoding underscore to %5F

Open x2es opened this issue 5 years ago • 1 comments

Versions:

webmock: 3.8.3 rspec: 3.5.4 rails: 5.0.7

Problem

I am testing service in integration fashion. Service name is hermes_test.

WebMock.disable_net_connect!(allow: %w(localhost hermes_test elasticsearch))

Result:
     WebMock::NetConnectNotAllowedError:
       Real HTTP connections are disabled. Unregistered request: GET http://hermes%5Ftest:3199/products/search with headers {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip, deflate', 'Content-Type'=>'application/json', 'Cookie'=>'pp_session=0c394b279ff0769fde16a93e9e21853e', 'Host'=>'hermes_test:3199', 'User-Agent'=>'rest-client/2.0.2 (linux-gnu x86_64) ruby/2.4.4p296'}
     
       You can stub this request with the following snippet:
     
       stub_request(:get, "http://hermes%5Ftest:3199/products/search").
         with(
           headers: {

Workaround

Changing _ to %5F in :allow option works

WebMock.disable_net_connect!(allow: %w(localhost hermes%5Ftest elasticsearch))

Expected

:allow accepts hostnames with underscore, since it is valid character for domain name

x2es avatar May 08 '20 11:05 x2es

Thank you for submitting this @x2es

bblimke avatar Sep 09 '20 14:09 bblimke