Commit 92b5bd61 authored by Arturo Herrero's avatar Arturo Herrero

Reverts HTTP connection adapter with proxy settings

This partially reverts
https://gitlab.com/gitlab-org/gitlab/-/merge_requests/55406. We no
longer need this as we are using the proxy settings via environment
variables
https://docs.gitlab.com/omnibus/settings/environment-variables.html#setting-custom-environment-variables.
parent 3557470f
...@@ -17,14 +17,6 @@ module Gitlab ...@@ -17,14 +17,6 @@ module Gitlab
def connection def connection
@uri, hostname = validate_url!(uri) @uri, hostname = validate_url!(uri)
if options.key?(:http_proxyaddr)
proxy_uri_with_port = uri_with_port(options[:http_proxyaddr], options[:http_proxyport])
proxy_uri_validated = validate_url!(proxy_uri_with_port).first
@options[:http_proxyaddr] = proxy_uri_validated.omit(:port).to_s
@options[:http_proxyport] = proxy_uri_validated.port
end
super.tap do |http| super.tap do |http|
http.hostname_override = hostname if hostname http.hostname_override = hostname if hostname
end end
...@@ -53,11 +45,5 @@ module Gitlab ...@@ -53,11 +45,5 @@ module Gitlab
def allow_settings_local_requests? def allow_settings_local_requests?
Gitlab::CurrentSettings.allow_local_requests_from_web_hooks_and_services? Gitlab::CurrentSettings.allow_local_requests_from_web_hooks_and_services?
end end
def uri_with_port(address, port)
uri = Addressable::URI.parse(address)
uri.port = port if port.present?
uri
end
end end
end end
...@@ -124,130 +124,5 @@ RSpec.describe Gitlab::HTTPConnectionAdapter do ...@@ -124,130 +124,5 @@ RSpec.describe Gitlab::HTTPConnectionAdapter do
expect(connection.port).to eq(443) expect(connection.port).to eq(443)
end end
end end
context 'when proxy settings are configured' do
let(:options) do
{
http_proxyaddr: 'https://proxy.org',
http_proxyport: 1557,
http_proxyuser: 'user',
http_proxypass: 'pass'
}
end
before do
stub_all_dns('https://proxy.org', ip_address: '166.84.12.54')
end
it 'sets up the proxy settings' do
expect(connection.proxy_address).to eq('https://166.84.12.54')
expect(connection.proxy_port).to eq(1557)
expect(connection.proxy_user).to eq('user')
expect(connection.proxy_pass).to eq('pass')
end
context 'when the address has path' do
before do
options[:http_proxyaddr] = 'https://proxy.org/path'
end
it 'sets up the proxy settings' do
expect(connection.proxy_address).to eq('https://166.84.12.54/path')
expect(connection.proxy_port).to eq(1557)
end
end
context 'when the port is in the address and port' do
before do
options[:http_proxyaddr] = 'https://proxy.org:1422'
end
it 'sets up the proxy settings' do
expect(connection.proxy_address).to eq('https://166.84.12.54')
expect(connection.proxy_port).to eq(1557)
end
context 'when the port is only in the address' do
before do
options[:http_proxyport] = nil
end
it 'sets up the proxy settings' do
expect(connection.proxy_address).to eq('https://166.84.12.54')
expect(connection.proxy_port).to eq(1422)
end
end
end
context 'when it is a request to local network' do
before do
options[:http_proxyaddr] = 'http://172.16.0.0/12'
end
it 'raises error' do
expect { subject }.to raise_error(
Gitlab::HTTP::BlockedUrlError,
"URL 'http://172.16.0.0:1557/12' is blocked: Requests to the local network are not allowed"
)
end
context 'when local request allowed' do
before do
options[:allow_local_requests] = true
end
it 'sets up the connection' do
expect(connection.proxy_address).to eq('http://172.16.0.0/12')
expect(connection.proxy_port).to eq(1557)
end
end
end
context 'when it is a request to local address' do
before do
options[:http_proxyaddr] = 'http://127.0.0.1'
end
it 'raises error' do
expect { subject }.to raise_error(
Gitlab::HTTP::BlockedUrlError,
"URL 'http://127.0.0.1:1557' is blocked: Requests to localhost are not allowed"
)
end
context 'when local request allowed' do
before do
options[:allow_local_requests] = true
end
it 'sets up the connection' do
expect(connection.proxy_address).to eq('http://127.0.0.1')
expect(connection.proxy_port).to eq(1557)
end
end
end
context 'when http(s) environment variable is set' do
before do
stub_env('https_proxy' => 'https://my.proxy')
end
it 'sets up the connection' do
expect(connection.proxy_address).to eq('https://proxy.org')
expect(connection.proxy_port).to eq(1557)
end
end
context 'when DNS rebinding protection is disabled' do
before do
stub_application_setting(dns_rebinding_protection_enabled: false)
end
it 'sets up the connection' do
expect(connection.proxy_address).to eq('https://proxy.org')
expect(connection.proxy_port).to eq(1557)
end
end
end
end end
end end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment