Skip to content

Commit

Permalink
Merge pull request #2663 from coneill-enhance/patch-1
Browse files Browse the repository at this point in the history
fix: prevent unintentional modification of arguments
  • Loading branch information
GustavoCaso authored Mar 8, 2023
2 parents e3cdbb4 + fd5ce77 commit 848c6db
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/datadog/kit/appsec/events.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def self.track_login_success(trace, user:, **others)
track(LOGIN_SUCCESS_EVENT, trace, **others)

user_options = user.dup
user_id = user.delete(:id)
user_id = user_options.delete(:id)

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

Expand Down
9 changes: 9 additions & 0 deletions spec/datadog/kit/appsec/events_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,15 @@
end
expect(meta).to include('usr.id' => '42', 'appsec.events.users.login.success.foo' => 'bar')
end

it 'maintains integrity of user argument' do
user_argument = { id: '42' }
user_argument_dup = user_argument.dup
trace_op.measure('root') do
described_class.track_login_success(trace_op, user: user_argument, foo: 'bar')
end
expect(user_argument).to eql(user_argument_dup)
end
end

describe '#track_login_failure' do
Expand Down

0 comments on commit 848c6db

Please sign in to comment.