From 79044b39f2fa010cb53b225c7119a4120c5a46c6 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 | 49 ++++++++++--------- 1 file changed, 27 insertions(+), 22 deletions(-) diff --git a/packages/dd-trace/test/appsec/passport.spec.js b/packages/dd-trace/test/appsec/passport.spec.js index 9d3e59d07fc..c12d2e1d403 100644 --- a/packages/dd-trace/test/appsec/passport.spec.js +++ b/packages/dd-trace/test/appsec/passport.spec.js @@ -38,7 +38,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 +46,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 +76,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 +84,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 +102,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 +120,7 @@ describe('Passport', () => { ) expect(events.trackEvent).to.have.been.calledOnceWithExactly( 'users.login.success', - {}, + null, 'passportTrackEvent', rootSpan, 'extended' @@ -136,7 +141,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 +155,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 +167,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' } } } @@ -195,7 +200,7 @@ describe('Passport', () => { 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'