Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion rb/lib/selenium/webdriver/common/proxy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ def as_json(*)
'proxyType' => TYPES[type].downcase,
'ftpProxy' => ftp,
'httpProxy' => http,
'noProxy' => no_proxy.is_a?(String) ? no_proxy.split(', ') : no_proxy,
'noProxy' => no_proxy.is_a?(String) ? no_proxy.split(',').map(&:strip).reject(&:empty?) : no_proxy,
'proxyAutoconfigUrl' => pac,
'sslProxy' => ssl,
'autodetect' => auto_detect,
Expand Down
26 changes: 12 additions & 14 deletions rb/lib/selenium/webdriver/remote/http/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -148,24 +148,22 @@ def proxy

def use_proxy?
return false if proxy.nil?
return true unless proxy.no_proxy

if proxy.no_proxy
ignored = proxy.no_proxy.split(',').any? do |host|
host == '*' ||
host == server_url.host || (
begin
IPAddr.new(host).include?(server_url.host)
rescue ArgumentError
false
end
)
end
!proxy_ignored?
end

!ignored
else
true
def proxy_ignored?
proxy.no_proxy.split(',').map(&:strip).reject(&:empty?).any? do |host|
host == '*' || host == server_url.host || ip_match?(host)
end
end

def ip_match?(host)
IPAddr.new(host).include?(server_url.host)
rescue ArgumentError
false
end
end # Default
end # Http
end # Remote
Expand Down
12 changes: 12 additions & 0 deletions rb/spec/unit/selenium/webdriver/remote/capabilities_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,18 @@ module Remote
expect(caps.as_json['proxy']['noProxy']).to eq(%w[proxy_url localhost])
end

it 'converts noProxy from comma-only separated string to array' do
proxy = Proxy.new(no_proxy: 'proxy_url,localhost')
caps = described_class.new(proxy: proxy)
expect(caps.as_json['proxy']['noProxy']).to eq(%w[proxy_url localhost])
end

it 'trims whitespace around noProxy entries' do
proxy = Proxy.new(no_proxy: ' proxy_url , localhost ')
caps = described_class.new(proxy: proxy)
expect(caps.as_json['proxy']['noProxy']).to eq(%w[proxy_url localhost])
end

it 'does not convert noProxy if it is already array' do
proxy = Proxy.new(no_proxy: ['proxy_url'])
caps = described_class.new(proxy: proxy)
Expand Down
14 changes: 14 additions & 0 deletions rb/spec/unit/selenium/webdriver/remote/http/default_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,20 @@ module Http
expect(http).not_to be_proxy
end
end

it "trims whitespace around entries in #{no_proxy_var}" do
with_env('http_proxy' => 'proxy.org:8080', no_proxy_var => 'localhost, example.com') do
http = client.send :http
expect(http).not_to be_proxy
end
end

it "trims leading whitespace on a single entry in #{no_proxy_var}" do
with_env('http_proxy' => 'proxy.org:8080', no_proxy_var => ' example.com') do
http = client.send :http
expect(http).not_to be_proxy
end
end
end

it 'raises a sane error if a proxy is refusing connections' do
Expand Down
Loading