diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-03-02 21:08:01 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-03-02 21:08:01 +0000 |
commit | 561e1b470f0a99fe6304c8f197348c47a637d594 (patch) | |
tree | 6b361b6b0b412b70450aca167079c50a13bd88d8 /spec/requests | |
parent | 7b52c7cb634ef7047d30b0337fe477bcdcedf41d (diff) | |
download | gitlab-ce-561e1b470f0a99fe6304c8f197348c47a637d594.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/requests')
-rw-r--r-- | spec/requests/api/graphql/mutations/snippets/create_spec.rb | 4 | ||||
-rw-r--r-- | spec/requests/api/graphql/mutations/snippets/update_spec.rb | 4 | ||||
-rw-r--r-- | spec/requests/api/lsif_data_spec.rb | 75 | ||||
-rw-r--r-- | spec/requests/api/project_container_repositories_spec.rb | 55 | ||||
-rw-r--r-- | spec/requests/api/projects_spec.rb | 65 |
5 files changed, 159 insertions, 44 deletions
diff --git a/spec/requests/api/graphql/mutations/snippets/create_spec.rb b/spec/requests/api/graphql/mutations/snippets/create_spec.rb index cb19f50b5b5..cef7fc5cbe3 100644 --- a/spec/requests/api/graphql/mutations/snippets/create_spec.rb +++ b/spec/requests/api/graphql/mutations/snippets/create_spec.rb @@ -67,7 +67,7 @@ describe 'Creating a Snippet' do it 'returns the created Snippet' do post_graphql_mutation(mutation, current_user: current_user) - expect(mutation_response['snippet']['blob']['richData']).to match(content) + expect(mutation_response['snippet']['blob']['richData']).to be_nil expect(mutation_response['snippet']['blob']['plainData']).to match(content) expect(mutation_response['snippet']['title']).to eq(title) expect(mutation_response['snippet']['description']).to eq(description) @@ -93,7 +93,7 @@ describe 'Creating a Snippet' do it 'returns the created Snippet' do post_graphql_mutation(mutation, current_user: current_user) - expect(mutation_response['snippet']['blob']['richData']).to match(content) + expect(mutation_response['snippet']['blob']['richData']).to be_nil expect(mutation_response['snippet']['blob']['plainData']).to match(content) expect(mutation_response['snippet']['title']).to eq(title) expect(mutation_response['snippet']['description']).to eq(description) diff --git a/spec/requests/api/graphql/mutations/snippets/update_spec.rb b/spec/requests/api/graphql/mutations/snippets/update_spec.rb index e9481a36287..820c97e8341 100644 --- a/spec/requests/api/graphql/mutations/snippets/update_spec.rb +++ b/spec/requests/api/graphql/mutations/snippets/update_spec.rb @@ -56,7 +56,7 @@ describe 'Updating a Snippet' do it 'returns the updated Snippet' do post_graphql_mutation(mutation, current_user: current_user) - expect(mutation_response['snippet']['blob']['richData']).to match(updated_content) + expect(mutation_response['snippet']['blob']['richData']).to be_nil expect(mutation_response['snippet']['blob']['plainData']).to match(updated_content) expect(mutation_response['snippet']['title']).to eq(updated_title) expect(mutation_response['snippet']['description']).to eq(updated_description) @@ -78,7 +78,7 @@ describe 'Updating a Snippet' do it 'returns the Snippet with its original values' do post_graphql_mutation(mutation, current_user: current_user) - expect(mutation_response['snippet']['blob']['richData']).to match(original_content) + expect(mutation_response['snippet']['blob']['richData']).to be_nil expect(mutation_response['snippet']['blob']['plainData']).to match(original_content) expect(mutation_response['snippet']['title']).to eq(original_title) expect(mutation_response['snippet']['description']).to eq(original_description) diff --git a/spec/requests/api/lsif_data_spec.rb b/spec/requests/api/lsif_data_spec.rb index 214bc832cda..a1516046e3e 100644 --- a/spec/requests/api/lsif_data_spec.rb +++ b/spec/requests/api/lsif_data_spec.rb @@ -9,18 +9,20 @@ describe API::LsifData do let(:commit) { project.commit } describe 'GET lsif/info' do - let(:endpoint_path) { "/projects/#{project.id}/commits/#{commit.id}/lsif/info" } + subject do + endpoint_path = "/projects/#{project.id}/commits/#{commit.id}/lsif/info" + + get api(endpoint_path, user), params: { paths: ['main.go', 'morestrings/reverse.go'] } + + response + end context 'user does not have access to the project' do before do project.add_guest(user) end - it 'returns 403' do - get api(endpoint_path, user), params: { path: 'main.go' } - - expect(response).to have_gitlab_http_status(:forbidden) - end + it { is_expected.to have_gitlab_http_status(:forbidden) } end context 'user has access to the project' do @@ -28,35 +30,27 @@ describe API::LsifData do project.add_reporter(user) end - context 'code_navigation feature is disabled' do - before do - stub_feature_flags(code_navigation: false) - end - - it 'returns 404' do - get api(endpoint_path, user) - - expect(response).to have_gitlab_http_status(:not_found) - end - end - context 'there is no job artifact for the passed commit' do - it 'returns 404' do - get api(endpoint_path, user), params: { path: 'main.go' } - - expect(response).to have_gitlab_http_status(:not_found) - end + it { is_expected.to have_gitlab_http_status(:not_found) } end context 'lsif data is stored as a job artifact' do let!(:pipeline) { create(:ci_pipeline, project: project, sha: commit.id) } let!(:artifact) { create(:ci_job_artifact, :lsif, job: create(:ci_build, pipeline: pipeline)) } - it 'returns code navigation info for a given path' do - get api(endpoint_path, user), params: { path: 'main.go' } + context 'code_navigation feature is disabled' do + before do + stub_feature_flags(code_navigation: false) + end - expect(response).to have_gitlab_http_status(:ok) - expect(response.parsed_body.last).to eq({ + it { is_expected.to have_gitlab_http_status(:not_found) } + end + + it 'returns code navigation info for a given path', :aggregate_failures do + expect(subject).to have_gitlab_http_status(:ok) + + data_for_main = response.parsed_body['main.go'] + expect(data_for_main.last).to eq({ 'end_char' => 18, 'end_line' => 8, 'start_char' => 13, @@ -67,26 +61,33 @@ describe API::LsifData do 'value' => Gitlab::Highlight.highlight(nil, 'func Func2(i int) string', language: 'go') }] }) + + data_for_reverse = response.parsed_body['morestrings/reverse.go'] + expect(data_for_reverse.last).to eq({ + 'end_char' => 9, + 'end_line' => 7, + 'start_char' => 8, + 'start_line' => 7, + 'definition_url' => project_blob_path(project, "#{commit.id}/morestrings/reverse.go", anchor: 'L6'), + 'hover' => [{ + 'language' => 'go', + 'value' => Gitlab::Highlight.highlight(nil, 'var b string', language: 'go') + }] + }) end context 'the stored file is too large' do - it 'returns 413' do + before do allow_any_instance_of(JobArtifactUploader).to receive(:cached_size).and_return(20.megabytes) - - get api(endpoint_path, user), params: { path: 'main.go' } - - expect(response).to have_gitlab_http_status(:payload_too_large) end + + it { is_expected.to have_gitlab_http_status(:payload_too_large) } end context 'the user does not have access to the pipeline' do let(:project) { create(:project, :repository, builds_access_level: ProjectFeature::DISABLED) } - it 'returns 403' do - get api(endpoint_path, user), params: { path: 'main.go' } - - expect(response).to have_gitlab_http_status(:forbidden) - end + it { is_expected.to have_gitlab_http_status(:forbidden) } end end end diff --git a/spec/requests/api/project_container_repositories_spec.rb b/spec/requests/api/project_container_repositories_spec.rb index 1854d4db920..91905635c3f 100644 --- a/spec/requests/api/project_container_repositories_spec.rb +++ b/spec/requests/api/project_container_repositories_spec.rb @@ -109,7 +109,7 @@ describe API::ProjectContainerRepositories do context 'disallowed' do let(:params) do - { name_regex: 'v10.*' } + { name_regex_delete: 'v10.*' } end it_behaves_like 'rejected container repository access', :developer, :forbidden @@ -130,16 +130,33 @@ describe API::ProjectContainerRepositories do end end + context 'without name_regex' do + let(:params) do + { keep_n: 100, + older_than: '1 day', + other: 'some value' } + end + + it 'returns bad request' do + subject + + expect(response).to have_gitlab_http_status(:bad_request) + end + end + context 'passes all declared parameters' do let(:params) do - { name_regex: 'v10.*', + { name_regex_delete: 'v10.*', + name_regex_keep: 'v10.1.*', keep_n: 100, older_than: '1 day', other: 'some value' } end let(:worker_params) do - { name_regex: 'v10.*', + { name_regex: nil, + name_regex_delete: 'v10.*', + name_regex_keep: 'v10.1.*', keep_n: 100, older_than: '1 day', container_expiration_policy: false } @@ -174,6 +191,38 @@ describe API::ProjectContainerRepositories do end end end + + context 'with deprecated name_regex param' do + let(:params) do + { name_regex: 'v10.*', + name_regex_keep: 'v10.1.*', + keep_n: 100, + older_than: '1 day', + other: 'some value' } + end + + let(:worker_params) do + { name_regex: 'v10.*', + name_regex_delete: nil, + name_regex_keep: 'v10.1.*', + keep_n: 100, + older_than: '1 day', + container_expiration_policy: false } + end + + let(:lease_key) { "container_repository:cleanup_tags:#{root_repository.id}" } + + it 'schedules cleanup of tags repository' do + stub_last_activity_update + stub_exclusive_lease(lease_key, timeout: 1.hour) + expect(CleanupContainerRepositoryWorker).to receive(:perform_async) + .with(maintainer.id, root_repository.id, worker_params) + + subject + + expect(response).to have_gitlab_http_status(:accepted) + end + end end end diff --git a/spec/requests/api/projects_spec.rb b/spec/requests/api/projects_spec.rb index 2f1760a570e..59c394d8d8d 100644 --- a/spec/requests/api/projects_spec.rb +++ b/spec/requests/api/projects_spec.rb @@ -1751,6 +1751,27 @@ describe API::Projects do subject { get api("/projects/#{project.id}", user) } end + + describe 'repository_storage attribute' do + before do + get api("/projects/#{project.id}", user) + end + + context 'when authenticated as an admin' do + let(:user) { create(:admin) } + + it 'returns repository_storage attribute' do + expect(response).to have_gitlab_http_status(:ok) + expect(json_response['repository_storage']).to eq(project.repository_storage) + end + end + + context 'when authenticated as a regular user' do + it 'does not return repository_storage attribute' do + expect(json_response).not_to have_key('repository_storage') + end + end + end end describe 'GET /projects/:id/users' do @@ -2402,6 +2423,50 @@ describe API::Projects do expect(response).to have_gitlab_http_status(:forbidden) end end + + context 'when updating repository storage' do + let(:unknown_storage) { 'new-storage' } + let(:new_project) { create(:project, :repository, namespace: user.namespace) } + + context 'as a user' do + it 'returns 200 but does not change repository_storage' do + expect do + Sidekiq::Testing.fake! do + put(api("/projects/#{new_project.id}", user), params: { repository_storage: unknown_storage, issues_enabled: false }) + end + end.not_to change(ProjectUpdateRepositoryStorageWorker.jobs, :size) + + expect(response).to have_gitlab_http_status(:ok) + expect(json_response['issues_enabled']).to eq(false) + expect(new_project.reload.repository.storage).to eq('default') + end + end + + context 'as an admin' do + include_context 'custom session' + + let(:admin) { create(:admin) } + + it 'returns 500 when repository storage is unknown' do + put(api("/projects/#{new_project.id}", admin), params: { repository_storage: unknown_storage }) + + expect(response).to have_gitlab_http_status(:internal_server_error) + expect(json_response['message']).to match('ArgumentError') + end + + it 'returns 200 when repository storage has changed' do + stub_storage_settings('test_second_storage' => { 'path' => 'tmp/tests/second_storage' }) + + expect do + Sidekiq::Testing.fake! do + put(api("/projects/#{new_project.id}", admin), params: { repository_storage: 'test_second_storage' }) + end + end.to change(ProjectUpdateRepositoryStorageWorker.jobs, :size).by(1) + + expect(response).to have_gitlab_http_status(:ok) + end + end + end end describe 'POST /projects/:id/archive' do |