summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-02-27 09:09:01 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2020-02-27 09:09:01 +0000
commitc72e5ebe9938d315ec598197873e71a80168d40a (patch)
tree439bf5c40aaf774e5a301825af517cb52726f450 /spec
parentffc43b862df32a590eae874bcbb11109b46dc8be (diff)
downloadgitlab-ce-c72e5ebe9938d315ec598197873e71a80168d40a.tar.gz
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec')
-rw-r--r--spec/lib/gitlab/profiler_spec.rb6
-rw-r--r--spec/requests/api/project_import_spec.rb109
-rw-r--r--spec/support/helpers/workhorse_helpers.rb4
-rw-r--r--spec/views/projects/settings/operations/show.html.haml_spec.rb2
4 files changed, 118 insertions, 3 deletions
diff --git a/spec/lib/gitlab/profiler_spec.rb b/spec/lib/gitlab/profiler_spec.rb
index 1e53faf7275..603417c5532 100644
--- a/spec/lib/gitlab/profiler_spec.rb
+++ b/spec/lib/gitlab/profiler_spec.rb
@@ -221,6 +221,12 @@ describe Gitlab::Profiler do
.map { |(total)| total.to_f }
expect(output).to include('Kernel#sleep')
+
+ if total_times != total_times.sort.reverse
+ warn "Profiler test failed, output is:"
+ warn output
+ end
+
expect(total_times).to eq(total_times.sort.reverse)
expect(total_times).not_to eq(total_times.uniq)
end
diff --git a/spec/requests/api/project_import_spec.rb b/spec/requests/api/project_import_spec.rb
index 71dd8fee0ae..1cba98d6dee 100644
--- a/spec/requests/api/project_import_spec.rb
+++ b/spec/requests/api/project_import_spec.rb
@@ -3,11 +3,16 @@
require 'spec_helper'
describe API::ProjectImport do
+ include WorkhorseHelpers
+
let(:export_path) { "#{Dir.tmpdir}/project_export_spec" }
let(:user) { create(:user) }
let(:file) { File.join('spec', 'features', 'projects', 'import_export', 'test_project_export.tar.gz') }
let(:namespace) { create(:group) }
+ let(:workhorse_token) { JWT.encode({ 'iss' => 'gitlab-workhorse' }, Gitlab::Workhorse.secret, 'HS256') }
+ let(:workhorse_headers) { { 'GitLab-Workhorse' => '1.0', Gitlab::Workhorse::INTERNAL_API_REQUEST_HEADER => workhorse_token } }
+
before do
allow_any_instance_of(Gitlab::ImportExport).to receive(:storage_path).and_return(export_path)
stub_uploads_object_storage(FileUploader)
@@ -209,6 +214,55 @@ describe API::ProjectImport do
end
end
+ context 'with direct upload enabled' do
+ subject { upload_archive(file_upload, workhorse_headers, params) }
+
+ let(:file_name) { 'project_export.tar.gz' }
+
+ let!(:fog_connection) do
+ stub_uploads_object_storage(ImportExportUploader, direct_upload: true)
+ end
+
+ let(:tmp_object) do
+ fog_connection.directories.new(key: 'uploads').files.create(
+ key: "tmp/uploads/#{file_name}",
+ body: fixture_file_upload(file)
+ )
+ end
+
+ let(:file_upload) { fog_to_uploaded_file(tmp_object) }
+
+ let(:params) do
+ {
+ path: 'test-import-project',
+ namespace: namespace.id,
+ 'file.remote_id' => file_name,
+ 'file.size' => file_upload.size
+ }
+ end
+
+ before do
+ allow(ImportExportUploader).to receive(:workhorse_upload_path).and_return('/')
+ end
+
+ it 'accepts the request and stores the file' do
+ expect { subject }.to change { Project.count }.by(1)
+
+ expect(response).to have_gitlab_http_status(:created)
+ end
+ end
+
+ def upload_archive(file, headers = {}, params = {})
+ workhorse_finalize(
+ api("/projects/import", user),
+ method: :post,
+ file_key: :file,
+ params: params.merge(file: file_upload),
+ headers: headers,
+ send_rewritten_field: true
+ )
+ end
+
def stub_import(namespace)
expect_any_instance_of(ProjectImportState).to receive(:schedule)
expect(::Projects::CreateService).to receive(:new).with(user, hash_including(namespace_id: namespace.id)).and_call_original
@@ -238,4 +292,59 @@ describe API::ProjectImport do
'import_error' => 'error')
end
end
+
+ describe 'POST /projects/import/authorize' do
+ subject { post api('/projects/import/authorize', user), headers: workhorse_headers }
+
+ it 'authorizes importing project with workhorse header' do
+ subject
+
+ expect(response).to have_gitlab_http_status(:ok)
+ expect(response.content_type.to_s).to eq(Gitlab::Workhorse::INTERNAL_API_CONTENT_TYPE)
+ end
+
+ it 'rejects requests that bypassed gitlab-workhorse' do
+ workhorse_headers.delete(Gitlab::Workhorse::INTERNAL_API_REQUEST_HEADER)
+
+ subject
+
+ expect(response).to have_gitlab_http_status(:forbidden)
+ end
+
+ context 'when using remote storage' do
+ context 'when direct upload is enabled' do
+ before do
+ stub_uploads_object_storage(ImportExportUploader, enabled: true, direct_upload: true)
+ end
+
+ it 'responds with status 200, location of file remote store and object details' do
+ subject
+
+ expect(response).to have_gitlab_http_status(:ok)
+ expect(response.content_type.to_s).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')
+ expect(json_response['RemoteObject']).to have_key('StoreURL')
+ expect(json_response['RemoteObject']).to have_key('DeleteURL')
+ expect(json_response['RemoteObject']).to have_key('MultipartUpload')
+ end
+ end
+
+ context 'when direct upload is disabled' do
+ before do
+ stub_uploads_object_storage(ImportExportUploader, enabled: true, direct_upload: false)
+ end
+
+ it 'handles as a local file' do
+ subject
+
+ expect(response).to have_gitlab_http_status(:ok)
+ expect(response.content_type.to_s).to eq(Gitlab::Workhorse::INTERNAL_API_CONTENT_TYPE)
+ expect(json_response['TempPath']).to eq(ImportExportUploader.workhorse_local_upload_path)
+ expect(json_response['RemoteObject']).to be_nil
+ end
+ end
+ end
+ end
end
diff --git a/spec/support/helpers/workhorse_helpers.rb b/spec/support/helpers/workhorse_helpers.rb
index e0fba191deb..27d5083728d 100644
--- a/spec/support/helpers/workhorse_helpers.rb
+++ b/spec/support/helpers/workhorse_helpers.rb
@@ -32,12 +32,12 @@ module WorkhorseHelpers
# workhorse_finalize will transform file_key inside params as if it was the finalize call of an inline object storage upload.
# note that based on the content of the params it can simulate a disc acceleration or an object storage upload
- def workhorse_finalize(url, method: :post, file_key:, params:, headers: {})
+ def workhorse_finalize(url, method: :post, file_key:, params:, headers: {}, send_rewritten_field: false)
workhorse_request_with_file(method, url,
file_key: file_key,
params: params,
extra_headers: headers,
- send_rewritten_field: false
+ send_rewritten_field: send_rewritten_field
)
end
diff --git a/spec/views/projects/settings/operations/show.html.haml_spec.rb b/spec/views/projects/settings/operations/show.html.haml_spec.rb
index ece9c16650f..7d6faae0f5a 100644
--- a/spec/views/projects/settings/operations/show.html.haml_spec.rb
+++ b/spec/views/projects/settings/operations/show.html.haml_spec.rb
@@ -26,7 +26,7 @@ describe 'projects/settings/operations/show' do
context 'Settings page ' do
it 'renders the Operations Settings page' do
- render
+ render template: "projects/settings/operations/show", locals: { prometheus_service: project.find_or_initialize_service('prometheus') }
expect(rendered).to have_content _('Error Tracking')
expect(rendered).to have_content _('To link Sentry to GitLab, enter your Sentry URL and Auth Token')