Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Verification wether uri is allowed now works with array of regex

  • Loading branch information...
commit 3122c7f42c0711ecd9ecfe8ed12b5040417be995 1 parent e0cd200
@bastien bastien authored
Showing with 14 additions and 12 deletions.
  1. +14 −12 lib/webmock/webmock.rb
View
26 lib/webmock/webmock.rb
@@ -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!
Please sign in to comment.
Something went wrong with that request. Please try again.