From 4eed545e92f2b9266b86674039e25edf95a4e0d4 Mon Sep 17 00:00:00 2001 From: Julio Gonzalez Date: Wed, 28 Jun 2023 18:38:19 +0200 Subject: [PATCH] Fix PR comments. --- .../dd-trace/test/appsec/passport.spec.js | 53 ++++++++++--------- 1 file changed, 29 insertions(+), 24 deletions(-) diff --git a/packages/dd-trace/test/appsec/passport.spec.js b/packages/dd-trace/test/appsec/passport.spec.js index 9d3e59d07fc..9d1ad8a0e00 100644 --- a/packages/dd-trace/test/appsec/passport.spec.js +++ b/packages/dd-trace/test/appsec/passport.spec.js @@ -15,6 +15,8 @@ describe('Passport', () => { let passportModule, log, events, setUser beforeEach(() => { + rootSpan.context = () => { return {} } + log = { warn: sinon.stub() } @@ -38,7 +40,7 @@ describe('Passport', () => { it('should call log when credentials is undefined', () => { passportModule.passportTrackEvent(undefined, undefined, undefined, 'safe') - expect(log.warn).to.have.been.calledOnceWithExactly('No username found in authentication instrumentation') + expect(log.warn).to.have.been.calledOnceWithExactly('No user ID found in authentication instrumentation') }) it('should call log when type is not known', () => { @@ -46,15 +48,15 @@ describe('Passport', () => { passportModule.passportTrackEvent(credentials, undefined, undefined, 'safe') - expect(log.warn).to.have.been.calledOnceWithExactly('No username found in authentication instrumentation') + expect(log.warn).to.have.been.calledOnceWithExactly('No user ID found in authentication instrumentation') }) it('should call log when type is known but username not present', () => { - const credentials = { type: 'unknown' } + const credentials = { type: 'http' } passportModule.passportTrackEvent(credentials, undefined, undefined, 'safe') - expect(log.warn).to.have.been.calledOnceWithExactly('No username found in authentication instrumentation') + expect(log.warn).to.have.been.calledOnceWithExactly('No user ID found in authentication instrumentation') }) it('should report login failure when passportUser is not present', () => { @@ -76,7 +78,7 @@ describe('Passport', () => { expect(setUser.setUserTags).to.have.been.calledOnceWithExactly({ id: userUuid.id }, rootSpan) expect(events.trackEvent).to.have.been.calledOnceWithExactly( 'users.login.success', - {}, + null, 'passportTrackEvent', rootSpan, 'safe' @@ -84,15 +86,17 @@ describe('Passport', () => { }) it('should report login success and blank id in safe mode when id is not a uuid', () => { - const user = userUuid - - user.id = 'publicName' + const user = { + id: 'publicName', + email: 'testUser@test.com', + username: 'Test User' + } passportModule.passportTrackEvent(loginLocal, user, rootSpan, 'safe') expect(setUser.setUserTags).to.have.been.calledOnceWithExactly({ id: ' ' }, rootSpan) expect(events.trackEvent).to.have.been.calledOnceWithExactly( 'users.login.success', - {}, + null, 'passportTrackEvent', rootSpan, 'safe' @@ -100,13 +104,16 @@ describe('Passport', () => { }) it('should report login success and the extended fields in extended mode', () => { - const user = userUuid + const user = { + id: 'publicName', + email: 'testUser@test.com', + username: 'Test User' + } - user.id = 'publicName' passportModule.passportTrackEvent(loginLocal, user, rootSpan, 'extended') expect(setUser.setUserTags).to.have.been.calledOnceWithExactly( { - id: user.id, + id: 'publicName', login: 'test', email: 'testUser@test.com', username: 'Test User' @@ -115,7 +122,7 @@ describe('Passport', () => { ) expect(events.trackEvent).to.have.been.calledOnceWithExactly( 'users.login.success', - {}, + null, 'passportTrackEvent', rootSpan, 'extended' @@ -136,7 +143,7 @@ describe('Passport', () => { expect(events.trackEvent).not.to.have.been.called }) - it('should not call trackEvent in extended mode if sdk user event functions are already called', () => { + it('should not call trackEvent in extended mode if trackUserLoginSuccessEvent is already called', () => { rootSpan.context = () => { return { _tags: { @@ -150,7 +157,7 @@ describe('Passport', () => { expect(events.trackEvent).not.to.have.been.called }) - it('should call trackEvent in extended mode if sdk custom event function is already called', () => { + it('should call trackEvent in extended mode if trackCustomEvent function is already called', () => { rootSpan.context = () => { return { _tags: { @@ -162,18 +169,18 @@ describe('Passport', () => { passportModule.passportTrackEvent(loginLocal, userUuid, rootSpan, 'extended') expect(events.trackEvent).to.have.been.calledOnceWithExactly( 'users.login.success', - {}, + null, 'passportTrackEvent', rootSpan, 'extended' ) }) - it('should call trackEvent in extended mode if sdk dy called', () => { + it('should not call trackEvent in extended mode if trackUserLoginFailureEvent is already called', () => { rootSpan.context = () => { return { _tags: { - '_dd.appsec.events.users.login.success.sdk': 'true' + '_dd.appsec.events.users.login.failure.sdk': 'true' } } } @@ -190,12 +197,10 @@ describe('Passport', () => { username: 'Test User' } - rootSpan.context = () => { return {} } - passportModule.passportTrackEvent(loginLocal, user, rootSpan, 'extended') expect(setUser.setUserTags).to.have.been.calledOnceWithExactly( { - id: user._id, + id: '591dc126-8431-4d0f-9509-b23318d3dce4', login: 'test', email: 'testUser@test.com', username: 'Test User' @@ -204,7 +209,7 @@ describe('Passport', () => { ) expect(events.trackEvent).to.have.been.calledOnceWithExactly( 'users.login.success', - {}, + null, 'passportTrackEvent', rootSpan, 'extended' @@ -222,14 +227,14 @@ describe('Passport', () => { passportModule.passportTrackEvent(loginLocal, user, rootSpan, 'extended') expect(setUser.setUserTags).to.have.been.calledOnceWithExactly( { - id: loginLocal.username, + id: 'test', login: 'test', email: 'testUser@test.com', username: 'Test User' }, rootSpan) expect(events.trackEvent).to.have.been.calledOnceWithExactly( 'users.login.success', - {}, + null, 'passportTrackEvent', rootSpan, 'extended'