Commit f61bdfe3 authored by Douwe Maan's avatar Douwe Maan

Merge branch 'unix-socket-host' into 'master'

Set a 'Host' header on unix sockets

Closes #72

See merge request !117
parents a3712cc1 3695d162
...@@ -159,6 +159,12 @@ class GitlabNet ...@@ -159,6 +159,12 @@ class GitlabNet
request.set_form_data(params.merge(secret_token: secret_token)) request.set_form_data(params.merge(secret_token: secret_token))
if uri.is_a?(URI::HTTPUNIX)
# The HTTPUNIX HTTP client does not set a correct Host header. This can
# lead to 400 Bad Request responses.
request['Host'] = 'localhost'
end
request request
end end
......
...@@ -248,24 +248,37 @@ describe GitlabNet, vcr: true do ...@@ -248,24 +248,37 @@ describe GitlabNet, vcr: true do
end end
describe :http_request_for do describe :http_request_for do
let(:get) do context 'with stub' do
double(Net::HTTP::Get).tap do |get| let(:get) do
Net::HTTP::Get.stub(:new) { get } double(Net::HTTP::Get).tap do |get|
Net::HTTP::Get.stub(:new) { get }
end
end
let(:user) { 'user' }
let(:password) { 'password' }
let(:url) { URI 'http://localhost/' }
subject { gitlab_net.send :http_request_for, :get, url }
before do
gitlab_net.send(:config).http_settings.stub(:[]).with('user') { user }
gitlab_net.send(:config).http_settings.stub(:[]).with('password') { password }
get.should_receive(:basic_auth).with(user, password).once
get.should_receive(:set_form_data).with(hash_including(secret_token: 'a123')).once
end end
it { should_not be_nil }
end end
let(:user) { 'user' }
let(:password) { 'password' }
let(:url) { URI 'http://localhost/' }
subject { gitlab_net.send :http_request_for, :get, url }
before do context 'Unix socket' do
gitlab_net.send(:config).http_settings.stub(:[]).with('user') { user } it 'sets the Host header to "localhost"' do
gitlab_net.send(:config).http_settings.stub(:[]).with('password') { password } gitlab_net = described_class.new
get.should_receive(:basic_auth).with(user, password).once gitlab_net.should_receive(:secret_token).and_return('a123')
get.should_receive(:set_form_data).with(hash_including(secret_token: 'a123')).once
end
it { should_not be_nil } request = gitlab_net.send(:http_request_for, :get, URI('http+unix://%2Ffoo'))
expect(request['Host']).to eq('localhost')
end
end
end end
describe :cert_store do describe :cert_store do
......
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