Skip to content

Commit

Permalink
Merge pull request #333 from KevinButterfield/allow-proxy-usernames-a…
Browse files Browse the repository at this point in the history
…nd-passwords

Add support for proxy usernames/passwords
  • Loading branch information
SimonMiaou authored Mar 14, 2020
2 parents f58ac03 + b9edcf5 commit 39e47f4
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 1 deletion.
2 changes: 2 additions & 0 deletions lib/jira/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ module JIRA
# :auth_type => :oauth,
# :proxy_address => nil,
# :proxy_port => nil,
# :proxy_username => nil,
# :proxy_password => nil,
# :additional_cookies => nil,
# :default_headers => {}
#
Expand Down
2 changes: 1 addition & 1 deletion lib/jira/http_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def basic_auth_http_conn

def http_conn(uri)
if @options[:proxy_address]
http_class = Net::HTTP::Proxy(@options[:proxy_address], @options[:proxy_port] || 80)
http_class = Net::HTTP::Proxy(@options[:proxy_address], @options[:proxy_port] || 80, @options[:proxy_username], @options[:proxy_password])
else
http_class = Net::HTTP
end
Expand Down
40 changes: 40 additions & 0 deletions spec/jira/http_client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,16 @@
{ username: 'donaldduck', password: 'supersecret' }
end

let(:proxy_client) do
options = JIRA::Client::DEFAULT_OPTIONS.merge(JIRA::HttpClient::DEFAULT_OPTIONS).merge(
proxy_address: 'proxyAddress',
proxy_port: 42,
proxy_username: 'proxyUsername',
proxy_password: 'proxyPassword'
)
JIRA::HttpClient.new(options)
end

let(:response) do
response = double('response')
allow(response).to receive(:kind_of?).with(Net::HTTPSuccess).and_return(true)
Expand Down Expand Up @@ -229,6 +239,36 @@
expect(custom_ssl_version_client.http_conn(uri)).to eq(http_conn)
end

it 'sets up a non-proxied http connection by default' do
uri = double
host = double
port = double

expect(uri).to receive(:host).and_return(host)
expect(uri).to receive(:port).and_return(port)

proxy_configuration = basic_client.http_conn(uri).class
expect(proxy_configuration.proxy_address).to be_nil
expect(proxy_configuration.proxy_port).to be_nil
expect(proxy_configuration.proxy_user).to be_nil
expect(proxy_configuration.proxy_pass).to be_nil
end

it 'sets up a proxied http connection when using proxy options' do
uri = double
host = double
port = double

expect(uri).to receive(:host).and_return(host)
expect(uri).to receive(:port).and_return(port)

proxy_configuration = proxy_client.http_conn(uri).class
expect(proxy_configuration.proxy_address).to eq(proxy_client.options[:proxy_address])
expect(proxy_configuration.proxy_port).to eq(proxy_client.options[:proxy_port])
expect(proxy_configuration.proxy_user).to eq(proxy_client.options[:proxy_username])
expect(proxy_configuration.proxy_pass).to eq(proxy_client.options[:proxy_password])
end

it 'can use client certificates' do
http_conn = double
uri = double
Expand Down

0 comments on commit 39e47f4

Please sign in to comment.