diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-08-20 21:42:06 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-08-20 21:42:06 +0300 |
commit | 6e4e1050d9dba2b7b2523fdd1768823ab85feef4 (patch) | |
tree | 78be5963ec075d80116a932011d695dd33910b4e /spec/support/shared_contexts | |
parent | 1ce776de4ae122aba3f349c02c17cebeaa8ecf07 (diff) |
Add latest changes from gitlab-org/gitlab@13-3-stable-ee
Diffstat (limited to 'spec/support/shared_contexts')
10 files changed, 124 insertions, 3 deletions
diff --git a/spec/support/shared_contexts/change_access_checks_shared_context.rb b/spec/support/shared_contexts/change_access_checks_shared_context.rb index e1ab81b4e3d..4c55990c901 100644 --- a/spec/support/shared_contexts/change_access_checks_shared_context.rb +++ b/spec/support/shared_contexts/change_access_checks_shared_context.rb @@ -3,7 +3,7 @@ RSpec.shared_context 'change access checks context' do let(:user) { create(:user) } let(:project) { create(:project, :repository) } - let(:user_access) { Gitlab::UserAccess.new(user, project: project) } + let(:user_access) { Gitlab::UserAccess.new(user, container: project) } let(:oldrev) { 'be93687618e4b132087f430a4d8fc3a609c9b77c' } let(:newrev) { '54fcc214b94e78d7a41a9a8fe6d87a5e59500e51' } let(:ref) { 'refs/heads/master' } diff --git a/spec/support/shared_contexts/csv_response_shared_context.rb b/spec/support/shared_contexts/csv_response_shared_context.rb new file mode 100644 index 00000000000..af79e393a91 --- /dev/null +++ b/spec/support/shared_contexts/csv_response_shared_context.rb @@ -0,0 +1,5 @@ +# frozen_string_literal: true + +RSpec.shared_context 'CSV response' do + let(:csv_response) { CSV.parse(response.body) } +end diff --git a/spec/support/shared_contexts/finders/merge_requests_finder_shared_contexts.rb b/spec/support/shared_contexts/finders/merge_requests_finder_shared_contexts.rb index 07b6b98222f..010c445d8df 100644 --- a/spec/support/shared_contexts/finders/merge_requests_finder_shared_contexts.rb +++ b/spec/support/shared_contexts/finders/merge_requests_finder_shared_contexts.rb @@ -28,6 +28,7 @@ RSpec.shared_context 'MergeRequestsFinder multiple projects with merge requests fork_project(project1, user) end end + let!(:project3) do allow_gitaly_n_plus_1 do fork_project(project1, user).tap do |project| @@ -35,6 +36,7 @@ RSpec.shared_context 'MergeRequestsFinder multiple projects with merge requests end end end + let_it_be(:project4, reload: true) do allow_gitaly_n_plus_1 { create(:project, :repository, group: subgroup) } end @@ -53,22 +55,26 @@ RSpec.shared_context 'MergeRequestsFinder multiple projects with merge requests source_project: project2, target_project: project1, target_branch: 'merged-target') end + let!(:merge_request2) do create(:merge_request, :conflict, assignees: [user], author: user, source_project: project2, target_project: project1, state: 'closed') end + let!(:merge_request3) do create(:merge_request, :simple, author: user, assignees: [user2], source_project: project2, target_project: project2, state: 'locked', title: 'thing WIP thing') end + let!(:merge_request4) do create(:merge_request, :simple, author: user, source_project: project3, target_project: project3, title: 'WIP thing') end + let_it_be(:merge_request5) do create(:merge_request, :simple, author: user, source_project: project4, target_project: project4, diff --git a/spec/support/shared_contexts/lib/gitlab/git_access_shared_examples.rb b/spec/support/shared_contexts/lib/gitlab/git_access_shared_examples.rb new file mode 100644 index 00000000000..837c1c37aa3 --- /dev/null +++ b/spec/support/shared_contexts/lib/gitlab/git_access_shared_examples.rb @@ -0,0 +1,17 @@ +# frozen_string_literal: true + +RSpec.shared_examples 'forbidden git access' do + let(:message) { /You can't/ } + + it 'prevents access' do + expect { subject }.to raise_error(Gitlab::GitAccess::ForbiddenError, message) + end +end + +RSpec.shared_examples 'not-found git access' do + let(:message) { /not found/ } + + it 'prevents access' do + expect { subject }.to raise_error(Gitlab::GitAccess::NotFoundError, message) + end +end diff --git a/spec/support/shared_contexts/navbar_structure_context.rb b/spec/support/shared_contexts/navbar_structure_context.rb index d9a72f2b54a..e276a54224b 100644 --- a/spec/support/shared_contexts/navbar_structure_context.rb +++ b/spec/support/shared_contexts/navbar_structure_context.rb @@ -7,6 +7,7 @@ RSpec.shared_context 'project navbar structure' do nav_sub_items: [ _('CI / CD'), (_('Code Review') if Gitlab.ee?), + (_('Merge Request') if Gitlab.ee?), _('Repository'), _('Value Stream') ] @@ -64,8 +65,10 @@ RSpec.shared_context 'project navbar structure' do nav_sub_items: [ _('Metrics'), _('Alerts'), + _('Incidents'), _('Environments'), _('Error Tracking'), + _('Product Analytics'), _('Serverless'), _('Logs'), _('Kubernetes') 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 4b0c7afab6d..af46e5474b0 100644 --- a/spec/support/shared_contexts/policies/group_policy_shared_context.rb +++ b/spec/support/shared_contexts/policies/group_policy_shared_context.rb @@ -17,6 +17,7 @@ RSpec.shared_context 'GroupPolicy context' do read_group_merge_requests ] end + let(:read_group_permissions) { %i[read_label read_list read_milestone read_board] } let(:reporter_permissions) { %i[admin_label read_container_image read_metrics_dashboard_annotation read_prometheus] } let(:developer_permissions) { %i[admin_milestone create_metrics_dashboard_annotation delete_metrics_dashboard_annotation update_metrics_dashboard_annotation] } @@ -26,6 +27,7 @@ RSpec.shared_context 'GroupPolicy context' do read_cluster create_cluster update_cluster admin_cluster add_cluster ] end + let(:owner_permissions) do [ :admin_group, @@ -38,6 +40,7 @@ RSpec.shared_context 'GroupPolicy context' do :update_default_branch_protection ].compact end + let(:admin_permissions) { %i[read_confidential_issues] } before_all do diff --git a/spec/support/shared_contexts/prometheus/alert_shared_context.rb b/spec/support/shared_contexts/prometheus/alert_shared_context.rb index 330d2c4515f..932ab899270 100644 --- a/spec/support/shared_contexts/prometheus/alert_shared_context.rb +++ b/spec/support/shared_contexts/prometheus/alert_shared_context.rb @@ -15,7 +15,7 @@ RSpec.shared_context 'self-managed prometheus alert attributes' do { panel_groups: [{ panels: [{ - type: 'line-graph', + type: 'area-chart', title: title, y_label: y_label, metrics: [{ query_range: query }] diff --git a/spec/support/shared_contexts/read_ci_configuration_shared_context.rb b/spec/support/shared_contexts/read_ci_configuration_shared_context.rb new file mode 100644 index 00000000000..f8f33e2a745 --- /dev/null +++ b/spec/support/shared_contexts/read_ci_configuration_shared_context.rb @@ -0,0 +1,9 @@ +# frozen_string_literal: true + +RSpec.shared_context 'read ci configuration for sast enabled project' do + let_it_be(:gitlab_ci_yml_content) do + File.read(Rails.root.join('spec/support/gitlab_stubs/gitlab_ci_for_sast.yml')) + end + + let_it_be(:project) { create(:project, :repository) } +end diff --git a/spec/support/shared_contexts/requests/api/graphql/jira_import/jira_projects_context.rb b/spec/support/shared_contexts/requests/api/graphql/jira_import/jira_projects_context.rb index 7f150bed43d..edc5b313220 100644 --- a/spec/support/shared_contexts/requests/api/graphql/jira_import/jira_projects_context.rb +++ b/spec/support/shared_contexts/requests/api/graphql/jira_import/jira_projects_context.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -RSpec.shared_context 'jira projects request context' do +RSpec.shared_context 'Jira projects request context' do let(:url) { 'https://jira.example.com' } let(:username) { 'jira-username' } let(:password) { 'jira-password' } diff --git a/spec/support/shared_contexts/services/projects/container_repository/delete_tags_service_shared_context.rb b/spec/support/shared_contexts/services/projects/container_repository/delete_tags_service_shared_context.rb new file mode 100644 index 00000000000..bcc98cf6416 --- /dev/null +++ b/spec/support/shared_contexts/services/projects/container_repository/delete_tags_service_shared_context.rb @@ -0,0 +1,78 @@ +# frozen_string_literal: true + +RSpec.shared_context 'container repository delete tags service shared context' do + let_it_be(:user) { create(:user) } + let_it_be(:project, reload: true) { create(:project, :private) } + let_it_be(:repository) { create(:container_repository, :root, project: project) } + + let(:params) { { tags: tags } } + + before do + stub_container_registry_config(enabled: true, + api_url: 'http://registry.gitlab', + host_port: 'registry.gitlab') + + stub_container_registry_tags( + repository: repository.path, + tags: %w(latest A Ba Bb C D E)) + end + + def stub_delete_reference_request(tag, status = 200) + stub_request(:delete, "http://registry.gitlab/v2/#{repository.path}/tags/reference/#{tag}") + .to_return(status: status, body: '') + end + + def stub_delete_reference_requests(tags) + tags = Hash[Array.wrap(tags).map { |tag| [tag, 200] }] unless tags.is_a?(Hash) + + tags.each do |tag, status| + stub_request(:delete, "http://registry.gitlab/v2/#{repository.path}/tags/reference/#{tag}") + .to_return(status: status, body: '') + end + end + + def stub_put_manifest_request(tag, status = 200, headers = { 'docker-content-digest' => 'sha256:dummy' }) + stub_request(:put, "http://registry.gitlab/v2/#{repository.path}/manifests/#{tag}") + .to_return(status: status, body: '', headers: headers) + end + + def stub_tag_digest(tag, digest) + stub_request(:head, "http://registry.gitlab/v2/#{repository.path}/manifests/#{tag}") + .to_return(status: 200, body: '', headers: { 'docker-content-digest' => digest }) + end + + def stub_digest_config(digest, created_at) + allow_any_instance_of(ContainerRegistry::Client) + .to receive(:blob) + .with(repository.path, digest, nil) do + { 'created' => created_at.to_datetime.rfc3339 }.to_json if created_at + end + end + + def stub_upload(digest, success: true) + content = "{\n \"config\": {\n }\n}" + expect_any_instance_of(ContainerRegistry::Client) + .to receive(:upload_blob) + .with(repository.path, content, digest) { double(success?: success ) } + end + + def expect_delete_tag_by_digest(digest) + expect_any_instance_of(ContainerRegistry::Client) + .to receive(:delete_repository_tag_by_digest) + .with(repository.path, digest) { true } + + expect_any_instance_of(ContainerRegistry::Client) + .not_to receive(:delete_repository_tag_by_name) + end + + def expect_delete_tag_by_names(names) + Array.wrap(names).each do |name| + expect_any_instance_of(ContainerRegistry::Client) + .to receive(:delete_repository_tag_by_name) + .with(repository.path, name) { true } + + expect_any_instance_of(ContainerRegistry::Client) + .not_to receive(:delete_repository_tag_by_digest) + end + end +end |