Skip to content

Commit

Permalink
Fix PR comments.
Browse files Browse the repository at this point in the history
  • Loading branch information
hoolioh committed Jun 28, 2023
1 parent c55380e commit 79044b3
Showing 1 changed file with 27 additions and 22 deletions.
49 changes: 27 additions & 22 deletions packages/dd-trace/test/appsec/passport.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand All @@ -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: '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'
)
})

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'
Expand All @@ -115,7 +120,7 @@ describe('Passport', () => {
)
expect(events.trackEvent).to.have.been.calledOnceWithExactly(
'users.login.success',
{},
null,
'passportTrackEvent',
rootSpan,
'extended'
Expand All @@ -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: {
Expand All @@ -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: {
Expand All @@ -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'
}
}
}
Expand All @@ -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'
Expand All @@ -204,7 +209,7 @@ describe('Passport', () => {
)
expect(events.trackEvent).to.have.been.calledOnceWithExactly(
'users.login.success',
{},
null,
'passportTrackEvent',
rootSpan,
'extended'
Expand All @@ -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'
Expand Down

0 comments on commit 79044b3

Please sign in to comment.