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

Add support for proxy usernames/passwords #333

Merged
merged 4 commits into from
Mar 14, 2020
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
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