Permalink
Browse files

:allow_localhost => true' now permits 0.0.0.0 in addition to 127.0.0.…

…1 and 'localhost'
  • Loading branch information...
1 parent 6eb8bb5 commit c646491e4faf4b7e91ff58f98b3e19cd2ca3ccd3 @bblimke committed Oct 3, 2010
Showing with 16 additions and 1 deletion.
  1. +2 −0 CHANGELOG.md
  2. +8 −1 lib/webmock/webmock.rb
  3. +6 −0 spec/webmock_spec.rb
View
@@ -2,6 +2,8 @@
## Master
+* :allow_localhost => true' now permits 0.0.0.0 in addition to 127.0.0.1 and 'localhost'. Thanks to Myron Marston and Mike Gehard for suggesting this.
+
* Fixed issue with both Rspec 1.x and 2.x being available.
WebMock now tries to use already loaded version of RSpec (1.x or 2.x). Previously it was loading Rspec 2.0 if available, even if RSpec 1.3 was already loaded.
View
@@ -45,7 +45,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' || uri.host == '127.0.0.1')) ||
+ (Config.instance.allow_localhost && uri_is_localhost(uri)) ||
Config.instance.allow && Config.instance.allow.include?(uri.host)
end
@@ -72,5 +72,12 @@ def assertion_failure(message)
def after_request(options={}, &block)
CallbackRegistry.add_callback(options, block)
end
+
+ private
+
+ def uri_is_localhost(uri)
+ uri.is_a?(Addressable::URI) &&
+ %w(localhost 127.0.0.1 0.0.0.0).include?(uri.host)
+ end
end
View
@@ -98,6 +98,12 @@ class MyException < StandardError; end;
http_request(:get, "http://127.0.0.1:12345/")
}.should raise_error(connection_refused_exception_class)
end
+
+ it "should allow a real request to 0.0.0.0" do
+ lambda {
+ http_request(:get, "http://0.0.0.0:12345/")
+ }.should raise_error(connection_refused_exception_class)
+ end
end
describe "is not allowed with exception for allowed domains" do

0 comments on commit c646491

Please sign in to comment.