Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-02-10 18:08:54 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2020-02-10 18:08:54 +0300
commit11e5d1b9ca3efa7be34ddebb708a6aedb4e91639 (patch)
tree999fdffb9d3db2e5200994e289e50fa3a3a1684a /spec/requests/api
parent7351a484d79236b7e9d47c86f2fcc970b7ae10b0 (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/requests/api')
-rw-r--r--spec/requests/api/api_spec.rb25
-rw-r--r--spec/requests/api/lsif_data_spec.rb89
-rw-r--r--spec/requests/api/project_container_repositories_spec.rb1
-rw-r--r--spec/requests/api/runner_spec.rb6
4 files changed, 118 insertions, 3 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