Commit 285e10aa authored by Sean McGivern's avatar Sean McGivern

Merge branch 'fj-add-exception-loggin-snippet-check' into 'master'

Add exception logging in SnippetsCheck

See merge request gitlab-org/gitlab!48873
parents f353f6b7 44ffde08
...@@ -26,6 +26,10 @@ module Gitlab ...@@ -26,6 +26,10 @@ module Gitlab
end end
true true
rescue GitAccess::ForbiddenError => e
Gitlab::ErrorTracking.log_exception(e, default_branch: @default_branch, branch_name: @branch_name, creation: creation?, deletion: deletion?)
raise e
end end
private private
......
...@@ -9,6 +9,9 @@ RSpec.describe Gitlab::Checks::SnippetCheck do ...@@ -9,6 +9,9 @@ RSpec.describe Gitlab::Checks::SnippetCheck do
let(:user_access) { Gitlab::UserAccessSnippet.new(user, snippet: snippet) } let(:user_access) { Gitlab::UserAccessSnippet.new(user, snippet: snippet) }
let(:default_branch) { snippet.default_branch } let(:default_branch) { snippet.default_branch }
let(:branch_name) { default_branch }
let(:creation) { false }
let(:deletion) { false }
subject { Gitlab::Checks::SnippetCheck.new(changes, default_branch: default_branch, logger: logger) } subject { Gitlab::Checks::SnippetCheck.new(changes, default_branch: default_branch, logger: logger) }
...@@ -17,11 +20,19 @@ RSpec.describe Gitlab::Checks::SnippetCheck do ...@@ -17,11 +20,19 @@ RSpec.describe Gitlab::Checks::SnippetCheck do
expect { subject.validate! }.not_to raise_error expect { subject.validate! }.not_to raise_error
end end
shared_examples 'raises and logs error' do
specify do
expect(Gitlab::ErrorTracking).to receive(:log_exception).with(instance_of(Gitlab::GitAccess::ForbiddenError), default_branch: default_branch, branch_name: branch_name, creation: creation, deletion: deletion)
expect { subject.validate! }.to raise_error(Gitlab::GitAccess::ForbiddenError, 'You can not create or delete branches.')
end
end
context 'trying to delete the branch' do context 'trying to delete the branch' do
let(:newrev) { '0000000000000000000000000000000000000000' } let(:newrev) { '0000000000000000000000000000000000000000' }
it 'raises an error' do it_behaves_like 'raises and logs error' do
expect { subject.validate! }.to raise_error(Gitlab::GitAccess::ForbiddenError, 'You can not create or delete branches.') let(:deletion) { true }
end end
end end
...@@ -29,8 +40,9 @@ RSpec.describe Gitlab::Checks::SnippetCheck do ...@@ -29,8 +40,9 @@ RSpec.describe Gitlab::Checks::SnippetCheck do
let(:oldrev) { '0000000000000000000000000000000000000000' } let(:oldrev) { '0000000000000000000000000000000000000000' }
let(:ref) { 'refs/heads/feature' } let(:ref) { 'refs/heads/feature' }
it 'raises an error' do it_behaves_like 'raises and logs error' do
expect { subject.validate! }.to raise_error(Gitlab::GitAccess::ForbiddenError, 'You can not create or delete branches.') let(:creation) { true }
let(:branch_name) { 'feature' }
end end
context "when branch is 'master'" do context "when branch is 'master'" do
...@@ -45,8 +57,8 @@ RSpec.describe Gitlab::Checks::SnippetCheck do ...@@ -45,8 +57,8 @@ RSpec.describe Gitlab::Checks::SnippetCheck do
context 'when default_branch is nil' do context 'when default_branch is nil' do
let(:default_branch) { nil } let(:default_branch) { nil }
it 'raises an error' do it_behaves_like 'raises and logs error' do
expect { subject.validate! }.to raise_error(Gitlab::GitAccess::ForbiddenError, 'You can not create or delete branches.') let(:branch_name) { 'master' }
end end
end 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