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
path: root/spec/lib
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2024-01-19 18:10:53 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2024-01-19 18:10:53 +0300
commit8f3a9dbb94b5a9ae4570a22bbc2a75e7572407c8 (patch)
tree0d7e5d6d5747b57a93df1181bd86a7a127c16934 /spec/lib
parent7344cec8c24f1599086498ba19096cf9918ee168 (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/lib')
-rw-r--r--spec/lib/api/entities/group_detail_spec.rb46
-rw-r--r--spec/lib/gitlab/click_house_spec.rb17
-rw-r--r--spec/lib/gitlab/gitaly_client_spec.rb14
-rw-r--r--spec/lib/gitlab/http_connection_adapter_spec.rb161
-rw-r--r--spec/lib/gitlab/import_export/all_models.yml1
-rw-r--r--spec/lib/gitlab/import_export/remote_stream_upload_spec.rb26
-rw-r--r--spec/lib/gitlab/metrics/global_search_slis_spec.rb48
7 files changed, 135 insertions, 178 deletions
diff --git a/spec/lib/api/entities/group_detail_spec.rb b/spec/lib/api/entities/group_detail_spec.rb
index 8fcb120c809..f3200b28c4d 100644
--- a/spec/lib/api/entities/group_detail_spec.rb
+++ b/spec/lib/api/entities/group_detail_spec.rb
@@ -2,18 +2,50 @@
require 'spec_helper'
-RSpec.describe API::Entities::GroupDetail do
+RSpec.describe API::Entities::GroupDetail, feature_category: :groups_and_projects do
describe '#as_json' do
- it 'includes prevent_sharing_groups_outside_hierarchy for a root group' do
- group = create(:group)
+ subject { described_class.new(group, options).as_json }
- expect(described_class.new(group).as_json).to include(prevent_sharing_groups_outside_hierarchy: false)
+ let_it_be(:root_group) { create(:group) }
+ let_it_be(:subgroup) { create(:group, :nested) }
+
+ let(:options) { {} }
+
+ describe '#prevent_sharing_groups_outside_hierarchy' do
+ context 'for a root group' do
+ let(:group) { root_group }
+
+ it { is_expected.to include(:prevent_sharing_groups_outside_hierarchy) }
+ end
+
+ context 'for a subgroup' do
+ let(:group) { subgroup }
+
+ it { is_expected.not_to include(:prevent_sharing_groups_outside_hierarchy) }
+ end
end
- it 'excludes prevent_sharing_groups_outside_hierarchy for a subgroup' do
- subgroup = build(:group, :nested)
+ describe '#enabled_git_access_protocol' do
+ using RSpec::Parameterized::TableSyntax
+
+ where(:group, :can_admin_group, :includes_field) do
+ ref(:root_group) | false | false
+ ref(:root_group) | true | true
+ ref(:subgroup) | false | false
+ ref(:subgroup) | true | false
+ end
+
+ with_them do
+ let(:options) { { user_can_admin_group: can_admin_group } }
- expect(described_class.new(subgroup).as_json.keys).not_to include(:prevent_sharing_groups_outside_hierarchy)
+ it 'verifies presence of the field' do
+ if includes_field
+ is_expected.to include(:enabled_git_access_protocol)
+ else
+ is_expected.not_to include(:enabled_git_access_protocol)
+ end
+ end
+ end
end
end
end
diff --git a/spec/lib/gitlab/click_house_spec.rb b/spec/lib/gitlab/click_house_spec.rb
new file mode 100644
index 00000000000..3241eca34ae
--- /dev/null
+++ b/spec/lib/gitlab/click_house_spec.rb
@@ -0,0 +1,17 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+RSpec.describe Gitlab::ClickHouse, feature_category: :database do
+ context 'when ClickHouse is not configured' do
+ it 'returns false' do
+ expect(described_class).not_to be_configured
+ end
+ end
+
+ context 'when ClickHouse is configured', :click_house do
+ it 'returns false' do
+ expect(described_class).to be_configured
+ end
+ end
+end
diff --git a/spec/lib/gitlab/gitaly_client_spec.rb b/spec/lib/gitlab/gitaly_client_spec.rb
index 796fe75521a..5ff3bc20bc1 100644
--- a/spec/lib/gitlab/gitaly_client_spec.rb
+++ b/spec/lib/gitlab/gitaly_client_spec.rb
@@ -365,6 +365,20 @@ RSpec.describe Gitlab::GitalyClient, feature_category: :gitaly do
it 'returns the result of the allow_n_plus_1_calls block' do
expect(described_class.allow_n_plus_1_calls { "result" }).to eq("result")
end
+
+ context 'when the `gitaly_call_count_exception_block_depth` key is not present' do
+ before do
+ allow(Gitlab::SafeRequestStore).to receive(:[]).with(:gitaly_call_count_exception_block_depth).and_return(0, 1, nil)
+ allow(Gitlab::SafeRequestStore).to receive(:+)
+ allow(Gitlab::SafeRequestStore).to receive(:-)
+ end
+
+ it 'does not decrement call count' do
+ expect(Gitlab::SafeRequestStore).not_to have_received(:-)
+
+ described_class.allow_n_plus_1_calls { "result" }
+ end
+ end
end
context 'when RequestStore is not active' do
diff --git a/spec/lib/gitlab/http_connection_adapter_spec.rb b/spec/lib/gitlab/http_connection_adapter_spec.rb
deleted file mode 100644
index fac0c1a2a9f..00000000000
--- a/spec/lib/gitlab/http_connection_adapter_spec.rb
+++ /dev/null
@@ -1,161 +0,0 @@
-# frozen_string_literal: true
-
-require 'spec_helper'
-
-RSpec.describe Gitlab::HTTPConnectionAdapter, feature_category: :shared do
- include StubRequests
-
- let(:uri) { URI('https://example.org') }
- let(:options) { {} }
-
- subject(:connection) { described_class.new(uri, options).connection }
-
- describe '#connection' do
- before do
- stub_all_dns('https://example.org', ip_address: '93.184.216.34')
- end
-
- context 'when local requests are allowed' do
- let(:options) { { allow_local_requests: true } }
-
- it 'sets up the connection' do
- expect(connection).to be_a(Gitlab::NetHttpAdapter)
- expect(connection.address).to eq('93.184.216.34')
- expect(connection.hostname_override).to eq('example.org')
- expect(connection.addr_port).to eq('example.org')
- expect(connection.port).to eq(443)
- end
- end
-
- context 'when local requests are not allowed' do
- let(:options) { { allow_local_requests: false } }
-
- it 'sets up the connection' do
- expect(connection).to be_a(Gitlab::NetHttpAdapter)
- expect(connection.address).to eq('93.184.216.34')
- expect(connection.hostname_override).to eq('example.org')
- expect(connection.addr_port).to eq('example.org')
- expect(connection.port).to eq(443)
- end
-
- context 'when it is a request to local network' do
- let(:uri) { URI('http://172.16.0.0/12') }
-
- it 'raises error' do
- expect { subject }.to raise_error(
- Gitlab::HTTP::BlockedUrlError,
- "URL is blocked: Requests to the local network are not allowed"
- )
- end
-
- context 'when local request allowed' do
- let(:options) { { allow_local_requests: true } }
-
- it 'sets up the connection' do
- expect(connection).to be_a(Gitlab::NetHttpAdapter)
- expect(connection.address).to eq('172.16.0.0')
- expect(connection.hostname_override).to be(nil)
- expect(connection.addr_port).to eq('172.16.0.0')
- expect(connection.port).to eq(80)
- end
- end
- end
-
- context 'when it is a request to local address' do
- let(:uri) { URI('http://127.0.0.1') }
-
- it 'raises error' do
- expect { subject }.to raise_error(
- Gitlab::HTTP::BlockedUrlError,
- "URL is blocked: Requests to localhost are not allowed"
- )
- end
-
- context 'when local request allowed' do
- let(:options) { { allow_local_requests: true } }
-
- it 'sets up the connection' do
- expect(connection).to be_a(Gitlab::NetHttpAdapter)
- expect(connection.address).to eq('127.0.0.1')
- expect(connection.hostname_override).to be(nil)
- expect(connection.addr_port).to eq('127.0.0.1')
- expect(connection.port).to eq(80)
- end
- end
- end
-
- context 'when port different from URL scheme is used' do
- let(:uri) { URI('https://example.org:8080') }
-
- it 'sets up the addr_port accordingly' do
- expect(connection).to be_a(Gitlab::NetHttpAdapter)
- expect(connection.address).to eq('93.184.216.34')
- expect(connection.hostname_override).to eq('example.org')
- expect(connection.addr_port).to eq('example.org:8080')
- expect(connection.port).to eq(8080)
- end
- 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).to be_a(Gitlab::NetHttpAdapter)
- expect(connection.address).to eq('example.org')
- expect(connection.hostname_override).to eq(nil)
- expect(connection.addr_port).to eq('example.org')
- expect(connection.port).to eq(443)
- end
- end
-
- context 'when proxy is enabled' do
- before do
- stub_env('http_proxy', 'http://proxy.example.com')
- end
-
- it 'proxy stays configured' do
- expect(connection.proxy?).to be true
- expect(connection.proxy_from_env?).to be true
- expect(connection.proxy_address).to eq('proxy.example.com')
- end
-
- context 'when no_proxy matches the request' do
- before do
- stub_env('no_proxy', 'example.org')
- end
-
- it 'proxy is disabled' do
- expect(connection.proxy?).to be false
- expect(connection.proxy_from_env?).to be false
- expect(connection.proxy_address).to be nil
- end
- end
-
- context 'when no_proxy does not match the request' do
- before do
- stub_env('no_proxy', 'example.com')
- end
-
- it 'proxy stays configured' do
- expect(connection.proxy?).to be true
- expect(connection.proxy_from_env?).to be true
- expect(connection.proxy_address).to eq('proxy.example.com')
- end
- end
- end
-
- context 'when URL scheme is not HTTP/HTTPS' do
- let(:uri) { URI('ssh://example.org') }
-
- it 'raises error' do
- expect { subject }.to raise_error(
- Gitlab::HTTP::BlockedUrlError,
- "URL is blocked: Only allowed schemes are http, https"
- )
- end
- end
- end
-end
diff --git a/spec/lib/gitlab/import_export/all_models.yml b/spec/lib/gitlab/import_export/all_models.yml
index 6d5c17176dc..9e83b7d85e9 100644
--- a/spec/lib/gitlab/import_export/all_models.yml
+++ b/spec/lib/gitlab/import_export/all_models.yml
@@ -1010,6 +1010,7 @@ epic:
- user_note_authors
- boards_epic_user_preferences
- epic_board_positions
+- work_item
epic_issue:
- epic
- issue
diff --git a/spec/lib/gitlab/import_export/remote_stream_upload_spec.rb b/spec/lib/gitlab/import_export/remote_stream_upload_spec.rb
index 3d9d6e1b96b..c27bc7b5fe1 100644
--- a/spec/lib/gitlab/import_export/remote_stream_upload_spec.rb
+++ b/spec/lib/gitlab/import_export/remote_stream_upload_spec.rb
@@ -23,10 +23,14 @@ RSpec.describe Gitlab::ImportExport::RemoteStreamUpload do
describe '#execute' do
context 'when download request and upload request return 200' do
- it 'uploads the downloaded content' do
+ before do
+ stub_application_setting(allow_local_requests_from_web_hooks_and_services: true)
+ stub_application_setting(dns_rebinding_protection_enabled: false)
stub_request(:get, download_url).to_return(status: 200, body: 'ABC', headers: { 'Content-Length' => 3 })
stub_request(:post, upload_url)
+ end
+ it 'uploads the downloaded content' do
subject.execute
expect(
@@ -35,6 +39,16 @@ RSpec.describe Gitlab::ImportExport::RemoteStreamUpload do
)
).to have_been_made
end
+
+ it 'calls the connection adapter twice with required args' do
+ expect(Gitlab::HTTP_V2::NewConnectionAdapter)
+ .to receive(:new).twice.with(instance_of(URI::HTTP), {
+ allow_local_requests: true,
+ dns_rebind_protection: false
+ }).and_call_original
+
+ subject.execute
+ end
end
context 'when upload method is put' do
@@ -87,7 +101,7 @@ RSpec.describe Gitlab::ImportExport::RemoteStreamUpload do
it 'raises error' do
expect { subject.execute }.to raise_error(
- Gitlab::HTTP::BlockedUrlError,
+ Gitlab::HTTP_V2::BlockedUrlError,
"URL is blocked: Requests to localhost are not allowed"
)
end
@@ -113,7 +127,7 @@ RSpec.describe Gitlab::ImportExport::RemoteStreamUpload do
it 'raises error' do
expect { subject.execute }.to raise_error(
- Gitlab::HTTP::BlockedUrlError,
+ Gitlab::HTTP_V2::BlockedUrlError,
"URL is blocked: Requests to the local network are not allowed"
)
end
@@ -141,7 +155,7 @@ RSpec.describe Gitlab::ImportExport::RemoteStreamUpload do
stub_request(:get, download_url)
expect { subject.execute }.to raise_error(
- Gitlab::HTTP::BlockedUrlError,
+ Gitlab::HTTP_V2::BlockedUrlError,
"URL is blocked: Requests to localhost are not allowed"
)
end
@@ -167,7 +181,7 @@ RSpec.describe Gitlab::ImportExport::RemoteStreamUpload do
it 'raises error' do
expect { subject.execute }.to raise_error(
- Gitlab::HTTP::BlockedUrlError,
+ Gitlab::HTTP_V2::BlockedUrlError,
"URL is blocked: Requests to the local network are not allowed"
)
end
@@ -191,7 +205,7 @@ RSpec.describe Gitlab::ImportExport::RemoteStreamUpload do
stub_full_request(upload_url, ip_address: '127.0.0.1', method: upload_method)
expect { subject.execute }.to raise_error(
- Gitlab::HTTP::BlockedUrlError,
+ Gitlab::HTTP_V2::BlockedUrlError,
"URL is blocked: Requests to localhost are not allowed"
)
end
diff --git a/spec/lib/gitlab/metrics/global_search_slis_spec.rb b/spec/lib/gitlab/metrics/global_search_slis_spec.rb
index 68793db6e41..9aa4f3b106e 100644
--- a/spec/lib/gitlab/metrics/global_search_slis_spec.rb
+++ b/spec/lib/gitlab/metrics/global_search_slis_spec.rb
@@ -87,6 +87,10 @@ RSpec.describe Gitlab::Metrics::GlobalSearchSlis, feature_category: :global_sear
end
describe '#record_apdex' do
+ before do
+ allow(::Gitlab::ApplicationContext).to receive(:current_context_attribute).with(:caller_id).and_return('end')
+ end
+
where(:search_type, :code_search, :duration_target) do
'basic' | false | 8.812
'basic' | true | 27.538
@@ -96,10 +100,6 @@ RSpec.describe Gitlab::Metrics::GlobalSearchSlis, feature_category: :global_sear
end
with_them do
- before do
- allow(::Gitlab::ApplicationContext).to receive(:current_context_attribute).with(:caller_id).and_return('end')
- end
-
let(:search_scope) { code_search ? 'blobs' : 'issues' }
it 'increments the global_search SLI as a success if the elapsed time is within the target' do
@@ -144,6 +144,46 @@ RSpec.describe Gitlab::Metrics::GlobalSearchSlis, feature_category: :global_sear
)
end
end
+
+ context 'when the search scope is merge_requests and the search type is basic' do
+ it 'increments the global_search SLI as a success if the elapsed time is within the target' do
+ expect(Gitlab::Metrics::Sli::Apdex[:global_search]).to receive(:increment).with(
+ labels: {
+ search_type: 'basic',
+ search_level: 'global',
+ search_scope: 'merge_requests',
+ endpoint_id: 'end'
+ },
+ success: true
+ )
+
+ described_class.record_apdex(
+ elapsed: 14,
+ search_type: 'basic',
+ search_level: 'global',
+ search_scope: 'merge_requests'
+ )
+ end
+
+ it 'increments the global_search SLI as a failure if the elapsed time is not within the target' do
+ expect(Gitlab::Metrics::Sli::Apdex[:global_search]).to receive(:increment).with(
+ labels: {
+ search_type: 'basic',
+ search_level: 'global',
+ search_scope: 'merge_requests',
+ endpoint_id: 'end'
+ },
+ success: false
+ )
+
+ described_class.record_apdex(
+ elapsed: 16,
+ search_type: 'basic',
+ search_level: 'global',
+ search_scope: 'merge_requests'
+ )
+ end
+ end
end
describe '#record_error_rate' do