Commit 5bdbf365 authored by Douglas Barbosa Alexandre's avatar Douglas Barbosa Alexandre

Merge branch 'vij-snippet-status-codes' into 'master'

Modify invalid Snippet response status codes

See merge request gitlab-org/gitlab!40619
parents 255e8376 f93f1913
...@@ -46,7 +46,7 @@ module Snippets ...@@ -46,7 +46,7 @@ module Snippets
snippet.errors.add(:snippet_actions, 'have invalid data') snippet.errors.add(:snippet_actions, 'have invalid data')
end end
snippet_error_response(snippet, 403) snippet_error_response(snippet, 422)
end end
def snippet_error_response(snippet, http_status) def snippet_error_response(snippet, http_status)
......
---
title: Change invalid Snippet params status code from 403 to 422
merge_request: 40619
author:
type: changed
...@@ -417,7 +417,7 @@ RSpec.describe API::Snippets do ...@@ -417,7 +417,7 @@ RSpec.describe API::Snippets do
true | nil | '' | [create_action] | :bad_request true | nil | '' | [create_action] | :bad_request
true | nil | nil | [bad_file_path] | :bad_request true | nil | nil | [bad_file_path] | :bad_request
true | nil | nil | [bad_previous_path] | :bad_request true | nil | nil | [bad_previous_path] | :bad_request
true | nil | nil | [invalid_move] | :forbidden true | nil | nil | [invalid_move] | :unprocessable_entity
false | 'foo.txt' | 'bar' | nil | :success false | 'foo.txt' | 'bar' | nil | :success
false | 'foo.txt' | nil | nil | :success false | 'foo.txt' | nil | nil | :success
......
...@@ -313,6 +313,7 @@ RSpec.describe Snippets::CreateService do ...@@ -313,6 +313,7 @@ RSpec.describe Snippets::CreateService do
it_behaves_like 'creates repository and files' it_behaves_like 'creates repository and files'
it_behaves_like 'after_save callback to store_mentions', ProjectSnippet it_behaves_like 'after_save callback to store_mentions', ProjectSnippet
it_behaves_like 'when snippet_actions param is present' 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 context 'when uploaded files are passed to the service' do
let(:extra_opts) { { files: ['foo'] } } let(:extra_opts) { { files: ['foo'] } }
...@@ -340,6 +341,7 @@ RSpec.describe Snippets::CreateService do ...@@ -340,6 +341,7 @@ RSpec.describe Snippets::CreateService do
it_behaves_like 'creates repository and files' it_behaves_like 'creates repository and files'
it_behaves_like 'after_save callback to store_mentions', PersonalSnippet it_behaves_like 'after_save callback to store_mentions', PersonalSnippet
it_behaves_like 'when snippet_actions param is present' it_behaves_like 'when snippet_actions param is present'
it_behaves_like 'invalid params error response'
context 'when the snippet description contains files' do context 'when the snippet description contains files' do
include FileMoverHelpers include FileMoverHelpers
......
...@@ -698,6 +698,7 @@ RSpec.describe Snippets::UpdateService do ...@@ -698,6 +698,7 @@ RSpec.describe Snippets::UpdateService do
it_behaves_like 'when snippet_actions param is present' it_behaves_like 'when snippet_actions param is present'
it_behaves_like 'only file_name is present' it_behaves_like 'only file_name is present'
it_behaves_like 'only content 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 it_behaves_like 'snippets spam check is performed' do
before do before do
subject subject
...@@ -725,6 +726,7 @@ RSpec.describe Snippets::UpdateService do ...@@ -725,6 +726,7 @@ RSpec.describe Snippets::UpdateService do
it_behaves_like 'when snippet_actions param is present' it_behaves_like 'when snippet_actions param is present'
it_behaves_like 'only file_name is present' it_behaves_like 'only file_name is present'
it_behaves_like 'only content 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 it_behaves_like 'snippets spam check is performed' do
before do before do
subject subject
......
...@@ -40,3 +40,20 @@ RSpec.shared_examples 'snippets spam check is performed' do ...@@ -40,3 +40,20 @@ RSpec.shared_examples 'snippets spam check is performed' do
end end
end 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