diff options
Diffstat (limited to 'spec/support/shared_contexts')
8 files changed, 115 insertions, 7 deletions
diff --git a/spec/support/shared_contexts/container_repositories_shared_context.rb b/spec/support/shared_contexts/container_repositories_shared_context.rb index a74b09d38bd..c3040a77517 100644 --- a/spec/support/shared_contexts/container_repositories_shared_context.rb +++ b/spec/support/shared_contexts/container_repositories_shared_context.rb @@ -14,7 +14,6 @@ RSpec.shared_context 'importable repositories' do before do stub_application_setting(container_registry_import_created_before: 1.day.ago) stub_feature_flags( - container_registry_phase_2_deny_list: false, container_registry_migration_limit_gitlab_org: false, container_registry_migration_phase2_all_plans: false ) diff --git a/spec/support/shared_contexts/graphql/resolvers/runners_resolver_shared_context.rb b/spec/support/shared_contexts/graphql/resolvers/runners_resolver_shared_context.rb index aa857cfdb70..1480b5f98e7 100644 --- a/spec/support/shared_contexts/graphql/resolvers/runners_resolver_shared_context.rb +++ b/spec/support/shared_contexts/graphql/resolvers/runners_resolver_shared_context.rb @@ -17,6 +17,6 @@ RSpec.shared_context 'runners resolver setup' do end let_it_be(:group_runner) { create(:ci_runner, :group, groups: [group], token: 'mnopqr', description: 'group runner', contacted_at: 2.seconds.ago) } - let_it_be(:subgroup_runner) { create(:ci_runner, :group, groups: [subgroup], token: 'mnopqr', description: 'subgroup runner', contacted_at: 1.second.ago) } + let_it_be(:subgroup_runner) { create(:ci_runner, :group, groups: [subgroup], token: '123456', description: 'subgroup runner', contacted_at: 1.second.ago) } let_it_be(:instance_runner) { create(:ci_runner, :instance, description: 'shared runner', token: 'stuvxz', contacted_at: 2.minutes.ago, tag_list: %w(instance_runner active_runner)) } end diff --git a/spec/support/shared_contexts/jobs/handling_retried_jobs_shared_context.rb b/spec/support/shared_contexts/jobs/handling_retried_jobs_shared_context.rb new file mode 100644 index 00000000000..428eff77373 --- /dev/null +++ b/spec/support/shared_contexts/jobs/handling_retried_jobs_shared_context.rb @@ -0,0 +1,26 @@ +# frozen_string_literal: true + +RSpec.shared_context 'when handling retried jobs' do |url| + let(:set_name) { 'retry' } + # Account for Sidekiq retry jitter + # https://github.com/mperham/sidekiq/blob/3575ccb44c688dd08bfbfd937696260b12c622fb/lib/sidekiq/job_retry.rb#L217 + let(:schedule_jitter) { 10 } + + # Try to mimic as closely as possible what Sidekiq will actually + # do to retry a job. + def retry_in(klass, time, args = 0) + message = Gitlab::Json.generate( + 'class' => klass.name, + 'args' => [args], + 'retry' => true + ) + + allow(klass).to receive(:sidekiq_retry_in_block).and_return(proc { time.to_i }) + + begin + Sidekiq::JobRetry.new(Sidekiq).local(klass, message, klass.queue) { raise 'boom' } + rescue Sidekiq::JobRetry::Skip + # Sidekiq scheduled the retry + end + end +end diff --git a/spec/support/shared_contexts/lib/sbom/package_url_shared_contexts.rb b/spec/support/shared_contexts/lib/sbom/package_url_shared_contexts.rb new file mode 100644 index 00000000000..263cf9f5e19 --- /dev/null +++ b/spec/support/shared_contexts/lib/sbom/package_url_shared_contexts.rb @@ -0,0 +1,26 @@ +# frozen_string_literal: true + +require 'oj' + +def parameterized_test_matrix(invalid: false) + test_cases_path = File.join( + File.expand_path(__dir__), '..', '..', '..', '..', 'fixtures', 'lib', 'sbom', 'package-url-test-cases.json') + test_cases = Gitlab::Json.parse(File.read(test_cases_path)) + + test_cases.filter { _1.delete('is_invalid') == invalid }.each_with_object({}) do |test_case, memo| + description = test_case.delete('description') + memo[description] = test_case.symbolize_keys + end +end + +RSpec.shared_context 'with valid purl examples' do + where do + parameterized_test_matrix(invalid: false) + end +end + +RSpec.shared_context 'with invalid purl examples' do + where do + parameterized_test_matrix(invalid: true) + end +end diff --git a/spec/support/shared_contexts/navbar_structure_context.rb b/spec/support/shared_contexts/navbar_structure_context.rb index 064e40287be..af35a5ff068 100644 --- a/spec/support/shared_contexts/navbar_structure_context.rb +++ b/spec/support/shared_contexts/navbar_structure_context.rb @@ -67,8 +67,8 @@ RSpec.shared_context 'project navbar structure' do { nav_item: _('Deployments'), nav_sub_items: [ - _('Feature Flags'), _('Environments'), + _('Feature Flags'), _('Releases') ] }, @@ -85,8 +85,7 @@ RSpec.shared_context 'project navbar structure' do _('Metrics'), _('Error Tracking'), _('Alerts'), - _('Incidents'), - _('Product Analytics') + _('Incidents') ] }, { diff --git a/spec/support/shared_contexts/policies/group_policy_shared_context.rb b/spec/support/shared_contexts/policies/group_policy_shared_context.rb index bb1b794c2b6..a6226fe903b 100644 --- a/spec/support/shared_contexts/policies/group_policy_shared_context.rb +++ b/spec/support/shared_contexts/policies/group_policy_shared_context.rb @@ -76,6 +76,7 @@ RSpec.shared_context 'GroupPolicy context' do register_group_runners read_billing edit_billing + admin_member_access_request ] end diff --git a/spec/support/shared_contexts/policies/project_policy_shared_context.rb b/spec/support/shared_contexts/policies/project_policy_shared_context.rb index fc7255a4a20..6e2caa853f8 100644 --- a/spec/support/shared_contexts/policies/project_policy_shared_context.rb +++ b/spec/support/shared_contexts/policies/project_policy_shared_context.rb @@ -68,7 +68,7 @@ RSpec.shared_context 'ProjectPolicy context' do admin_project admin_project_member admin_snippet admin_terraform_state admin_wiki create_deploy_token destroy_deploy_token push_to_delete_protected_branch read_deploy_token update_snippet - destroy_upload + destroy_upload admin_member_access_request rename_project ] end @@ -83,7 +83,7 @@ RSpec.shared_context 'ProjectPolicy context' do let(:base_owner_permissions) do %i[ archive_project change_namespace change_visibility_level destroy_issue - destroy_merge_request manage_owners remove_fork_project remove_project rename_project + destroy_merge_request manage_owners remove_fork_project remove_project set_issue_created_at set_issue_iid set_issue_updated_at set_note_created_at ] diff --git a/spec/support/shared_contexts/policies/project_policy_table_shared_context.rb b/spec/support/shared_contexts/policies/project_policy_table_shared_context.rb index b18ce14eba6..d9ea7bc7f82 100644 --- a/spec/support/shared_contexts/policies/project_policy_table_shared_context.rb +++ b/spec/support/shared_contexts/policies/project_policy_table_shared_context.rb @@ -126,6 +126,63 @@ RSpec.shared_context 'ProjectPolicyTable context' do end # This table is based on permission_table_for_guest_feature_access, + # but takes into account note confidentiality. It is required on the context + # to have one regular note and one confidential note. + # + # project_level, :feature_access_level, :membership, :admin_mode, :expected_count + def permission_table_for_notes_feature_access + :public | :enabled | :admin | true | 2 + :public | :enabled | :admin | false | 1 + :public | :enabled | :reporter | nil | 2 + :public | :enabled | :guest | nil | 1 + :public | :enabled | :non_member | nil | 1 + :public | :enabled | :anonymous | nil | 1 + + :public | :private | :admin | true | 2 + :public | :private | :admin | false | 0 + :public | :private | :reporter | nil | 2 + :public | :private | :guest | nil | 1 + :public | :private | :non_member | nil | 0 + :public | :private | :anonymous | nil | 0 + + :public | :disabled | :reporter | nil | 0 + :public | :disabled | :guest | nil | 0 + :public | :disabled | :non_member | nil | 0 + :public | :disabled | :anonymous | nil | 0 + + :internal | :enabled | :admin | true | 2 + :internal | :enabled | :admin | false | 1 + :internal | :enabled | :reporter | nil | 2 + :internal | :enabled | :guest | nil | 1 + :internal | :enabled | :non_member | nil | 1 + :internal | :enabled | :anonymous | nil | 0 + + :internal | :private | :admin | true | 2 + :internal | :private | :admin | false | 0 + :internal | :private | :reporter | nil | 2 + :internal | :private | :guest | nil | 1 + :internal | :private | :non_member | nil | 0 + :internal | :private | :anonymous | nil | 0 + + :internal | :disabled | :reporter | nil | 0 + :internal | :disabled | :guest | nil | 0 + :internal | :disabled | :non_member | nil | 0 + :internal | :disabled | :anonymous | nil | 0 + + :private | :private | :admin | true | 2 + :private | :private | :admin | false | 0 + :private | :private | :reporter | nil | 2 + :private | :private | :guest | nil | 1 + :private | :private | :non_member | nil | 0 + :private | :private | :anonymous | nil | 0 + + :private | :disabled | :reporter | nil | 0 + :private | :disabled | :guest | nil | 0 + :private | :disabled | :non_member | nil | 0 + :private | :disabled | :anonymous | nil | 0 + end + + # This table is based on permission_table_for_guest_feature_access, # but with a slight twist. # Some features can be hidden away to GUEST, when project is private. # (see ProjectFeature::PRIVATE_FEATURES_MIN_ACCESS_LEVEL_FOR_PRIVATE_PROJECT) |