diff --git a/.travis.yml b/.travis.yml index 2ee45b5..327046d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,3 +7,6 @@ rvm: - 2.2.4 - 2.3.0 - jruby +env: + global: + - JRUBY_OPTS="--2.0" diff --git a/Gemfile b/Gemfile index 39770f4..f491647 100644 --- a/Gemfile +++ b/Gemfile @@ -3,6 +3,9 @@ gemspec gem 'jruby-openssl', :platforms => :jruby +# compatibility restrictions for http clients under existing travis test environments +gem 'public_suffix', '~> 2.0' # or remove rubies < 2.1 from travis.yml + # http clients gem 'httpclient', '~> 2.3', :require => false gem 'curb', '~> 0.8', :require => false, :platforms => :ruby diff --git a/Rakefile b/Rakefile index 62e1522..b6001e4 100644 --- a/Rakefile +++ b/Rakefile @@ -10,7 +10,9 @@ RSpec::Core::RakeTask.new "spec_integration" do |t| t.pattern = "spec/integration/*_spec.rb" end -task :default => :spec - desc "Run RSpec code and integration examples" -task :ci => [:spec, :spec_integration] +RSpec::Core::RakeTask.new "ci" do |t| + t.pattern = "spec/{httpi,integration}/**/*_spec.rb" +end + +task :default => :spec diff --git a/lib/httpi/adapter/net_http.rb b/lib/httpi/adapter/net_http.rb index 6390178..9aa3855 100644 --- a/lib/httpi/adapter/net_http.rb +++ b/lib/httpi/adapter/net_http.rb @@ -18,7 +18,7 @@ class NetHTTP < Base register :net_http, :deps => %w(net/https) def initialize(request) - check_net_ntlm_version! + check_net_ntlm_version! if request.auth.ntlm? @request = request @client = create_client end @@ -55,11 +55,15 @@ def request(method) end private + def ntlm_version + Net::NTLM::VERSION::STRING + end + def check_net_ntlm_version! begin require 'net/ntlm' require 'net/ntlm/version' unless Net::NTLM.const_defined?(:VERSION, false) - unless Net::NTLM::VERSION::STRING >= '0.3.2' + unless ntlm_version >= '0.3.2' raise ArgumentError, 'Invalid version of rubyntlm. Please use v0.3.2+.' end rescue LoadError diff --git a/spec/httpi/adapter/net_http_spec.rb b/spec/httpi/adapter/net_http_spec.rb index 0158fef..51e94e2 100644 --- a/spec/httpi/adapter/net_http_spec.rb +++ b/spec/httpi/adapter/net_http_spec.rb @@ -132,6 +132,33 @@ to raise_error(HTTPI::NotSupportedError, /Net::NTLM is not available/) end + it 'does not require ntlm when ntlm authenication is not requested' do + HTTPI::Adapter::NetHTTP.any_instance.stubs(:check_net_ntlm_version!).raises(RuntimeError) + request = HTTPI::Request.new(@server.url) + expect(request.auth.ntlm?).to be false + + # make sure a request doesn't call ntlm check if we don't ask for it. + expect { HTTPI.get(request, adapter) }.not_to raise_error + HTTPI::Adapter::NetHTTP.any_instance.unstub(:check_net_ntlm_version!) + end + + it 'does check ntlm when ntlm authentication is requested' do + request = HTTPI::Request.new(@server.url + "ntlm-auth") + request.auth.ntlm("tester", "vReqSoafRe5O") + + expect { HTTPI.get(request, adapter) }.not_to raise_error + + # the check should also verify that the version of ntlm is supported and still fail if it isn't + HTTPI::Adapter::NetHTTP.any_instance.stubs(:ntlm_version).returns("0.1.1") + + request = HTTPI::Request.new(@server.url + "ntlm-auth") + request.auth.ntlm("tester", "vReqSoafRe5O") + + expect { HTTPI.get(request, adapter) }.to raise_error(ArgumentError, /Invalid version/) + + HTTPI::Adapter::NetHTTP.any_instance.unstub(:ntlm_version) + end + it "does not crash when authenticate header is missing (on second request)" do request = HTTPI::Request.new(@server.url + 'ntlm-auth') request.auth.ntlm("tester", "vReqSoafRe5O") diff --git a/spec/integration/net_http_persistent_spec.rb b/spec/integration/net_http_persistent_spec.rb index c1e89a6..28aabbf 100644 --- a/spec/integration/net_http_persistent_spec.rb +++ b/spec/integration/net_http_persistent_spec.rb @@ -37,7 +37,9 @@ end it "executes POST requests" do - response = HTTPI.post(@server.url, "xml", adapter) + request = HTTPI::Request.new(url: @server.url, open_timeout: 1, read_timeout: 1, body: "xml") + + response = HTTPI.post(request, adapter) expect(response.body).to eq("post") expect(response.headers["Content-Type"]).to eq("text/plain") end