@@ -133,7 +133,7 @@ describe('Account Events', () => {
133133 describe ( 'security events' , ( ) => {
134134 it ( 'can record security event' , async ( ) => {
135135 const message = {
136- name : 'account.login' as const ,
136+ name : 'account.login' ,
137137 uid : '000' ,
138138 ipAddr : '123.123.123.123' ,
139139 tokenId : '123' ,
@@ -144,14 +144,54 @@ describe('Account Events', () => {
144144
145145 sinon . assert . calledOnceWithExactly (
146146 statsd . increment ,
147- 'accountEvents.recordSecurityEvent.write.account.login'
147+ 'accountEvents.recordSecurityEvent.write.account.login' ,
148+ { clientId : 'none' , service : 'none' }
149+ ) ;
150+ } ) ;
151+
152+ it ( 'includes clientId and service tags from additionalInfo' , async ( ) => {
153+ const message = {
154+ name : 'account.login' ,
155+ uid : '000' ,
156+ ipAddr : '123.123.123.123' ,
157+ tokenId : '123' ,
158+ additionalInfo : {
159+ client_id : '5882386c6d801776' ,
160+ service : 'sync' ,
161+ } ,
162+ } ;
163+ await accountEventsManager . recordSecurityEvent ( mockDb , message ) ;
164+
165+ sinon . assert . calledOnceWithExactly (
166+ statsd . increment ,
167+ 'accountEvents.recordSecurityEvent.write.account.login' ,
168+ { clientId : '5882386c6d801776' , service : 'sync' }
169+ ) ;
170+ } ) ;
171+
172+ it ( 'uses none for missing service when clientId is present' , async ( ) => {
173+ const message = {
174+ name : 'account.login' ,
175+ uid : '000' ,
176+ ipAddr : '123.123.123.123' ,
177+ tokenId : '123' ,
178+ additionalInfo : {
179+ client_id : 'deadbeefdeadbeef' ,
180+ } ,
181+ } ;
182+ await accountEventsManager . recordSecurityEvent ( mockDb , message ) ;
183+
184+ sinon . assert . calledOnceWithExactly (
185+ statsd . increment ,
186+ 'accountEvents.recordSecurityEvent.write.account.login' ,
187+ { clientId : 'deadbeefdeadbeef' , service : 'none' }
148188 ) ;
149189 } ) ;
150190
151191 it ( 'logs and does not throw on failure' , async ( ) => {
152192 mockDb . securityEvent = sinon . stub ( ) . throws ( ) ;
153193 const message = {
154- name : 'account.login' as const ,
194+ name : 'account.login' ,
155195 uid : '000' ,
156196 ip : '123.123.123.123' ,
157197 tokenId : '123' ,
@@ -160,7 +200,29 @@ describe('Account Events', () => {
160200 expect ( addMock . called ) . toBe ( false ) ;
161201 sinon . assert . calledOnceWithExactly (
162202 statsd . increment ,
163- 'accountEvents.recordSecurityEvent.error.account.login'
203+ 'accountEvents.recordSecurityEvent.error.account.login' ,
204+ { clientId : 'none' , service : 'none' }
205+ ) ;
206+ } ) ;
207+
208+ it ( 'includes tags on error path' , async ( ) => {
209+ mockDb . securityEvent = sinon . stub ( ) . throws ( ) ;
210+ const message = {
211+ name : 'account.login' ,
212+ uid : '000' ,
213+ ipAddr : '123.123.123.123' ,
214+ tokenId : '123' ,
215+ additionalInfo : {
216+ client_id : '5882386c6d801776' ,
217+ service : 'sync' ,
218+ } ,
219+ } ;
220+ await accountEventsManager . recordSecurityEvent ( mockDb , message as any ) ;
221+
222+ sinon . assert . calledOnceWithExactly (
223+ statsd . increment ,
224+ 'accountEvents.recordSecurityEvent.error.account.login' ,
225+ { clientId : '5882386c6d801776' , service : 'sync' }
164226 ) ;
165227 } ) ;
166228 } ) ;
0 commit comments