2019-01-03 16:17:44 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-24 05:08:32 -04:00
|
|
|
RSpec.describe ApplicationSettingsHelper do
|
2019-01-03 16:17:44 -05:00
|
|
|
context 'when all protocols in use' do
|
|
|
|
before do
|
|
|
|
stub_application_setting(enabled_git_access_protocol: '')
|
|
|
|
end
|
|
|
|
|
|
|
|
it { expect(all_protocols_enabled?).to be_truthy }
|
|
|
|
it { expect(http_enabled?).to be_truthy }
|
|
|
|
it { expect(ssh_enabled?).to be_truthy }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when SSH is only in use' do
|
|
|
|
before do
|
|
|
|
stub_application_setting(enabled_git_access_protocol: 'ssh')
|
|
|
|
end
|
|
|
|
|
|
|
|
it { expect(all_protocols_enabled?).to be_falsey }
|
|
|
|
it { expect(http_enabled?).to be_falsey }
|
|
|
|
it { expect(ssh_enabled?).to be_truthy }
|
|
|
|
end
|
|
|
|
|
|
|
|
shared_examples 'when HTTP protocol is in use' do |protocol|
|
|
|
|
before do
|
|
|
|
allow(Gitlab.config.gitlab).to receive(:protocol).and_return(protocol)
|
|
|
|
stub_application_setting(enabled_git_access_protocol: 'http')
|
|
|
|
end
|
|
|
|
|
|
|
|
it { expect(all_protocols_enabled?).to be_falsey }
|
|
|
|
it { expect(http_enabled?).to be_truthy }
|
|
|
|
it { expect(ssh_enabled?).to be_falsey }
|
|
|
|
end
|
|
|
|
|
|
|
|
it_behaves_like 'when HTTP protocol is in use', 'https'
|
|
|
|
it_behaves_like 'when HTTP protocol is in use', 'http'
|
2019-10-22 17:06:42 -04:00
|
|
|
|
2021-06-03 14:09:58 -04:00
|
|
|
describe '.visible_attributes' do
|
|
|
|
it 'contains tracking parameters' do
|
|
|
|
expect(helper.visible_attributes).to include(*%i(snowplow_collector_hostname snowplow_cookie_domain snowplow_enabled snowplow_app_id))
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'contains :deactivate_dormant_users' do
|
|
|
|
expect(helper.visible_attributes).to include(:deactivate_dormant_users)
|
|
|
|
end
|
|
|
|
|
2022-02-08 13:16:03 -05:00
|
|
|
it 'contains rate limit parameters' do
|
|
|
|
expect(helper.visible_attributes).to include(*%i(
|
|
|
|
issues_create_limit notes_create_limit project_export_limit
|
|
|
|
project_download_export_limit project_export_limit project_import_limit
|
|
|
|
raw_blob_request_limit group_export_limit group_download_export_limit
|
2022-03-14 02:07:47 -04:00
|
|
|
group_import_limit users_get_by_id_limit search_rate_limit search_rate_limit_unauthenticated
|
2022-02-08 13:16:03 -05:00
|
|
|
))
|
|
|
|
end
|
|
|
|
|
2021-06-03 14:09:58 -04:00
|
|
|
context 'when GitLab.com' do
|
|
|
|
before do
|
|
|
|
allow(Gitlab).to receive(:com?).and_return(true)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not contain :deactivate_dormant_users' do
|
|
|
|
expect(helper.visible_attributes).not_to include(:deactivate_dormant_users)
|
|
|
|
end
|
|
|
|
end
|
2019-11-04 01:06:46 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
describe '.integration_expanded?' do
|
|
|
|
let(:application_setting) { build(:application_setting) }
|
|
|
|
|
|
|
|
it 'is expanded' do
|
|
|
|
application_setting.plantuml_enabled = true
|
|
|
|
application_setting.valid?
|
|
|
|
helper.instance_variable_set(:@application_setting, application_setting)
|
|
|
|
|
|
|
|
expect(helper.integration_expanded?('plantuml_')).to be_truthy
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'is not expanded' do
|
|
|
|
application_setting.valid?
|
|
|
|
helper.instance_variable_set(:@application_setting, application_setting)
|
|
|
|
|
|
|
|
expect(helper.integration_expanded?('plantuml_')).to be_falsey
|
|
|
|
end
|
2019-10-22 17:06:42 -04:00
|
|
|
end
|
2020-01-08 04:07:53 -05:00
|
|
|
|
|
|
|
describe '.self_monitoring_project_data' do
|
|
|
|
context 'when self monitoring project does not exist' do
|
|
|
|
it 'returns create_self_monitoring_project_path' do
|
|
|
|
expect(helper.self_monitoring_project_data).to include(
|
|
|
|
'create_self_monitoring_project_path' =>
|
|
|
|
create_self_monitoring_project_admin_application_settings_path
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns status_create_self_monitoring_project_path' do
|
|
|
|
expect(helper.self_monitoring_project_data).to include(
|
|
|
|
'status_create_self_monitoring_project_path' =>
|
|
|
|
status_create_self_monitoring_project_admin_application_settings_path
|
2020-01-13 10:07:53 -05:00
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns delete_self_monitoring_project_path' do
|
|
|
|
expect(helper.self_monitoring_project_data).to include(
|
|
|
|
'delete_self_monitoring_project_path' =>
|
|
|
|
delete_self_monitoring_project_admin_application_settings_path
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns status_delete_self_monitoring_project_path' do
|
|
|
|
expect(helper.self_monitoring_project_data).to include(
|
|
|
|
'status_delete_self_monitoring_project_path' =>
|
|
|
|
status_delete_self_monitoring_project_admin_application_settings_path
|
2020-01-08 04:07:53 -05:00
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns self_monitoring_project_exists false' do
|
|
|
|
expect(helper.self_monitoring_project_data).to include(
|
2020-01-16 01:08:30 -05:00
|
|
|
'self_monitoring_project_exists' => "false"
|
2020-01-08 04:07:53 -05:00
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns nil for project full_path' do
|
|
|
|
expect(helper.self_monitoring_project_data).to include(
|
|
|
|
'self_monitoring_project_full_path' => nil
|
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when self monitoring project exists' do
|
|
|
|
let(:project) { build(:project) }
|
|
|
|
|
|
|
|
before do
|
2020-01-28 10:08:36 -05:00
|
|
|
stub_application_setting(self_monitoring_project: project)
|
2020-01-08 04:07:53 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns self_monitoring_project_exists true' do
|
|
|
|
expect(helper.self_monitoring_project_data).to include(
|
2020-01-16 01:08:30 -05:00
|
|
|
'self_monitoring_project_exists' => "true"
|
2020-01-08 04:07:53 -05:00
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns project full_path' do
|
|
|
|
expect(helper.self_monitoring_project_data).to include(
|
|
|
|
'self_monitoring_project_full_path' => project.full_path
|
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2020-06-16 08:09:00 -04:00
|
|
|
|
2022-04-04 23:08:30 -04:00
|
|
|
describe '#storage_weights' do
|
2020-06-16 08:09:00 -04:00
|
|
|
let(:application_setting) { build(:application_setting) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
helper.instance_variable_set(:@application_setting, application_setting)
|
|
|
|
stub_storage_settings({ 'default': {}, 'storage_1': {}, 'storage_2': {} })
|
|
|
|
stub_application_setting(repository_storages_weighted: { 'default' => 100, 'storage_1' => 50, 'storage_2' => nil })
|
|
|
|
end
|
|
|
|
|
2022-04-04 23:08:30 -04:00
|
|
|
it 'returns storage objects with assigned weights' do
|
|
|
|
expect(helper.storage_weights)
|
|
|
|
.to have_attributes(
|
|
|
|
default: 100,
|
|
|
|
storage_1: 50,
|
|
|
|
storage_2: 0
|
|
|
|
)
|
2020-06-16 08:09:00 -04:00
|
|
|
end
|
|
|
|
end
|
2020-10-05 14:08:51 -04:00
|
|
|
|
2021-06-21 17:08:33 -04:00
|
|
|
describe '.valid_runner_registrars' do
|
|
|
|
subject { helper.valid_runner_registrars }
|
|
|
|
|
|
|
|
context 'when only admins are permitted to register runners' do
|
|
|
|
before do
|
|
|
|
stub_application_setting(valid_runner_registrars: [])
|
|
|
|
end
|
|
|
|
|
|
|
|
it { is_expected.to eq [] }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when group and project users are permitted to register runners' do
|
|
|
|
before do
|
|
|
|
stub_application_setting(valid_runner_registrars: ApplicationSetting::VALID_RUNNER_REGISTRAR_TYPES)
|
|
|
|
end
|
|
|
|
|
|
|
|
it { is_expected.to eq ApplicationSetting::VALID_RUNNER_REGISTRAR_TYPES }
|
|
|
|
end
|
2020-10-05 14:08:51 -04:00
|
|
|
end
|
2020-11-16 04:09:18 -05:00
|
|
|
|
|
|
|
describe '.signup_enabled?' do
|
|
|
|
subject { helper.signup_enabled? }
|
|
|
|
|
|
|
|
context 'when signup is enabled' do
|
|
|
|
before do
|
|
|
|
stub_application_setting(signup_enabled: true)
|
|
|
|
end
|
|
|
|
|
|
|
|
it { is_expected.to be true }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when signup is disabled' do
|
|
|
|
before do
|
|
|
|
stub_application_setting(signup_enabled: false)
|
|
|
|
end
|
|
|
|
|
|
|
|
it { is_expected.to be false }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when `signup_enabled` is nil' do
|
|
|
|
before do
|
|
|
|
stub_application_setting(signup_enabled: nil)
|
|
|
|
end
|
|
|
|
|
|
|
|
it { is_expected.to be false }
|
|
|
|
end
|
|
|
|
end
|
2021-02-16 22:08:59 -05:00
|
|
|
|
|
|
|
describe '.kroki_available_formats' do
|
|
|
|
let(:application_setting) { build(:application_setting) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
helper.instance_variable_set(:@application_setting, application_setting)
|
|
|
|
stub_application_setting(kroki_formats: { 'blockdiag' => true, 'bpmn' => false, 'excalidraw' => false })
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns available formats correctly' do
|
|
|
|
expect(helper.kroki_available_formats).to eq([
|
|
|
|
{
|
|
|
|
name: 'kroki_formats_blockdiag',
|
2021-07-20 11:10:07 -04:00
|
|
|
label: 'BlockDiag (includes BlockDiag, SeqDiag, ActDiag, NwDiag, PacketDiag, and RackDiag)',
|
2021-02-16 22:08:59 -05:00
|
|
|
value: true
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'kroki_formats_bpmn',
|
|
|
|
label: 'BPMN',
|
|
|
|
value: false
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'kroki_formats_excalidraw',
|
|
|
|
label: 'Excalidraw',
|
|
|
|
value: false
|
|
|
|
}
|
|
|
|
])
|
|
|
|
end
|
|
|
|
end
|
2021-07-27 08:10:54 -04:00
|
|
|
|
|
|
|
describe '.pending_user_count' do
|
|
|
|
let(:user_cap) { 200 }
|
|
|
|
|
|
|
|
before do
|
|
|
|
stub_application_setting(new_user_signups_cap: user_cap)
|
|
|
|
end
|
|
|
|
|
|
|
|
subject(:pending_user_count) { helper.pending_user_count }
|
|
|
|
|
|
|
|
context 'when new_user_signups_cap is present' do
|
|
|
|
it 'returns the number of blocked pending users' do
|
|
|
|
create(:user, state: :blocked_pending_approval)
|
|
|
|
|
|
|
|
expect(pending_user_count).to eq 1
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2021-09-13 14:11:46 -04:00
|
|
|
|
2022-01-06 07:14:04 -05:00
|
|
|
describe '.registration_features_can_be_prompted?' do
|
|
|
|
subject { helper.registration_features_can_be_prompted? }
|
|
|
|
|
|
|
|
before do
|
|
|
|
if Gitlab.ee?
|
|
|
|
allow(License).to receive(:current).and_return(nil)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when service ping is enabled' do
|
|
|
|
before do
|
|
|
|
stub_application_setting(usage_ping_enabled: true)
|
|
|
|
end
|
|
|
|
|
|
|
|
it { is_expected.to be_falsey }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when service ping is disabled' do
|
|
|
|
before do
|
|
|
|
stub_application_setting(usage_ping_enabled: false)
|
|
|
|
end
|
|
|
|
|
|
|
|
it { is_expected.to be_truthy }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-09-13 14:11:46 -04:00
|
|
|
describe '#sidekiq_job_limiter_modes_for_select' do
|
|
|
|
subject { helper.sidekiq_job_limiter_modes_for_select }
|
|
|
|
|
|
|
|
it { is_expected.to eq([%w(Track track), %w(Compress compress)]) }
|
|
|
|
end
|
2022-03-14 14:07:46 -04:00
|
|
|
|
|
|
|
describe '#instance_clusters_enabled?' do
|
|
|
|
let_it_be(:user) { create(:user) }
|
|
|
|
|
|
|
|
subject { helper.instance_clusters_enabled? }
|
|
|
|
|
|
|
|
before do
|
|
|
|
allow(helper).to receive(:current_user).and_return(user)
|
|
|
|
allow(helper).to receive(:can?).with(user, :read_cluster, instance_of(Clusters::Instance)).and_return(true)
|
|
|
|
end
|
|
|
|
|
|
|
|
it { is_expected.to be_truthy}
|
|
|
|
|
|
|
|
context ':certificate_based_clusters feature flag is disabled' do
|
|
|
|
before do
|
|
|
|
stub_feature_flags(certificate_based_clusters: false)
|
|
|
|
end
|
|
|
|
|
|
|
|
it { is_expected.to be_falsey }
|
|
|
|
end
|
|
|
|
end
|
2019-01-03 16:17:44 -05:00
|
|
|
end
|