Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'spec/lib/gitlab/workhorse_spec.rb')
-rw-r--r--spec/lib/gitlab/workhorse_spec.rb162
1 files changed, 88 insertions, 74 deletions
diff --git a/spec/lib/gitlab/workhorse_spec.rb b/spec/lib/gitlab/workhorse_spec.rb
index 5c9a3cc0a24..3c7542ea5f9 100644
--- a/spec/lib/gitlab/workhorse_spec.rb
+++ b/spec/lib/gitlab/workhorse_spec.rb
@@ -4,6 +4,7 @@ require 'spec_helper'
RSpec.describe Gitlab::Workhorse do
let_it_be(:project) { create(:project, :repository) }
+ let(:features) { { 'gitaly-feature-enforce-requests-limits' => 'true' } }
let(:repository) { project.repository }
@@ -42,7 +43,7 @@ RSpec.describe Gitlab::Workhorse do
expect(command).to eq('git-archive')
expect(params).to eq({
'GitalyServer' => {
- features: { 'gitaly-feature-enforce-requests-limits' => 'true' },
+ 'call_metadata' => features,
address: Gitlab::GitalyClient.address(project.repository_storage),
token: Gitlab::GitalyClient.token(project.repository_storage)
},
@@ -92,7 +93,7 @@ RSpec.describe Gitlab::Workhorse do
expect(command).to eq("git-format-patch")
expect(params).to eq({
'GitalyServer' => {
- features: { 'gitaly-feature-enforce-requests-limits' => 'true' },
+ 'call_metadata' => features,
address: Gitlab::GitalyClient.address(project.repository_storage),
token: Gitlab::GitalyClient.token(project.repository_storage)
},
@@ -155,7 +156,7 @@ RSpec.describe Gitlab::Workhorse do
expect(command).to eq("git-diff")
expect(params).to eq({
'GitalyServer' => {
- features: { 'gitaly-feature-enforce-requests-limits' => 'true' },
+ 'call_metadata' => features,
address: Gitlab::GitalyClient.address(project.repository_storage),
token: Gitlab::GitalyClient.token(project.repository_storage)
},
@@ -208,6 +209,16 @@ RSpec.describe Gitlab::Workhorse do
describe '.git_http_ok' do
let(:user) { create(:user) }
+ let(:gitaly_params) do
+ {
+ GitalyServer: {
+ call_metadata: call_metadata,
+ address: Gitlab::GitalyClient.address('default'),
+ token: Gitlab::GitalyClient.token('default')
+ }
+ }
+ end
+
let(:repo_path) { 'ignored but not allowed to be empty in gitlab-workhorse' }
let(:action) { 'info_refs' }
let(:params) do
@@ -219,6 +230,13 @@ RSpec.describe Gitlab::Workhorse do
}
end
+ let(:call_metadata) do
+ features.merge({
+ 'user_id' => params[:GL_ID],
+ 'username' => params[:GL_USERNAME]
+ })
+ end
+
subject { described_class.git_http_ok(repository, Gitlab::GlRepository::PROJECT, user, action) }
it { expect(subject).to include(params) }
@@ -238,100 +256,79 @@ RSpec.describe Gitlab::Workhorse do
it { expect(subject).to include(params) }
end
- context 'when Gitaly is enabled' do
- let(:gitaly_params) do
- {
- GitalyServer: {
- features: { 'gitaly-feature-enforce-requests-limits' => 'true' },
- address: Gitlab::GitalyClient.address('default'),
- token: Gitlab::GitalyClient.token('default')
- }
- }
- end
+ it 'includes a Repository param' do
+ repo_param = {
+ storage_name: 'default',
+ relative_path: project.disk_path + '.git',
+ gl_repository: "project-#{project.id}"
+ }
- before do
- allow(Gitlab.config.gitaly).to receive(:enabled).and_return(true)
- end
+ expect(subject[:Repository]).to include(repo_param)
+ end
- it 'includes a Repository param' do
- repo_param = {
- storage_name: 'default',
- relative_path: project.disk_path + '.git',
- gl_repository: "project-#{project.id}"
- }
+ context "when git_upload_pack action is passed" do
+ let(:action) { 'git_upload_pack' }
- expect(subject[:Repository]).to include(repo_param)
- end
+ it { expect(subject).to include(gitaly_params) }
- context "when git_upload_pack action is passed" do
- let(:action) { 'git_upload_pack' }
- let(:feature_flag) { :post_upload_pack }
+ context 'show_all_refs enabled' do
+ subject { described_class.git_http_ok(repository, Gitlab::GlRepository::PROJECT, user, action, show_all_refs: true) }
- it 'includes Gitaly params in the returned value' do
- allow(Gitlab::GitalyClient).to receive(:feature_enabled?).with(feature_flag).and_return(true)
+ it { is_expected.to include(ShowAllRefs: true) }
+ end
- expect(subject).to include(gitaly_params)
+ context 'when a feature flag is set for a single project' do
+ before do
+ stub_feature_flags(gitaly_mep_mep: project)
end
- context 'show_all_refs enabled' do
- subject { described_class.git_http_ok(repository, Gitlab::GlRepository::PROJECT, user, action, show_all_refs: true) }
+ it 'sets the flag to true for that project' do
+ response = described_class.git_http_ok(repository, Gitlab::GlRepository::PROJECT, user, action)
- it { is_expected.to include(ShowAllRefs: true) }
+ expect(response.dig(:GitalyServer, :call_metadata)).to include('gitaly-feature-enforce-requests-limits' => 'true',
+ 'gitaly-feature-mep-mep' => 'true')
end
- context 'when a feature flag is set for a single project' do
- before do
- stub_feature_flags(gitaly_mep_mep: project)
- end
+ it 'sets the flag to false for other projects' do
+ other_project = create(:project, :public, :repository)
+ response = described_class.git_http_ok(other_project.repository, Gitlab::GlRepository::PROJECT, user, action)
- it 'sets the flag to true for that project' do
- response = described_class.git_http_ok(repository, Gitlab::GlRepository::PROJECT, user, action)
-
- expect(response.dig(:GitalyServer, :features)).to eq('gitaly-feature-enforce-requests-limits' => 'true',
- 'gitaly-feature-mep-mep' => 'true')
- end
-
- it 'sets the flag to false for other projects' do
- other_project = create(:project, :public, :repository)
- response = described_class.git_http_ok(other_project.repository, Gitlab::GlRepository::PROJECT, user, action)
-
- expect(response.dig(:GitalyServer, :features)).to eq('gitaly-feature-enforce-requests-limits' => 'true',
- 'gitaly-feature-mep-mep' => 'false')
- end
+ expect(response.dig(:GitalyServer, :call_metadata)).to include('gitaly-feature-enforce-requests-limits' => 'true',
+ 'gitaly-feature-mep-mep' => 'false')
+ end
- it 'sets the flag to false when there is no project' do
- snippet = create(:personal_snippet, :repository)
- response = described_class.git_http_ok(snippet.repository, Gitlab::GlRepository::SNIPPET, user, action)
+ it 'sets the flag to false when there is no project' do
+ snippet = create(:personal_snippet, :repository)
+ response = described_class.git_http_ok(snippet.repository, Gitlab::GlRepository::SNIPPET, user, action)
- expect(response.dig(:GitalyServer, :features)).to eq('gitaly-feature-enforce-requests-limits' => 'true',
- 'gitaly-feature-mep-mep' => 'false')
- end
+ expect(response.dig(:GitalyServer, :call_metadata)).to include('gitaly-feature-enforce-requests-limits' => 'true',
+ 'gitaly-feature-mep-mep' => 'false')
end
end
+ end
- context "when git_receive_pack action is passed" do
- let(:action) { 'git_receive_pack' }
+ context "when git_receive_pack action is passed" do
+ let(:action) { 'git_receive_pack' }
- it { expect(subject).to include(gitaly_params) }
- end
+ it { expect(subject).to include(gitaly_params) }
+ end
- context "when info_refs action is passed" do
- let(:action) { 'info_refs' }
+ context "when info_refs action is passed" do
+ let(:action) { 'info_refs' }
- it { expect(subject).to include(gitaly_params) }
+ it { expect(subject).to include(gitaly_params) }
- context 'show_all_refs enabled' do
- subject { described_class.git_http_ok(repository, Gitlab::GlRepository::PROJECT, user, action, show_all_refs: true) }
+ context 'show_all_refs enabled' do
+ subject { described_class.git_http_ok(repository, Gitlab::GlRepository::PROJECT, user, action, show_all_refs: true) }
- it { is_expected.to include(ShowAllRefs: true) }
- end
+ it { is_expected.to include(ShowAllRefs: true) }
end
+ end
- context 'when action passed is not supported by Gitaly' do
- let(:action) { 'download' }
+ context 'when action passed is not supported by Gitaly' do
+ let(:action) { 'download' }
- it { expect { subject }.to raise_exception('Unsupported action: download') }
- end
+ it { expect { subject }.to raise_exception('Unsupported action: download') }
end
context 'when receive_max_input_size has been updated' do
@@ -349,6 +346,23 @@ RSpec.describe Gitlab::Workhorse do
expect(subject[:GitConfigOptions]).to be_empty
end
end
+
+ context 'when remote_ip is available in the application context' do
+ it 'includes a RemoteIP params' do
+ result = {}
+ Gitlab::ApplicationContext.with_context(remote_ip: "1.2.3.4") do
+ result = described_class.git_http_ok(repository, Gitlab::GlRepository::PROJECT, user, action)
+ end
+ expect(result[:GitalyServer][:call_metadata]['remote_ip']).to eql("1.2.3.4")
+ end
+ end
+
+ context 'when remote_ip is not available in the application context' do
+ it 'does not include RemoteIP params' do
+ result = described_class.git_http_ok(repository, Gitlab::GlRepository::PROJECT, user, action)
+ expect(result[:GitalyServer][:call_metadata]).not_to have_key('remote_ip')
+ end
+ end
end
describe '.set_key_and_notify' do
@@ -428,7 +442,7 @@ RSpec.describe Gitlab::Workhorse do
expect(command).to eq('git-blob')
expect(params).to eq({
'GitalyServer' => {
- features: { 'gitaly-feature-enforce-requests-limits' => 'true' },
+ 'call_metadata' => features,
address: Gitlab::GitalyClient.address(project.repository_storage),
token: Gitlab::GitalyClient.token(project.repository_storage)
},
@@ -508,7 +522,7 @@ RSpec.describe Gitlab::Workhorse do
expect(command).to eq('git-snapshot')
expect(params).to eq(
'GitalyServer' => {
- 'features' => { 'gitaly-feature-enforce-requests-limits' => 'true' },
+ 'call_metadata' => features,
'address' => Gitlab::GitalyClient.address(project.repository_storage),
'token' => Gitlab::GitalyClient.token(project.repository_storage)
},