Skip to content

Commit

Permalink
':allow_localhost => true' now permits 127.0.0.1 as well as 'localhost'
Browse files Browse the repository at this point in the history
  • Loading branch information
MacksMind authored and Bartosz Blimke committed May 13, 2010
1 parent 7c4a298 commit 3c92a45
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/webmock/webmock.rb
Expand Up @@ -44,7 +44,7 @@ def net_connect_allowed?(uri = nil)
uri = WebMock::Util::URI.normalize_uri(uri)
end
Config.instance.allow_net_connect ||
(Config.instance.allow_localhost && uri.is_a?(Addressable::URI) && uri.host == 'localhost')
(Config.instance.allow_localhost && uri.is_a?(Addressable::URI) && (uri.host == 'localhost' || uri.host == '127.0.0.1'))
end

def registered_request?(request_signature)
Expand Down
8 changes: 7 additions & 1 deletion spec/webmock_spec.rb
Expand Up @@ -84,11 +84,17 @@ class MyException < StandardError; end;
}.should raise_error(WebMock::NetConnectNotAllowedError, client_specific_request_string("Real HTTP connections are disabled. Unregistered request: GET http://www.example.com/"))
end

it "should allow a real request localhost" do
it "should allow a real request to localhost" do
lambda {
http_request(:get, "http://localhost:12345/")
}.should raise_error(connection_refused_exception_class)
end

it "should allow a real request to 127.0.0.1" do
lambda {
http_request(:get, "http://127.0.0.1:12345/")
}.should raise_error(connection_refused_exception_class)
end
end
end

Expand Down

0 comments on commit 3c92a45

Please sign in to comment.