Skip to content

Commit

Permalink
Support URI reserved characters in proxy server passwords. (#757)
Browse files Browse the repository at this point in the history
  • Loading branch information
petelacey authored and rokob committed Jun 25, 2018
1 parent 270dc58 commit 2b663e6
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 16 deletions.
17 changes: 9 additions & 8 deletions lib/rollbar/notifier.rb
Original file line number Diff line number Diff line change
Expand Up @@ -530,14 +530,15 @@ def http_proxy(uri)
end

def proxy_from_config
proxy = configuration.proxy
return nil unless proxy

px = URI.parse(proxy[:host])
px.port = proxy[:port]
px.user = proxy[:user]
px.password = proxy[:password]
px
proxy_settings = configuration.proxy
return nil unless proxy_settings

proxy = null_proxy
proxy.host = URI.parse(proxy_settings[:host]).host
proxy.port = proxy_settings[:port]
proxy.user = proxy_settings[:user]
proxy.password = proxy_settings[:password]
proxy
end

def proxy_from_env(uri)
Expand Down
27 changes: 19 additions & 8 deletions spec/rollbar_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1043,18 +1043,20 @@ def backtrace
end

context 'via environment variables' do
before do
@uri = URI.parse(Rollbar::Configuration::DEFAULT_ENDPOINT)
end

it 'honors proxy settings in the environment' do
ENV['http_proxy'] = 'http://user:pass@example.com:80'
ENV['https_proxy'] = 'http://user:pass@example.com:80'

uri = URI.parse(Rollbar::Configuration::DEFAULT_ENDPOINT)
expect(Net::HTTP).to receive(:new).with(uri.host, uri.port, 'example.com', 80, 'user', 'pass').and_call_original
expect(Net::HTTP).to receive(:new).with(@uri.host, @uri.port, 'example.com', 80, 'user', 'pass').and_call_original
Rollbar.info("proxy this")
end

it 'does not use a proxy if no proxy settings in environemnt' do
uri = URI.parse(Rollbar::Configuration::DEFAULT_ENDPOINT)
expect(Net::HTTP).to receive(:new).with(uri.host, uri.port, nil, nil, nil, nil).and_call_original
expect(Net::HTTP).to receive(:new).with(@uri.host, @uri.port, nil, nil, nil, nil).and_call_original
Rollbar.info("proxy this")
end
end
Expand All @@ -1069,20 +1071,29 @@ def backtrace
:password => 'bar'
}
end

@uri = URI.parse(Rollbar::Configuration::DEFAULT_ENDPOINT)
end

it 'honors proxy settings in the config file' do
uri = URI.parse(Rollbar::Configuration::DEFAULT_ENDPOINT)
expect(Net::HTTP).to receive(:new).with(uri.host, uri.port, 'config.com', 8080, 'foo', 'bar').and_call_original
expect(Net::HTTP).to receive(:new).with(@uri.host, @uri.port, 'config.com', 8080, 'foo', 'bar').and_call_original
Rollbar.info("proxy this")
end

it 'gives the configuration settings precedence over environment' do
ENV['http_proxy'] = 'http://user:pass@example.com:80'
ENV['https_proxy'] = 'http://user:pass@example.com:80'

uri = URI.parse(Rollbar::Configuration::DEFAULT_ENDPOINT)
expect(Net::HTTP).to receive(:new).with(uri.host, uri.port, 'config.com', 8080, 'foo', 'bar').and_call_original
expect(Net::HTTP).to receive(:new).with(@uri.host, @uri.port, 'config.com', 8080, 'foo', 'bar').and_call_original
Rollbar.info("proxy this")
end

it 'allows @-signs in passwords' do
Rollbar.configure do |config|
config.proxy[:password] = "manh@tan"
end

expect(Net::HTTP).to receive(:new).with(@uri.host, @uri.port, 'config.com', 8080, 'foo', 'manh@tan').and_call_original
Rollbar.info("proxy this")
end
end
Expand Down

0 comments on commit 2b663e6

Please sign in to comment.