Commit 140b5493 authored by Manoj M J's avatar Manoj M J

Modify exception logging in U2fRegistration’s callback

This MR modifies exception logging in
U2fRegistration’s callback
parent 38bbc861
...@@ -12,11 +12,7 @@ class U2fRegistration < ApplicationRecord ...@@ -12,11 +12,7 @@ class U2fRegistration < ApplicationRecord
converter = Gitlab::Auth::U2fWebauthnConverter.new(self) converter = Gitlab::Auth::U2fWebauthnConverter.new(self)
WebauthnRegistration.create!(converter.convert) WebauthnRegistration.create!(converter.convert)
rescue StandardError => ex rescue StandardError => ex
Gitlab::AppJsonLogger.error( Gitlab::ErrorTracking.track_exception(ex, u2f_registration_id: self.id)
event: 'u2f_migration',
error: ex.class.name,
backtrace: ::Gitlab::BacktraceCleaner.clean_backtrace(ex.backtrace),
message: "U2F to WebAuthn conversion failed")
end end
def update_webauthn_registration def update_webauthn_registration
......
...@@ -20,9 +20,9 @@ RSpec.describe U2fRegistration do ...@@ -20,9 +20,9 @@ RSpec.describe U2fRegistration do
describe '#create_webauthn_registration' do describe '#create_webauthn_registration' do
shared_examples_for 'creates webauthn registration' do shared_examples_for 'creates webauthn registration' do
it '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 expect(webauthn_registration).to exist
end end
end end
...@@ -43,13 +43,16 @@ RSpec.describe U2fRegistration do ...@@ -43,13 +43,16 @@ RSpec.describe U2fRegistration do
it 'logs error' do it 'logs error' do
allow(Gitlab::Auth::U2fWebauthnConverter).to receive(:new).and_raise('boom!') 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 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