Commit 5d87931e authored by Max Woolf's avatar Max Woolf

Merge branch '351006-auditevents-openssl-exception-rescue' into 'master'

Catch HTTP errors exceptions while streaming audit events.

See merge request gitlab-org/gitlab!79410
parents f6d3f747 2344fddb
...@@ -29,6 +29,9 @@ module AuditEvents ...@@ -29,6 +29,9 @@ module AuditEvents
body: Gitlab::Json::LimitedEncoder.encode(audit_event.as_json, limit: REQUEST_BODY_SIZE_LIMIT), body: Gitlab::Json::LimitedEncoder.encode(audit_event.as_json, limit: REQUEST_BODY_SIZE_LIMIT),
use_read_total_timeout: true, use_read_total_timeout: true,
headers: { HEADER_KEY => destination.verification_token }) headers: { HEADER_KEY => destination.verification_token })
rescue URI::InvalidURIError => e
Gitlab::ErrorTracking.log_exception(e)
rescue *Gitlab::HTTP::HTTP_ERRORS
end end
end end
......
...@@ -65,6 +65,43 @@ RSpec.describe AuditEvents::AuditEventStreamingWorker do ...@@ -65,6 +65,43 @@ RSpec.describe AuditEvents::AuditEventStreamingWorker do
end end
end end
shared_examples 'a http post error is raised' do
subject { worker.perform(event.id) }
context 'when any of Gitlab::HTTP::HTTP_ERRORS is raised' do
Gitlab::HTTP::HTTP_ERRORS.each do |error_klass|
let(:error) { error_klass.new('error') }
before do
allow(Gitlab::HTTP).to receive(:post).and_raise(error)
end
it 'does not logs the error' do
expect(Gitlab::ErrorTracking).not_to receive(:log_exception).with(
an_instance_of(error_klass)
)
subject
end
end
end
context 'when URI::InvalidURIError exception is raised' do
let(:error) { URI::InvalidURIError.new('invalid uri') }
before do
group.external_audit_event_destinations.create!(destination_url: 'http://example.com')
allow(Gitlab::HTTP).to receive(:post).and_raise(error)
end
it 'logs the error' do
expect(Gitlab::ErrorTracking).to receive(:log_exception).with(
an_instance_of(URI::InvalidURIError)
).once
subject
end
end
end
describe "#perform" do describe "#perform" do
context 'when the entity type is a group' do context 'when the entity type is a group' do
it_behaves_like 'a successful audit event stream' do it_behaves_like 'a successful audit event stream' do
...@@ -72,6 +109,12 @@ RSpec.describe AuditEvents::AuditEventStreamingWorker do ...@@ -72,6 +109,12 @@ RSpec.describe AuditEvents::AuditEventStreamingWorker do
let(:group) { event.entity } let(:group) { event.entity }
end end
it_behaves_like 'a http post error is raised' do
let_it_be(:event) { create(:audit_event, :group_event) }
let(:group) { event.entity }
end
end end
context 'when the entity type is a project that belongs to a group' do context 'when the entity type is a project that belongs to a group' do
...@@ -80,6 +123,12 @@ RSpec.describe AuditEvents::AuditEventStreamingWorker do ...@@ -80,6 +123,12 @@ RSpec.describe AuditEvents::AuditEventStreamingWorker do
let_it_be(:project) { create(:project, group: group) } let_it_be(:project) { create(:project, group: group) }
let_it_be(:event) { create(:audit_event, :project_event, target_project: project) } let_it_be(:event) { create(:audit_event, :project_event, target_project: project) }
end end
it_behaves_like 'a http post error is raised' do
let_it_be(:group) { create(:group) }
let_it_be(:project) { create(:project, group: group) }
let_it_be(:event) { create(:audit_event, :project_event, target_project: project) }
end
end end
context 'when the entity type is a project at a root namespace level' do context 'when the entity type is a project at a root namespace level' do
......
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