diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-06-06 21:07:33 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-06-06 21:07:33 +0300 |
commit | 9e5484cee690f8bb2c1796013345d8cbc1872d77 (patch) | |
tree | 7b5c95c7de5eaba5ebb053da65c83184af1cf74c /spec/models | |
parent | 638e2f1c5f55988135da63c7aa57bcecb9355a2b (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/models')
-rw-r--r-- | spec/models/application_setting_spec.rb | 40 | ||||
-rw-r--r-- | spec/models/ci/pipeline_spec.rb | 22 | ||||
-rw-r--r-- | spec/models/namespace_setting_spec.rb | 45 |
3 files changed, 107 insertions, 0 deletions
diff --git a/spec/models/application_setting_spec.rb b/spec/models/application_setting_spec.rb index f94dc059ea0..bac9b58056b 100644 --- a/spec/models/application_setting_spec.rb +++ b/spec/models/application_setting_spec.rb @@ -23,6 +23,7 @@ RSpec.describe ApplicationSetting, feature_category: :shared, type: :model do it { expect(setting.id).to eq(1) } it { expect(setting.repository_storages_weighted).to eq({}) } it { expect(setting.kroki_formats).to eq({}) } + it { expect(setting.default_branch_protection_defaults).to eq({}) } end describe 'validations' do @@ -1228,6 +1229,25 @@ RSpec.describe ApplicationSetting, feature_category: :shared, type: :model do it { is_expected.to allow_value(*Gitlab::ColorSchemes.valid_ids).for(:default_syntax_highlighting_theme) } it { is_expected.not_to allow_value(nil, 0, Gitlab::ColorSchemes.available_schemes.size + 1).for(:default_syntax_highlighting_theme) } end + + context 'default_branch_protections_defaults validations' do + let(:charset) { [*'a'..'z'] + [*0..9] } + let(:value) { Array.new(byte_size) { charset.sample }.join } + + it { expect(described_class).to validate_jsonb_schema(['default_branch_protection_defaults']) } + + context 'when json is more than 1kb' do + let(:byte_size) { 1.1.kilobytes } + + it { is_expected.not_to allow_value({ name: value }).for(:default_branch_protection_defaults) } + end + + context 'when json less than 1kb' do + let(:byte_size) { 0.5.kilobytes } + + it { is_expected.to allow_value({ name: value }).for(:default_branch_protection_defaults) } + end + end end context 'restrict creating duplicates' do @@ -1498,6 +1518,26 @@ RSpec.describe ApplicationSetting, feature_category: :shared, type: :model do end end + describe 'default_branch_protection_defaults' do + let(:defaults) { { name: 'main', push_access_level: 30, merge_access_level: 30, unprotect_access_level: 40 } } + + it 'returns the value for default_branch_protection_defaults' do + subject.default_branch_protection_defaults = defaults + expect(subject.default_branch_protection_defaults['name']).to eq('main') + expect(subject.default_branch_protection_defaults['push_access_level']).to eq(30) + expect(subject.default_branch_protection_defaults['merge_access_level']).to eq(30) + expect(subject.default_branch_protection_defaults['unprotect_access_level']).to eq(40) + end + + context 'when provided with content that does not match the JSON schema' do + # valid json + it { is_expected.to allow_value({ name: 'bar' }).for(:default_branch_protection_defaults) } + + # invalid json + it { is_expected.not_to allow_value({ foo: 'bar' }).for(:default_branch_protection_defaults) } + end + end + describe '#static_objects_external_storage_auth_token=', :aggregate_failures do subject { setting.static_objects_external_storage_auth_token = token } diff --git a/spec/models/ci/pipeline_spec.rb b/spec/models/ci/pipeline_spec.rb index b336018247c..46d050c0625 100644 --- a/spec/models/ci/pipeline_spec.rb +++ b/spec/models/ci/pipeline_spec.rb @@ -498,6 +498,28 @@ RSpec.describe Ci::Pipeline, :mailer, factory_default: :keep, feature_category: end end + describe '.ci_and_security_orchestration_sources' do + subject { described_class.ci_and_security_orchestration_sources } + + let_it_be(:push_pipeline) { create(:ci_pipeline, source: :push) } + let_it_be(:web_pipeline) { create(:ci_pipeline, source: :web) } + let_it_be(:api_pipeline) { create(:ci_pipeline, source: :api) } + let_it_be(:webide_pipeline) { create(:ci_pipeline, source: :webide) } + let_it_be(:child_pipeline) { create(:ci_pipeline, source: :parent_pipeline) } + let_it_be(:merge_request_pipeline) { create(:ci_pipeline, :detached_merge_request_pipeline) } + let_it_be(:sec_orchestration_pipeline) { create(:ci_pipeline, :security_orchestration_policy) } + + it 'contains pipelines having CI and security_orchestration_policy sources' do + expect(subject).to contain_exactly(push_pipeline, web_pipeline, api_pipeline, merge_request_pipeline, sec_orchestration_pipeline) + end + + it 'filters on expected sources' do + expect(::Enums::Ci::Pipeline.ci_and_security_orchestration_sources.keys).to contain_exactly( + *%i[unknown push web trigger schedule api external pipeline chat merge_request_event + external_pull_request_event security_orchestration_policy]) + end + end + describe '.outside_pipeline_family' do subject(:outside_pipeline_family) { described_class.outside_pipeline_family(upstream_pipeline) } diff --git a/spec/models/namespace_setting_spec.rb b/spec/models/namespace_setting_spec.rb index 9ccb40705c4..a937a3e8988 100644 --- a/spec/models/namespace_setting_spec.rb +++ b/spec/models/namespace_setting_spec.rb @@ -14,6 +14,12 @@ RSpec.describe NamespaceSetting, feature_category: :groups_and_projects, type: : it { is_expected.to define_enum_for(:jobs_to_be_done).with_values([:basics, :move_repository, :code_storage, :exploring, :ci, :other]).with_suffix } it { is_expected.to define_enum_for(:enabled_git_access_protocol).with_values([:all, :ssh, :http]).with_suffix } + describe 'default values' do + subject(:setting) { described_class.new } + + it { expect(setting.default_branch_protection_defaults).to eq({}) } + end + describe "validations" do it { is_expected.to validate_inclusion_of(:code_suggestions).in_array([true, false]) } @@ -138,6 +144,25 @@ RSpec.describe NamespaceSetting, feature_category: :groups_and_projects, type: : end end end + + context 'default_branch_protections_defaults validations' do + let(:charset) { [*'a'..'z'] + [*0..9] } + let(:value) { Array.new(byte_size) { charset.sample }.join } + + it { expect(described_class).to validate_jsonb_schema(['default_branch_protection_defaults']) } + + context 'when json is more than 1kb' do + let(:byte_size) { 1.1.kilobytes } + + it { is_expected.not_to allow_value({ name: value }).for(:default_branch_protection_defaults) } + end + + context 'when json less than 1kb' do + let(:byte_size) { 0.5.kilobytes } + + it { is_expected.to allow_value({ name: value }).for(:default_branch_protection_defaults) } + end + end end describe '#prevent_sharing_groups_outside_hierarchy' do @@ -404,4 +429,24 @@ RSpec.describe NamespaceSetting, feature_category: :groups_and_projects, type: : describe '#delayed_project_removal' do it_behaves_like 'a cascading namespace setting boolean attribute', settings_attribute_name: :delayed_project_removal end + + describe 'default_branch_protection_defaults' do + let(:defaults) { { name: 'main', push_access_level: 30, merge_access_level: 30, unprotect_access_level: 40 } } + + it 'returns the value for default_branch_protection_defaults' do + subject.default_branch_protection_defaults = defaults + expect(subject.default_branch_protection_defaults['name']).to eq('main') + expect(subject.default_branch_protection_defaults['push_access_level']).to eq(30) + expect(subject.default_branch_protection_defaults['merge_access_level']).to eq(30) + expect(subject.default_branch_protection_defaults['unprotect_access_level']).to eq(40) + end + + context 'when provided with content that does not match the JSON schema' do + # valid json + it { is_expected.to allow_value({ name: 'bar' }).for(:default_branch_protection_defaults) } + + # invalid json + it { is_expected.not_to allow_value({ foo: 'bar' }).for(:default_branch_protection_defaults) } + end + end end |