diff --git a/CHANGES b/CHANGES index 3c3c362..35498e0 100644 --- a/CHANGES +++ b/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". diff --git a/Gemfile.lock b/Gemfile.lock index f6edc78..82fa625 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,7 @@ PATH remote: . specs: - frameworks-capybara (2.0.0) + frameworks-capybara (2.0.1) capybara capybara-mechanize cucumber diff --git a/lib/frameworks/cucumber.rb b/lib/frameworks/cucumber.rb index 409b7ae..915d125 100644 --- a/lib/frameworks/cucumber.rb +++ b/lib/frameworks/cucumber.rb @@ -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 diff --git a/lib/version.rb b/lib/version.rb index 4a2c3e6..0558b6f 100644 --- a/lib/version.rb +++ b/lib/version.rb @@ -1,3 +1,3 @@ module FrameworksCapybara - VERSION = '2.0.0' + VERSION = '2.0.1' end diff --git a/spec/frameworks_cucumber_spec.rb b/spec/frameworks_cucumber_spec.rb index f00a305..1d10a6a 100644 --- a/spec/frameworks_cucumber_spec.rb +++ b/spec/frameworks_cucumber_spec.rb @@ -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