Skip to content

Commit e8a75d8

Browse files
committed
Fix devise integration tests
* Fix usr.login for AppSec Events kit
1 parent c790fdc commit e8a75d8

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

lib/datadog/kit/appsec/events.rb

+5-2
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,10 @@ def track_login_success(trace = nil, span = nil, user:, **others)
3333

3434
raise ArgumentError, 'missing required key: :user => { :id }' if user_id.nil?
3535

36-
others['usr.login'] ||= user_options.fetch(:login, user_id)
36+
if !others.key?('usr.login') && !others.key?(:'usr.login')
37+
others['usr.login'] = user_options.fetch(:login, user_id)
38+
end
39+
3740
track(LOGIN_SUCCESS_EVENT, active_trace, active_span, **others)
3841

3942
Kit::Identity.set_user(active_trace, active_span, id: user_id, **user_options)
@@ -56,7 +59,7 @@ def track_login_success(trace = nil, span = nil, user:, **others)
5659
# event information to attach to the trace.
5760
def track_login_failure(trace = nil, span = nil, user_exists:, user_id: nil, **others)
5861
set_trace_and_span_context('track_login_failure', trace, span) do |active_trace, active_span|
59-
others['usr.login'] ||= user_id if user_id
62+
others['usr.login'] = user_id if user_id && !others.key?('usr.login') && !others.key?(:'usr.login')
6063
track(LOGIN_FAILURE_EVENT, active_trace, active_span, **others)
6164

6265
active_span.set_tag('appsec.events.users.login.failure.usr.id', user_id) if user_id

spec/datadog/appsec/contrib/integration/devise/signin_multi_user_tracking_spec.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ def index
224224
before do
225225
Admin.create!(username: 'JohnDoe', email: 'john.doe@example.com', password: '123456')
226226

227-
post('/admins/sign_in', { user: { email: 'john.doe@example.com', password: '123456' } })
227+
post('/admins/sign_in', { admin: { email: 'john.doe@example.com', password: '123456' } })
228228
end
229229

230230
it 'tracks successfull login event' do

0 commit comments

Comments
 (0)