Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

httpclient adapter now accepts NTLM auth. #160

Merged
merged 1 commit into from
Sep 25, 2015
Merged
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
15 changes: 11 additions & 4 deletions lib/httpi/adapter/httpclient.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,8 @@ def request(method)
def setup_client
basic_setup

if @request.auth.ntlm?
raise NotSupportedError, "HTTPClient adapter does not support NTLM authentication"
end

setup_auth if @request.auth.http?
setup_ntlm_auth if @request.auth.ntlm?
setup_ssl_auth if @request.auth.ssl? || @request.ssl?
end

Expand All @@ -54,6 +51,16 @@ def setup_auth
@client.set_auth @request.url, *@request.auth.credentials
end

def setup_ntlm_auth
username, password, domain = @request.auth.credentials

unless domain.nil?
username = "#{domain.upcase}\\#{username}"
end

@client.set_auth @request.url, username, password
end

def setup_ssl_auth
ssl = @request.auth.ssl

Expand Down
18 changes: 14 additions & 4 deletions spec/httpi/adapter/httpclient_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
require "spec_helper"
require "httpi/adapter/httpclient"
require "httpi/request"
require "integration/support/server"

HTTPI::Adapter.load_adapter(:httpclient)

Expand All @@ -10,6 +11,14 @@
let(:ssl_config) { HTTPClient::SSLConfig.any_instance }
let(:request) { HTTPI::Request.new("http://example.com") }

before :all do
@server = IntegrationServer.run
end

after :all do
@server.stop
end

describe "#request(:get)" do
it "returns a valid HTTPI::Response" do
httpclient_expects(:get)
Expand Down Expand Up @@ -174,11 +183,12 @@
end
end

it "does not support NTLM authentication" do
request.auth.ntlm("tester", "vReqSoafRe5O")
it "supports NTLM authentication" do
request = HTTPI::Request.new(@server.url + "ntlm-auth")

expect { adapter.request(:get) }.
to raise_error(HTTPI::NotSupportedError, /adapter does not support NTLM authentication/)
request.auth.ntlm("tester", "vReqSoafRe5O")
response = HTTPI.get(request, :httpclient)
expect(response.body).to eq("ntlm-auth")
end

def httpclient_expects(method)
Expand Down