diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-02-10 18:08:54 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-02-10 18:08:54 +0300 |
commit | 11e5d1b9ca3efa7be34ddebb708a6aedb4e91639 (patch) | |
tree | 999fdffb9d3db2e5200994e289e50fa3a3a1684a /spec/requests | |
parent | 7351a484d79236b7e9d47c86f2fcc970b7ae10b0 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/requests')
-rw-r--r-- | spec/requests/api/api_spec.rb | 25 | ||||
-rw-r--r-- | spec/requests/api/lsif_data_spec.rb | 89 | ||||
-rw-r--r-- | spec/requests/api/project_container_repositories_spec.rb | 1 | ||||
-rw-r--r-- | spec/requests/api/runner_spec.rb | 6 | ||||
-rw-r--r-- | spec/requests/git_http_spec.rb | 8 | ||||
-rw-r--r-- | spec/requests/lfs_http_spec.rb | 2 |
6 files changed, 123 insertions, 8 deletions
diff --git a/spec/requests/api/api_spec.rb b/spec/requests/api/api_spec.rb new file mode 100644 index 00000000000..c794db4cb0b --- /dev/null +++ b/spec/requests/api/api_spec.rb @@ -0,0 +1,25 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe API::API do + let(:user) { create(:user, last_activity_on: Date.yesterday) } + + describe 'Record user last activity in after hook' do + # It does not matter which endpoint is used because last_activity_on should + # be updated on every request. `/groups` is used as an example + # to represent any API endpoint + + it 'updates the users last_activity_on date' do + expect { get api('/groups', user) }.to change { user.reload.last_activity_on }.to(Date.today) + end + + context 'when the the api_activity_logging feature is disabled' do + it 'does not touch last_activity_on' do + stub_feature_flags(api_activity_logging: false) + + expect { get api('/groups', user) }.not_to change { user.reload.last_activity_on } + end + end + end +end diff --git a/spec/requests/api/lsif_data_spec.rb b/spec/requests/api/lsif_data_spec.rb new file mode 100644 index 00000000000..ca3a30bd1d0 --- /dev/null +++ b/spec/requests/api/lsif_data_spec.rb @@ -0,0 +1,89 @@ +# frozen_string_literal: true + +require "spec_helper" + +describe API::LsifData do + let_it_be(:user) { create(:user) } + let_it_be(:project) { create(:project, :repository) } + + let(:commit) { project.commit } + + describe 'GET lsif/info' do + let(:endpoint_path) { "/projects/#{project.id}/commits/#{commit.id}/lsif/info" } + + 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 + end + + context 'user has access to the project' do + before 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 + 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' } + + expect(response).to have_gitlab_http_status(:ok) + expect(response.parsed_body.last).to eq({ + 'end_char' => 18, + 'end_line' => 8, + 'start_char' => 13, + 'start_line' => 8 + }) + end + + context 'the stored file is too large' do + it 'returns 413' 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 + 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 + end + end + end + end +end diff --git a/spec/requests/api/project_container_repositories_spec.rb b/spec/requests/api/project_container_repositories_spec.rb index d04db134db0..ece2033f9f8 100644 --- a/spec/requests/api/project_container_repositories_spec.rb +++ b/spec/requests/api/project_container_repositories_spec.rb @@ -148,6 +148,7 @@ describe API::ProjectContainerRepositories do 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) diff --git a/spec/requests/api/runner_spec.rb b/spec/requests/api/runner_spec.rb index eb9db7ff6b7..9d01a44916c 100644 --- a/spec/requests/api/runner_spec.rb +++ b/spec/requests/api/runner_spec.rb @@ -1462,7 +1462,7 @@ describe API::Runner, :clean_gitlab_redis_shared_state do subject expect(response).to have_gitlab_http_status(200) - expect(response.content_type.to_s).to eq(Gitlab::Workhorse::INTERNAL_API_CONTENT_TYPE) + expect(response.media_type).to eq(Gitlab::Workhorse::INTERNAL_API_CONTENT_TYPE) expect(json_response['TempPath']).to eq(JobArtifactUploader.workhorse_local_upload_path) expect(json_response['RemoteObject']).to be_nil end @@ -1482,7 +1482,7 @@ describe API::Runner, :clean_gitlab_redis_shared_state do subject expect(response).to have_gitlab_http_status(200) - expect(response.content_type.to_s).to eq(Gitlab::Workhorse::INTERNAL_API_CONTENT_TYPE) + expect(response.media_type).to eq(Gitlab::Workhorse::INTERNAL_API_CONTENT_TYPE) expect(json_response).not_to have_key('TempPath') expect(json_response['RemoteObject']).to have_key('ID') expect(json_response['RemoteObject']).to have_key('GetURL') @@ -1558,7 +1558,7 @@ describe API::Runner, :clean_gitlab_redis_shared_state do authorize_artifacts_with_token_in_headers expect(response).to have_gitlab_http_status(200) - expect(response.content_type.to_s).to eq(Gitlab::Workhorse::INTERNAL_API_CONTENT_TYPE) + expect(response.media_type).to eq(Gitlab::Workhorse::INTERNAL_API_CONTENT_TYPE) expect(json_response['TempPath']).not_to be_nil end diff --git a/spec/requests/git_http_spec.rb b/spec/requests/git_http_spec.rb index 9f493fdffea..381ad45d477 100644 --- a/spec/requests/git_http_spec.rb +++ b/spec/requests/git_http_spec.rb @@ -92,7 +92,7 @@ describe 'Git HTTP requests' do it 'allows pulls' do download(path, env) do |response| expect(response).to have_gitlab_http_status(:ok) - expect(response.content_type.to_s).to eq(Gitlab::Workhorse::INTERNAL_API_CONTENT_TYPE) + expect(response.media_type).to eq(Gitlab::Workhorse::INTERNAL_API_CONTENT_TYPE) end end end @@ -101,7 +101,7 @@ describe 'Git HTTP requests' do it 'allows pushes', :sidekiq_might_not_need_inline do upload(path, env) do |response| expect(response).to have_gitlab_http_status(:ok) - expect(response.content_type.to_s).to eq(Gitlab::Workhorse::INTERNAL_API_CONTENT_TYPE) + expect(response.media_type).to eq(Gitlab::Workhorse::INTERNAL_API_CONTENT_TYPE) end end end @@ -509,7 +509,7 @@ describe 'Git HTTP requests' do download(path, env) do expect(response).to have_gitlab_http_status(:ok) - expect(response.content_type.to_s).to eq(Gitlab::Workhorse::INTERNAL_API_CONTENT_TYPE) + expect(response.media_type).to eq(Gitlab::Workhorse::INTERNAL_API_CONTENT_TYPE) end end @@ -518,7 +518,7 @@ describe 'Git HTTP requests' do upload(path, env) do expect(response).to have_gitlab_http_status(:ok) - expect(response.content_type.to_s).to eq(Gitlab::Workhorse::INTERNAL_API_CONTENT_TYPE) + expect(response.media_type).to eq(Gitlab::Workhorse::INTERNAL_API_CONTENT_TYPE) end end diff --git a/spec/requests/lfs_http_spec.rb b/spec/requests/lfs_http_spec.rb index 4e21c08ad5c..c6403a6ab75 100644 --- a/spec/requests/lfs_http_spec.rb +++ b/spec/requests/lfs_http_spec.rb @@ -907,7 +907,7 @@ describe 'Git LFS API and storage' do it_behaves_like 'LFS http 200 response' it 'uses the gitlab-workhorse content type' do - expect(response.content_type.to_s).to eq(Gitlab::Workhorse::INTERNAL_API_CONTENT_TYPE) + expect(response.media_type).to eq(Gitlab::Workhorse::INTERNAL_API_CONTENT_TYPE) end end |