Commit 470ed4f4 authored by David Fernandez's avatar David Fernandez

Merge branch '347217-conan-packages-map-validation-errors-to-400-response' into 'master'

Resolve "Conan packages: map validation errors to 400 responses"

See merge request gitlab-org/gitlab!79475
parents f5dbddc5 05c606f5
......@@ -38,6 +38,10 @@ module API
helpers ::API::Helpers::Packages::Conan::ApiHelpers
helpers ::API::Helpers::RelatedResourcesHelpers
rescue_from ActiveRecord::RecordInvalid do |e|
render_api_error!(e.message, 400)
end
before do
require_packages_enabled!
......@@ -285,6 +289,7 @@ module API
params do
requires :file_name, type: String, desc: 'Package file name', values: CONAN_FILES
end
namespace 'export/:file_name', requirements: FILE_NAME_REQUIREMENTS do
desc 'Download recipe files' do
detail 'This feature was introduced in GitLab 12.6'
......
......@@ -178,6 +178,25 @@ RSpec.shared_examples 'rejects invalid recipe' do
end
end
RSpec.shared_examples 'handling validation error for package' do
context 'with validation error' do
before do
allow_next_instance_of(Packages::Package) do |instance|
instance.errors.add(:base, 'validation error')
allow(instance).to receive(:valid?).and_return(false)
end
end
it 'returns 400' do
subject
expect(response).to have_gitlab_http_status(:bad_request)
expect(json_response['message']).to include('Validation failed')
end
end
end
RSpec.shared_examples 'handling empty values for username and channel' do
using RSpec::Parameterized::TableSyntax
......@@ -678,6 +697,7 @@ RSpec.shared_examples 'workhorse recipe file upload endpoint' do
it_behaves_like 'uploads a package file'
it_behaves_like 'creates build_info when there is a job'
it_behaves_like 'handling empty values for username and channel'
it_behaves_like 'handling validation error for package'
end
RSpec.shared_examples 'workhorse package file upload endpoint' do
......@@ -700,6 +720,7 @@ RSpec.shared_examples 'workhorse package file upload endpoint' do
it_behaves_like 'uploads a package file'
it_behaves_like 'creates build_info when there is a job'
it_behaves_like 'handling empty values for username and channel'
it_behaves_like 'handling validation error for package'
context 'tracking the conan_package.tgz upload' do
let(:file_name) { ::Packages::Conan::FileMetadatum::PACKAGE_BINARY }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment