Skip to content

Commit

Permalink
Fixed issue with no_proxy variable not being honoured (Mechanize driv…
Browse files Browse the repository at this point in the history
…er).
  • Loading branch information
Glen Birnie committed Nov 14, 2014
1 parent a9a950a commit 6a244b6
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 2 deletions.
3 changes: 3 additions & 0 deletions CHANGES
@@ -1,3 +1,6 @@
2.0.1
Fixed issue with no_proxy variable not being honoured (Mechanize driver).

2.0.0
Upgraded to Capybara 2.0+ and the latest versions of remaining gems.
Removed monkey patches, reclassifying some as "extensions".
Expand Down
2 changes: 1 addition & 1 deletion Gemfile.lock
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
frameworks-capybara (2.0.0)
frameworks-capybara (2.0.1)
capybara
capybara-mechanize
cucumber
Expand Down
11 changes: 11 additions & 0 deletions lib/frameworks/cucumber.rb
Expand Up @@ -109,6 +109,17 @@ def setup_mechanize(agent, http_proxy=nil)
agent.ca_file = ENV['CA_CERT_LOCATION'] if ENV['CA_CERT_LOCATION']
agent.set_proxy(http_proxy.scan(/http:\/\/(.*):80/)[0][0].to_s,80) if http_proxy && !http_proxy.empty?

# The above proxy setting ignores any no_proxy variable setting:
# added the following to circumvent this
if(http_proxy)
no_proxy = ENV['NO_PROXY'] || ENV['no_proxy']
if(no_proxy)
# The no_proxy query string argument must not contain spaces
no_proxy_qs = no_proxy.gsub(/[, ]+/,',')
agent.agent.http.proxy = URI(http_proxy + '?no_proxy=' + no_proxy_qs)
end
end

#This is necessary because Mech2 does not ship with root certs like Mech1 did and boxes may not have the OpenSSL set installed
agent.verify_mode = OpenSSL::SSL::VERIFY_NONE

Expand Down
2 changes: 1 addition & 1 deletion lib/version.rb
@@ -1,3 +1,3 @@
module FrameworksCapybara
VERSION = '2.0.0'
VERSION = '2.0.1'
end
28 changes: 28 additions & 0 deletions spec/frameworks_cucumber_spec.rb
Expand Up @@ -247,5 +247,33 @@
agent.proxy_addr.should == 'mycache.co.uk'
end

it "the proxy should be ignored if the no_proxy exclusion is set" do
proxy_host = 'mycache.co.uk'
proxy_port = '80'
proxy_uri = 'http://' + proxy_host + ':' + proxy_port
no_proxy = 'ignore_this_host'
ENV['NO_PROXY'] = no_proxy
agent = new_mechanize(http_proxy=proxy_uri)
expect(agent).to be_a_kind_of Mechanize
expect(agent.agent.http.proxy_uri.host).to eq(proxy_host)
expect(agent.agent.http.proxy_uri.port).to eq(proxy_port.to_i)
no_proxy_array = [ no_proxy ]
expect(agent.agent.http.no_proxy).to eq(no_proxy_array)
end

it "the proxy should be ignored if the no_proxy exclusion is set with multiple values" do
proxy_host = 'mycache.co.uk'
proxy_port = '80'
proxy_uri = 'http://' + proxy_host + ':' + proxy_port
no_proxy1 = 'ignore_this_host'
no_proxy2 = '.and.this.domain'
ENV['NO_PROXY'] = no_proxy1 + ', ' + no_proxy2
agent = new_mechanize(http_proxy=proxy_uri)
expect(agent).to be_a_kind_of Mechanize
expect(agent.agent.http.proxy_uri.host).to eq(proxy_host)
expect(agent.agent.http.proxy_uri.port).to eq(proxy_port.to_i)
no_proxy_array = [ no_proxy1, no_proxy2 ]
expect(agent.agent.http.no_proxy).to eq(no_proxy_array)
end
end
end

0 comments on commit 6a244b6

Please sign in to comment.