From f44bb6654fcbe99efc0e3718df8131bdc2bf48d4 Mon Sep 17 00:00:00 2001 From: Kevin Butterfield Date: Tue, 16 Apr 2019 16:20:32 -0400 Subject: [PATCH 1/3] Add support for proxy usernames/passwords --- lib/jira/client.rb | 2 ++ lib/jira/http_client.rb | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/jira/client.rb b/lib/jira/client.rb index d9f88b06..d5ba04e2 100644 --- a/lib/jira/client.rb +++ b/lib/jira/client.rb @@ -25,6 +25,8 @@ module JIRA # :auth_type => :oauth, # :proxy_address => nil, # :proxy_port => nil, + # :proxy_username => nil, + # :proxy_password => nil, # :additional_cookies => nil, # :default_headers => {} # diff --git a/lib/jira/http_client.rb b/lib/jira/http_client.rb index d99c6f59..aead2929 100644 --- a/lib/jira/http_client.rb +++ b/lib/jira/http_client.rb @@ -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 From 581bde208631d1e64c32b4cac30a1b57ee431bd4 Mon Sep 17 00:00:00 2001 From: Kevin Butterfield Date: Tue, 20 Aug 2019 15:53:57 -0400 Subject: [PATCH 2/3] Add tests --- spec/jira/http_client_spec.rb | 40 +++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/spec/jira/http_client_spec.rb b/spec/jira/http_client_spec.rb index 4c81150e..a486b15f 100644 --- a/spec/jira/http_client_spec.rb +++ b/spec/jira/http_client_spec.rb @@ -36,6 +36,16 @@ JIRA::HttpClient.new(options) 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) @@ -178,6 +188,36 @@ expect(basic_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 From b9edcf51e452dd1fff0d68db287e1e318a4dddce Mon Sep 17 00:00:00 2001 From: Kevin Butterfield Date: Wed, 4 Mar 2020 15:59:45 -0500 Subject: [PATCH 3/3] Re-add missing test helper --- spec/jira/http_client_spec.rb | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/spec/jira/http_client_spec.rb b/spec/jira/http_client_spec.rb index 458c8c90..4334d80c 100644 --- a/spec/jira/http_client_spec.rb +++ b/spec/jira/http_client_spec.rb @@ -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)