Commit e74ae486 authored by Vijay Hawoldar's avatar Vijay Hawoldar

Modify invalid Snippet response codes

Previously if a Snippet service had invalid params
it would return a 403 (forbidden) status code, but a
422 (Unprocessable Entity) is more appropriate in this scenario
parent 54e30da3
......@@ -46,7 +46,7 @@ module Snippets
snippet.errors.add(:snippet_actions, 'have invalid data')
end
snippet_error_response(snippet, 403)
snippet_error_response(snippet, 422)
end
def snippet_error_response(snippet, http_status)
......
......@@ -313,6 +313,7 @@ RSpec.describe Snippets::CreateService do
it_behaves_like 'creates repository and files'
it_behaves_like 'after_save callback to store_mentions', ProjectSnippet
it_behaves_like 'when snippet_actions param is present'
it_behaves_like 'invalid params error response'
context 'when uploaded files are passed to the service' do
let(:extra_opts) { { files: ['foo'] } }
......@@ -340,6 +341,7 @@ RSpec.describe Snippets::CreateService do
it_behaves_like 'creates repository and files'
it_behaves_like 'after_save callback to store_mentions', PersonalSnippet
it_behaves_like 'when snippet_actions param is present'
it_behaves_like 'invalid params error response'
context 'when the snippet description contains files' do
include FileMoverHelpers
......
......@@ -698,6 +698,7 @@ RSpec.describe Snippets::UpdateService do
it_behaves_like 'when snippet_actions param is present'
it_behaves_like 'only file_name is present'
it_behaves_like 'only content is present'
it_behaves_like 'invalid params error response'
it_behaves_like 'snippets spam check is performed' do
before do
subject
......@@ -725,6 +726,7 @@ RSpec.describe Snippets::UpdateService do
it_behaves_like 'when snippet_actions param is present'
it_behaves_like 'only file_name is present'
it_behaves_like 'only content is present'
it_behaves_like 'invalid params error response'
it_behaves_like 'snippets spam check is performed' do
before do
subject
......
......@@ -40,3 +40,20 @@ RSpec.shared_examples 'snippets spam check is performed' do
end
end
end
shared_examples 'invalid params error response' do
before do
allow_next_instance_of(described_class) do |service|
allow(service).to receive(:valid_params?).and_return false
end
end
it 'responds to errors appropriately' do
response = subject
aggregate_failures do
expect(response).to be_error
expect(response.http_status).to eq 422
end
end
end
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