diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-10-05 15:08:47 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-10-05 15:08:47 +0300 |
commit | 5460c19548d3d3d2ff764ceff05c2b72aa2d3a32 (patch) | |
tree | 3a7fff116a7f6ff9c033e7f5e87a4341de801784 /spec/requests | |
parent | 2fe341d705700b3e99f82076b09b95885878ac0d (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/requests')
-rw-r--r-- | spec/requests/api/graphql/project/merge_requests_spec.rb | 22 | ||||
-rw-r--r-- | spec/requests/api/lint_spec.rb | 111 | ||||
-rw-r--r-- | spec/requests/api/pypi_packages_spec.rb | 146 |
3 files changed, 206 insertions, 73 deletions
diff --git a/spec/requests/api/graphql/project/merge_requests_spec.rb b/spec/requests/api/graphql/project/merge_requests_spec.rb index dfce1e12dd5..40e5e1d5a84 100644 --- a/spec/requests/api/graphql/project/merge_requests_spec.rb +++ b/spec/requests/api/graphql/project/merge_requests_spec.rb @@ -173,6 +173,28 @@ RSpec.describe 'getting merge request listings nested in a project' do it_behaves_like 'searching with parameters' end + context 'when requesting `approved_by`' do + let(:search_params) { { iids: [merge_request_a.iid.to_s, merge_request_b.iid.to_s] } } + let(:extra_iid_for_second_query) { merge_request_c.iid.to_s } + let(:requested_fields) { query_graphql_field(:approved_by, nil, query_graphql_field(:nodes, nil, [:username])) } + + def execute_query + query = query_merge_requests(requested_fields) + post_graphql(query, current_user: current_user) + end + + it 'exposes approver username' do + merge_request_a.approved_by_users << current_user + + execute_query + + user_data = { 'username' => current_user.username } + expect(results).to include(a_hash_including('approvedBy' => { 'nodes' => array_including(user_data) })) + end + + include_examples 'N+1 query check' + end + describe 'fields' do let(:requested_fields) { nil } let(:extra_iid_for_second_query) { merge_request_c.iid.to_s } diff --git a/spec/requests/api/lint_spec.rb b/spec/requests/api/lint_spec.rb index 6b5a4b6436a..3892df273bd 100644 --- a/spec/requests/api/lint_spec.rb +++ b/spec/requests/api/lint_spec.rb @@ -75,4 +75,115 @@ RSpec.describe API::Lint do end end end + + describe 'GET /projects/:id/ci/lint' do + subject(:ci_lint) { get api("/projects/#{project.id}/ci/lint", api_user), params: { dry_run: dry_run } } + + let_it_be(:api_user) { create(:user) } + let(:project) { create(:project, :repository) } + let(:dry_run) { nil } + + RSpec.shared_examples 'valid config' do + it 'passes validation' do + ci_lint + + included_config = YAML.safe_load(included_content, [Symbol]) + root_config = YAML.safe_load(yaml_content, [Symbol]) + expected_yaml = included_config.merge(root_config).except(:include).to_yaml + + expect(response).to have_gitlab_http_status(:ok) + expect(json_response).to be_an Hash + expect(json_response['merged_yaml']).to eq(expected_yaml) + expect(json_response['valid']).to eq(true) + expect(json_response['errors']).to eq([]) + end + end + + RSpec.shared_examples 'invalid config' do + it 'responds with errors about invalid configuration' do + ci_lint + + expect(response).to have_gitlab_http_status(:ok) + expect(json_response['merged_yaml']).to eq(yaml_content) + expect(json_response['valid']).to eq(false) + expect(json_response['errors']).to eq(['jobs config should contain at least one visible job']) + end + end + + context 'when unauthenticated' do + it 'returns authentication error' do + ci_lint + + expect(response).to have_gitlab_http_status(:not_found) + end + end + + context 'when authenticated as project member' do + before do + project.add_developer(api_user) + end + + context 'with valid .gitlab-ci.yml content' do + let(:yaml_content) do + { include: { local: 'another-gitlab-ci.yml' }, test: { stage: 'test', script: 'echo 1' } }.to_yaml + end + + let(:included_content) do + { another_test: { stage: 'test', script: 'echo 1' } }.to_yaml + end + + before do + project.repository.create_file( + project.creator, + '.gitlab-ci.yml', + yaml_content, + message: 'Automatically created .gitlab-ci.yml', + branch_name: 'master' + ) + + project.repository.create_file( + project.creator, + 'another-gitlab-ci.yml', + included_content, + message: 'Automatically created another-gitlab-ci.yml', + branch_name: 'master' + ) + end + + context 'when running as dry run' do + let(:dry_run) { true } + + it_behaves_like 'valid config' + end + + context 'when running static validation' do + let(:dry_run) { false } + + it_behaves_like 'valid config' + end + end + + context 'with invalid .gitlab-ci.yml content' do + let(:yaml_content) do + { image: 'ruby:2.7', services: ['postgres'] }.to_yaml + end + + before do + stub_ci_pipeline_yaml_file(yaml_content) + end + + context 'when running as dry run' do + let(:dry_run) { true } + + it_behaves_like 'invalid config' + end + + context 'when running static validation' do + let(:dry_run) { false } + + it_behaves_like 'invalid config' + end + end + end + end end diff --git a/spec/requests/api/pypi_packages_spec.rb b/spec/requests/api/pypi_packages_spec.rb index e72ac002f6b..de5dea449f8 100644 --- a/spec/requests/api/pypi_packages_spec.rb +++ b/spec/requests/api/pypi_packages_spec.rb @@ -23,24 +23,24 @@ RSpec.describe API::PypiPackages do using RSpec::Parameterized::TableSyntax where(:project_visibility_level, :user_role, :member, :user_token, :shared_examples_name, :expected_status) do - 'PUBLIC' | :developer | true | true | 'PyPi package versions' | :success - 'PUBLIC' | :guest | true | true | 'PyPi package versions' | :success - 'PUBLIC' | :developer | true | false | 'PyPi package versions' | :success - 'PUBLIC' | :guest | true | false | 'PyPi package versions' | :success - 'PUBLIC' | :developer | false | true | 'PyPi package versions' | :success - 'PUBLIC' | :guest | false | true | 'PyPi package versions' | :success - 'PUBLIC' | :developer | false | false | 'PyPi package versions' | :success - 'PUBLIC' | :guest | false | false | 'PyPi package versions' | :success - 'PUBLIC' | :anonymous | false | true | 'PyPi package versions' | :success - 'PRIVATE' | :developer | true | true | 'PyPi package versions' | :success - 'PRIVATE' | :guest | true | true | 'process PyPi api request' | :forbidden - 'PRIVATE' | :developer | true | false | 'process PyPi api request' | :unauthorized - 'PRIVATE' | :guest | true | false | 'process PyPi api request' | :unauthorized - 'PRIVATE' | :developer | false | true | 'process PyPi api request' | :not_found - 'PRIVATE' | :guest | false | true | 'process PyPi api request' | :not_found - 'PRIVATE' | :developer | false | false | 'process PyPi api request' | :unauthorized - 'PRIVATE' | :guest | false | false | 'process PyPi api request' | :unauthorized - 'PRIVATE' | :anonymous | false | true | 'process PyPi api request' | :unauthorized + 'PUBLIC' | :developer | true | true | 'PyPI package versions' | :success + 'PUBLIC' | :guest | true | true | 'PyPI package versions' | :success + 'PUBLIC' | :developer | true | false | 'PyPI package versions' | :success + 'PUBLIC' | :guest | true | false | 'PyPI package versions' | :success + 'PUBLIC' | :developer | false | true | 'PyPI package versions' | :success + 'PUBLIC' | :guest | false | true | 'PyPI package versions' | :success + 'PUBLIC' | :developer | false | false | 'PyPI package versions' | :success + 'PUBLIC' | :guest | false | false | 'PyPI package versions' | :success + 'PUBLIC' | :anonymous | false | true | 'PyPI package versions' | :success + 'PRIVATE' | :developer | true | true | 'PyPI package versions' | :success + 'PRIVATE' | :guest | true | true | 'process PyPI api request' | :forbidden + 'PRIVATE' | :developer | true | false | 'process PyPI api request' | :unauthorized + 'PRIVATE' | :guest | true | false | 'process PyPI api request' | :unauthorized + 'PRIVATE' | :developer | false | true | 'process PyPI api request' | :not_found + 'PRIVATE' | :guest | false | true | 'process PyPI api request' | :not_found + 'PRIVATE' | :developer | false | false | 'process PyPI api request' | :unauthorized + 'PRIVATE' | :guest | false | false | 'process PyPI api request' | :unauthorized + 'PRIVATE' | :anonymous | false | true | 'process PyPI api request' | :unauthorized end with_them do @@ -76,24 +76,24 @@ RSpec.describe API::PypiPackages do using RSpec::Parameterized::TableSyntax where(:project_visibility_level, :user_role, :member, :user_token, :shared_examples_name, :expected_status) do - 'PUBLIC' | :developer | true | true | 'process PyPi api request' | :success - 'PUBLIC' | :guest | true | true | 'process PyPi api request' | :forbidden - 'PUBLIC' | :developer | true | false | 'process PyPi api request' | :unauthorized - 'PUBLIC' | :guest | true | false | 'process PyPi api request' | :unauthorized - 'PUBLIC' | :developer | false | true | 'process PyPi api request' | :forbidden - 'PUBLIC' | :guest | false | true | 'process PyPi api request' | :forbidden - 'PUBLIC' | :developer | false | false | 'process PyPi api request' | :unauthorized - 'PUBLIC' | :guest | false | false | 'process PyPi api request' | :unauthorized - 'PUBLIC' | :anonymous | false | true | 'process PyPi api request' | :unauthorized - 'PRIVATE' | :developer | true | true | 'process PyPi api request' | :success - 'PRIVATE' | :guest | true | true | 'process PyPi api request' | :forbidden - 'PRIVATE' | :developer | true | false | 'process PyPi api request' | :unauthorized - 'PRIVATE' | :guest | true | false | 'process PyPi api request' | :unauthorized - 'PRIVATE' | :developer | false | true | 'process PyPi api request' | :not_found - 'PRIVATE' | :guest | false | true | 'process PyPi api request' | :not_found - 'PRIVATE' | :developer | false | false | 'process PyPi api request' | :unauthorized - 'PRIVATE' | :guest | false | false | 'process PyPi api request' | :unauthorized - 'PRIVATE' | :anonymous | false | true | 'process PyPi api request' | :unauthorized + 'PUBLIC' | :developer | true | true | 'process PyPI api request' | :success + 'PUBLIC' | :guest | true | true | 'process PyPI api request' | :forbidden + 'PUBLIC' | :developer | true | false | 'process PyPI api request' | :unauthorized + 'PUBLIC' | :guest | true | false | 'process PyPI api request' | :unauthorized + 'PUBLIC' | :developer | false | true | 'process PyPI api request' | :forbidden + 'PUBLIC' | :guest | false | true | 'process PyPI api request' | :forbidden + 'PUBLIC' | :developer | false | false | 'process PyPI api request' | :unauthorized + 'PUBLIC' | :guest | false | false | 'process PyPI api request' | :unauthorized + 'PUBLIC' | :anonymous | false | true | 'process PyPI api request' | :unauthorized + 'PRIVATE' | :developer | true | true | 'process PyPI api request' | :success + 'PRIVATE' | :guest | true | true | 'process PyPI api request' | :forbidden + 'PRIVATE' | :developer | true | false | 'process PyPI api request' | :unauthorized + 'PRIVATE' | :guest | true | false | 'process PyPI api request' | :unauthorized + 'PRIVATE' | :developer | false | true | 'process PyPI api request' | :not_found + 'PRIVATE' | :guest | false | true | 'process PyPI api request' | :not_found + 'PRIVATE' | :developer | false | false | 'process PyPI api request' | :unauthorized + 'PRIVATE' | :guest | false | false | 'process PyPI api request' | :unauthorized + 'PRIVATE' | :anonymous | false | true | 'process PyPI api request' | :unauthorized end with_them do @@ -142,24 +142,24 @@ RSpec.describe API::PypiPackages do using RSpec::Parameterized::TableSyntax where(:project_visibility_level, :user_role, :member, :user_token, :shared_examples_name, :expected_status) do - 'PUBLIC' | :developer | true | true | 'PyPi package creation' | :created - 'PUBLIC' | :guest | true | true | 'process PyPi api request' | :forbidden - 'PUBLIC' | :developer | true | false | 'process PyPi api request' | :unauthorized - 'PUBLIC' | :guest | true | false | 'process PyPi api request' | :unauthorized - 'PUBLIC' | :developer | false | true | 'process PyPi api request' | :forbidden - 'PUBLIC' | :guest | false | true | 'process PyPi api request' | :forbidden - 'PUBLIC' | :developer | false | false | 'process PyPi api request' | :unauthorized - 'PUBLIC' | :guest | false | false | 'process PyPi api request' | :unauthorized - 'PUBLIC' | :anonymous | false | true | 'process PyPi api request' | :unauthorized - 'PRIVATE' | :developer | true | true | 'process PyPi api request' | :created - 'PRIVATE' | :guest | true | true | 'process PyPi api request' | :forbidden - 'PRIVATE' | :developer | true | false | 'process PyPi api request' | :unauthorized - 'PRIVATE' | :guest | true | false | 'process PyPi api request' | :unauthorized - 'PRIVATE' | :developer | false | true | 'process PyPi api request' | :not_found - 'PRIVATE' | :guest | false | true | 'process PyPi api request' | :not_found - 'PRIVATE' | :developer | false | false | 'process PyPi api request' | :unauthorized - 'PRIVATE' | :guest | false | false | 'process PyPi api request' | :unauthorized - 'PRIVATE' | :anonymous | false | true | 'process PyPi api request' | :unauthorized + 'PUBLIC' | :developer | true | true | 'PyPI package creation' | :created + 'PUBLIC' | :guest | true | true | 'process PyPI api request' | :forbidden + 'PUBLIC' | :developer | true | false | 'process PyPI api request' | :unauthorized + 'PUBLIC' | :guest | true | false | 'process PyPI api request' | :unauthorized + 'PUBLIC' | :developer | false | true | 'process PyPI api request' | :forbidden + 'PUBLIC' | :guest | false | true | 'process PyPI api request' | :forbidden + 'PUBLIC' | :developer | false | false | 'process PyPI api request' | :unauthorized + 'PUBLIC' | :guest | false | false | 'process PyPI api request' | :unauthorized + 'PUBLIC' | :anonymous | false | true | 'process PyPI api request' | :unauthorized + 'PRIVATE' | :developer | true | true | 'process PyPI api request' | :created + 'PRIVATE' | :guest | true | true | 'process PyPI api request' | :forbidden + 'PRIVATE' | :developer | true | false | 'process PyPI api request' | :unauthorized + 'PRIVATE' | :guest | true | false | 'process PyPI api request' | :unauthorized + 'PRIVATE' | :developer | false | true | 'process PyPI api request' | :not_found + 'PRIVATE' | :guest | false | true | 'process PyPI api request' | :not_found + 'PRIVATE' | :developer | false | false | 'process PyPI api request' | :unauthorized + 'PRIVATE' | :guest | false | false | 'process PyPI api request' | :unauthorized + 'PRIVATE' | :anonymous | false | true | 'process PyPI api request' | :unauthorized end with_them do @@ -185,7 +185,7 @@ RSpec.describe API::PypiPackages do project.update!(visibility_level: Gitlab::VisibilityLevel::PRIVATE) end - it_behaves_like 'process PyPi api request', :developer, :bad_request, true + it_behaves_like 'process PyPI api request', :developer, :bad_request, true end context 'with an invalid package' do @@ -232,24 +232,24 @@ RSpec.describe API::PypiPackages do using RSpec::Parameterized::TableSyntax where(:project_visibility_level, :user_role, :member, :user_token, :shared_examples_name, :expected_status) do - 'PUBLIC' | :developer | true | true | 'PyPi package download' | :success - 'PUBLIC' | :guest | true | true | 'PyPi package download' | :success - 'PUBLIC' | :developer | true | false | 'PyPi package download' | :success - 'PUBLIC' | :guest | true | false | 'PyPi package download' | :success - 'PUBLIC' | :developer | false | true | 'PyPi package download' | :success - 'PUBLIC' | :guest | false | true | 'PyPi package download' | :success - 'PUBLIC' | :developer | false | false | 'PyPi package download' | :success - 'PUBLIC' | :guest | false | false | 'PyPi package download' | :success - 'PUBLIC' | :anonymous | false | true | 'PyPi package download' | :success - 'PRIVATE' | :developer | true | true | 'PyPi package download' | :success - 'PRIVATE' | :guest | true | true | 'PyPi package download' | :success - 'PRIVATE' | :developer | true | false | 'PyPi package download' | :success - 'PRIVATE' | :guest | true | false | 'PyPi package download' | :success - 'PRIVATE' | :developer | false | true | 'PyPi package download' | :success - 'PRIVATE' | :guest | false | true | 'PyPi package download' | :success - 'PRIVATE' | :developer | false | false | 'PyPi package download' | :success - 'PRIVATE' | :guest | false | false | 'PyPi package download' | :success - 'PRIVATE' | :anonymous | false | true | 'PyPi package download' | :success + 'PUBLIC' | :developer | true | true | 'PyPI package download' | :success + 'PUBLIC' | :guest | true | true | 'PyPI package download' | :success + 'PUBLIC' | :developer | true | false | 'PyPI package download' | :success + 'PUBLIC' | :guest | true | false | 'PyPI package download' | :success + 'PUBLIC' | :developer | false | true | 'PyPI package download' | :success + 'PUBLIC' | :guest | false | true | 'PyPI package download' | :success + 'PUBLIC' | :developer | false | false | 'PyPI package download' | :success + 'PUBLIC' | :guest | false | false | 'PyPI package download' | :success + 'PUBLIC' | :anonymous | false | true | 'PyPI package download' | :success + 'PRIVATE' | :developer | true | true | 'PyPI package download' | :success + 'PRIVATE' | :guest | true | true | 'PyPI package download' | :success + 'PRIVATE' | :developer | true | false | 'PyPI package download' | :success + 'PRIVATE' | :guest | true | false | 'PyPI package download' | :success + 'PRIVATE' | :developer | false | true | 'PyPI package download' | :success + 'PRIVATE' | :guest | false | true | 'PyPI package download' | :success + 'PRIVATE' | :developer | false | false | 'PyPI package download' | :success + 'PRIVATE' | :guest | false | false | 'PyPI package download' | :success + 'PRIVATE' | :anonymous | false | true | 'PyPI package download' | :success end with_them do |