Commit 0b9b0925 authored by Dmitry Gruzd's avatar Dmitry Gruzd

Merge branch 'mmj-u2f-exception-logging' into 'master'

Modify exception logging mechanism in U2fRegistration's callback

See merge request gitlab-org/gitlab!74673
parents 5a6f3da8 140b5493
......@@ -12,11 +12,7 @@ class U2fRegistration < ApplicationRecord
converter = Gitlab::Auth::U2fWebauthnConverter.new(self)
WebauthnRegistration.create!(converter.convert)
rescue StandardError => ex
Gitlab::AppJsonLogger.error(
event: 'u2f_migration',
error: ex.class.name,
backtrace: ::Gitlab::BacktraceCleaner.clean_backtrace(ex.backtrace),
message: "U2F to WebAuthn conversion failed")
Gitlab::ErrorTracking.track_exception(ex, u2f_registration_id: self.id)
end
def update_webauthn_registration
......
......@@ -20,9 +20,9 @@ RSpec.describe U2fRegistration do
describe '#create_webauthn_registration' do
shared_examples_for 'creates webauthn registration' do
it 'creates webauthn registration' do
u2f_registration.save!
created_record = u2f_registration
webauthn_registration = WebauthnRegistration.where(u2f_registration_id: u2f_registration.id)
webauthn_registration = WebauthnRegistration.where(u2f_registration_id: created_record.id)
expect(webauthn_registration).to exist
end
end
......@@ -43,13 +43,16 @@ RSpec.describe U2fRegistration do
it 'logs error' do
allow(Gitlab::Auth::U2fWebauthnConverter).to receive(:new).and_raise('boom!')
expect(Gitlab::AppJsonLogger).to(
receive(:error).with(a_hash_including(event: 'u2f_migration',
error: 'RuntimeError',
message: 'U2F to WebAuthn conversion failed'))
)
u2f_registration.save!
allow_next_instance_of(U2fRegistration) do |u2f_registration|
allow(u2f_registration).to receive(:id).and_return(123)
end
expect(Gitlab::ErrorTracking).to(
receive(:track_exception).with(kind_of(StandardError),
u2f_registration_id: 123))
u2f_registration
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