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
end
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
private
......
......@@ -9,6 +9,9 @@ RSpec.describe Gitlab::Checks::SnippetCheck do
let(:user_access) { Gitlab::UserAccessSnippet.new(user, snippet: snippet) }
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) }
......@@ -17,11 +20,19 @@ RSpec.describe Gitlab::Checks::SnippetCheck do
expect { subject.validate! }.not_to raise_error
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
let(:newrev) { '0000000000000000000000000000000000000000' }
it 'raises an error' do
expect { subject.validate! }.to raise_error(Gitlab::GitAccess::ForbiddenError, 'You can not create or delete branches.')
it_behaves_like 'raises and logs error' do
let(:deletion) { true }
end
end
......@@ -29,8 +40,9 @@ RSpec.describe Gitlab::Checks::SnippetCheck do
let(:oldrev) { '0000000000000000000000000000000000000000' }
let(:ref) { 'refs/heads/feature' }
it 'raises an error' do
expect { subject.validate! }.to raise_error(Gitlab::GitAccess::ForbiddenError, 'You can not create or delete branches.')
it_behaves_like 'raises and logs error' do
let(:creation) { true }
let(:branch_name) { 'feature' }
end
context "when branch is 'master'" do
......@@ -45,8 +57,8 @@ RSpec.describe Gitlab::Checks::SnippetCheck do
context 'when default_branch is nil' do
let(:default_branch) { nil }
it 'raises an error' do
expect { subject.validate! }.to raise_error(Gitlab::GitAccess::ForbiddenError, 'You can not create or delete branches.')
it_behaves_like 'raises and logs error' do
let(:branch_name) { 'master' }
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