@@ -13,6 +13,8 @@ const sinon = require('sinon');
1313const otplib = require ( 'otplib' ) ;
1414const assert = require ( '../../assert' ) ;
1515const gleanMock = mocks . mockGlean ( ) ;
16+ const { Container } = require ( 'typedi' ) ;
17+ const { AccountEventsManager } = require ( '../../../lib/account-events' ) ;
1618
1719const ROOT_DIR = '../../..' ;
1820
@@ -65,6 +67,11 @@ function makeRoutes(options = {}) {
6567 const glean = options . glean || gleanMock ;
6668 const statsd = options . statsd || mocks . mockStatsd ( ) ;
6769
70+ Container . set (
71+ AccountEventsManager ,
72+ options . accountEventsManager || { recordSecurityEvent : sinon . stub ( ) }
73+ ) ;
74+
6875 const Password =
6976 options . Password || require ( '../../../lib/crypto/password' ) ( log , config ) ;
7077 const customs = options . customs || {
@@ -715,12 +722,19 @@ describe('/session/destroy', () => {
715722 let request ;
716723 let log ;
717724 let db ;
725+ let securityEventStub ;
718726
719727 beforeEach ( ( ) => {
720728 db = mocks . mockDB ( ) ;
721729 log = mocks . mockLog ( ) ;
722730 const config = { } ;
723- const routes = makeRoutes ( { log, config, db } ) ;
731+ securityEventStub = sinon . stub ( ) ;
732+ const routes = makeRoutes ( {
733+ log,
734+ config,
735+ db,
736+ accountEventsManager : { recordSecurityEvent : securityEventStub } ,
737+ } ) ;
724738 route = getRoute ( routes , '/session/destroy' ) ;
725739 request = mocks . mockRequest ( {
726740 credentials : {
@@ -734,6 +748,12 @@ describe('/session/destroy', () => {
734748 it ( 'responds correctly when session is destroyed' , ( ) => {
735749 return runTest ( route , request ) . then ( ( res ) => {
736750 assert . equal ( Object . keys ( res ) . length , 0 ) ;
751+ sinon . assert . calledOnceWithExactly ( securityEventStub , db , {
752+ name : 'session.destroy' ,
753+ uid : 'foo' ,
754+ ipAddr : '63.245.221.32' ,
755+ tokenId : undefined ,
756+ } ) ;
737757 } ) ;
738758 } ) ;
739759
0 commit comments