Permalink
Browse files

Verification wether uri is allowed now works with array of regex

  • Loading branch information...
1 parent e0cd200 commit 3122c7f42c0711ecd9ecfe8ed12b5040417be995 @bastien bastien committed Mar 15, 2013
Showing with 14 additions and 12 deletions.
  1. +14 −12 lib/webmock/webmock.rb
View
@@ -59,18 +59,20 @@ def self.net_connect_allowed?(uri = nil)
end
Config.instance.allow_net_connect ||
- (
- Config.instance.allow_localhost && WebMock::Util::URI.is_uri_localhost?(uri)) ||
- Config.instance.allow && (
- (Config.instance.allow.kind_of?(Regexp) && uri.to_s =~ Config.instance.allow) ||
- (
- Config.instance.allow.respond_to?(:include?) &&
- (
- Config.instance.allow.include?(uri.host) ||
- Config.instance.allow.include?("#{uri.host}:#{uri.port}")
- )
- )
- )
+ ( Config.instance.allow_localhost && WebMock::Util::URI.is_uri_localhost?(uri) ||
+ Config.instance.allow && net_connect_explicit_allowed?(Config.instance.allow, uri) )
+ end
+
+ def self.net_connect_explicit_allowed?(allowed, uri=nil)
+ case allowed
+ when Array
+ allowed.any? { |allowed_item| net_connect_explicit_allowed?(allowed_item, uri) }
+ when Regexp
+ uri.to_s =~ allowed
+ when String
+ allowed == uri.host ||
+ allowed == "#{uri.host}:#{uri.port}"
+ end
end
def self.reset!

0 comments on commit 3122c7f

Please sign in to comment.