-
Notifications
You must be signed in to change notification settings - Fork 318
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
27 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,23 +38,23 @@ 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', () => { | ||
const credentials = { type: 'unknown', username: 'test' } | ||
|
||
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,37 +76,42 @@ 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' | ||
) | ||
}) | ||
|
||
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: '[email protected]', | ||
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' | ||
) | ||
}) | ||
|
||
it('should report login success and the extended fields in extended mode', () => { | ||
const user = userUuid | ||
const user = { | ||
id: 'publicName', | ||
email: '[email protected]', | ||
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: '[email protected]', | ||
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: '[email protected]', | ||
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: '[email protected]', | ||
username: 'Test User' | ||
}, rootSpan) | ||
expect(events.trackEvent).to.have.been.calledOnceWithExactly( | ||
'users.login.success', | ||
{}, | ||
null, | ||
'passportTrackEvent', | ||
rootSpan, | ||
'extended' | ||
|