@@ -99,7 +99,10 @@ const makeRoutes = function (options = {}, requireMocks = {}) {
9999 Container . set ( AuthLogger , log ) ;
100100
101101 Container . set ( AppConfig , config ) ;
102- Container . set ( AccountEventsManager , new AccountEventsManager ( ) ) ;
102+ Container . set (
103+ AccountEventsManager ,
104+ options . mockAccountEventsManager || new AccountEventsManager ( )
105+ ) ;
103106 Container . set ( RelyingPartyConfigurationManager , rpConfigManager ) ;
104107
105108 const mailer = options . mailer || { } ;
@@ -3153,7 +3156,7 @@ describe('/account/login', () => {
31533156 } ) ;
31543157
31553158 describe ( 'skip for new accounts' , ( ) => {
3156- function setup ( enabled , accountCreatedSince ) {
3159+ function setup ( enabled , accountCreatedSince , makeRoutesOptions = { } ) {
31573160 config . signinConfirmation . skipForNewAccounts = {
31583161 enabled : enabled ,
31593162 maxAge : 5 ,
@@ -3184,6 +3187,7 @@ describe('/account/login', () => {
31843187 } ;
31853188
31863189 const accountRoutes = makeRoutes ( {
3190+ ...makeRoutesOptions ,
31873191 checkPassword : function ( ) {
31883192 return Promise . resolve ( true ) ;
31893193 } ,
@@ -3373,14 +3377,30 @@ describe('/account/login', () => {
33733377 it ( 'logs metrics when accountAge is under maxAge config threshold' , ( ) => {
33743378 glean . loginConfirmSkipFor . newAccount . reset ( ) ;
33753379
3376- setup ( true , 0 ) ;
3380+ const mockAccountEventsManager = {
3381+ recordSecurityEvent : sinon . fake ( ) ,
3382+ } ;
3383+ setup ( true , 0 , { mockAccountEventsManager } ) ;
33773384
33783385 return runTest ( route , mockRequest , ( ) => {
33793386 sinon . assert . calledOnce ( glean . loginConfirmSkipFor . newAccount ) ;
33803387 sinon . assert . calledWith (
33813388 statsd . increment ,
33823389 'account.signin.confirm.bypass.newAccount'
33833390 ) ;
3391+ sinon . assert . calledWithMatch (
3392+ mockAccountEventsManager . recordSecurityEvent ,
3393+ mockDB ,
3394+ sinon . match ( {
3395+ name : 'account.signin_confirm_bypass_new_account' ,
3396+ uid,
3397+ ipAddr : mockRequest . app . clientAddress ,
3398+ additionalInfo : {
3399+ userAgent : mockRequest . headers [ 'user-agent' ] ,
3400+ location : mockRequest . app . geo . location ,
3401+ } ,
3402+ } )
3403+ ) ;
33843404 } ) ;
33853405 } ) ;
33863406
@@ -3396,6 +3416,11 @@ describe('/account/login', () => {
33963416 } ,
33973417 ] ) ;
33983418 } ) ;
3419+ const mockAccountEventsManager = {
3420+ recordSecurityEvent : sinon . fake ( ) ,
3421+ } ;
3422+ setup ( true , 0 , { mockAccountEventsManager } ) ;
3423+
33993424 return runTest ( route , mockRequest , ( response ) => {
34003425 assert . equal (
34013426 mockDB . verifiedLoginSecurityEvents . callCount ,
@@ -3404,6 +3429,19 @@ describe('/account/login', () => {
34043429 ) ;
34053430
34063431 sinon . assert . called ( glean . loginConfirmSkipFor . knownIp ) ;
3432+ sinon . assert . calledWithMatch (
3433+ mockAccountEventsManager . recordSecurityEvent ,
3434+ mockDB ,
3435+ sinon . match ( {
3436+ name : 'account.signin_confirm_bypass_known_ip' ,
3437+ uid,
3438+ ipAddr : mockRequest . app . clientAddress ,
3439+ additionalInfo : {
3440+ userAgent : mockRequest . headers [ 'user-agent' ] ,
3441+ location : mockRequest . app . geo . location ,
3442+ } ,
3443+ } )
3444+ ) ;
34073445 } ) ;
34083446 } ) ;
34093447 } ) ;
0 commit comments