@@ -183,9 +183,13 @@ describe('/account/device', function () {
183
183
describe ( '/account/devices/notify' , function ( ) {
184
184
var config = { }
185
185
var uid = uuid . v4 ( 'binary' )
186
+ var deviceId = crypto . randomBytes ( 16 )
187
+ var mockLog = mocks . spyLog ( )
186
188
var mockRequest = mocks . mockRequest ( {
189
+ log : mockLog ,
187
190
credentials : {
188
- uid : uid . toString ( 'hex' )
191
+ uid : uid ,
192
+ deviceId : deviceId
189
193
}
190
194
} )
191
195
var pushPayload = {
@@ -253,7 +257,7 @@ describe('/account/devices/notify', function () {
253
257
assert . equal ( mockPush . pushToAllDevices . callCount , 1 , 'mockPush.pushToAllDevices was called once' )
254
258
var args = mockPush . pushToAllDevices . args [ 0 ]
255
259
assert . equal ( args . length , 3 , 'mockPush.pushToAllDevices was passed three arguments' )
256
- assert . equal ( args [ 0 ] , uid . toString ( 'hex' ) , 'first argument was the device uid' )
260
+ assert . equal ( args [ 0 ] , uid , 'first argument was the device uid' )
257
261
assert . equal ( args [ 1 ] , 'devicesNotify' , 'second argument was the devicesNotify reason' )
258
262
assert . deepEqual ( args [ 2 ] , {
259
263
data : Buffer . from ( JSON . stringify ( pushPayload ) ) ,
@@ -266,6 +270,8 @@ describe('/account/devices/notify', function () {
266
270
267
271
it ( 'specific devices' , function ( ) {
268
272
mockCustoms . checkAuthenticated . reset ( )
273
+ mockLog . activityEvent . reset ( )
274
+ mockLog . error . reset ( )
269
275
mockRequest . payload = {
270
276
to : [ 'bogusid1' , 'bogusid2' ] ,
271
277
TTL : 60 ,
@@ -284,17 +290,48 @@ describe('/account/devices/notify', function () {
284
290
assert . equal ( mockPush . pushToDevices . callCount , 1 , 'mockPush.pushToDevices was called once' )
285
291
var args = mockPush . pushToDevices . args [ 0 ]
286
292
assert . equal ( args . length , 4 , 'mockPush.pushToDevices was passed four arguments' )
287
- assert . equal ( args [ 0 ] , uid . toString ( 'hex' ) , 'first argument was the device uid' )
293
+ assert . equal ( args [ 0 ] , uid , 'first argument was the device uid' )
288
294
assert . deepEqual ( args [ 1 ] , [ 'bogusid1' , 'bogusid2' ] , 'second argument was the list of device ids' )
289
295
assert . equal ( args [ 2 ] , 'devicesNotify' , 'third argument was the devicesNotify reason' )
290
296
assert . deepEqual ( args [ 3 ] , {
291
297
data : Buffer . from ( JSON . stringify ( pushPayload ) ) ,
292
298
TTL : 60
293
299
} , 'fourth argument was the push options' )
300
+ assert . equal ( mockLog . activityEvent . callCount , 1 , 'log.activityEvent was called once' )
301
+ args = mockLog . activityEvent . args [ 0 ]
302
+ assert . equal ( args . length , 1 , 'log.activityEvent was passed one argument' )
303
+ assert . deepEqual ( args [ 0 ] , {
304
+ event : 'sync.sentTabToDevice' ,
305
+ service : 'sync' ,
306
+ userAgent : 'test user-agent' ,
307
+ uid : uid . toString ( 'hex' ) ,
308
+ device_id : deviceId . toString ( 'hex' )
309
+ } , 'event data was correct' )
310
+ assert . equal ( mockLog . error . callCount , 0 , 'log.error was not called' )
294
311
} )
295
312
} )
296
313
} )
297
314
315
+ it ( 'does not log activity event for non-send-tab-related messages' , function ( ) {
316
+ mockPush . pushToDevices . reset ( )
317
+ mockLog . activityEvent . reset ( )
318
+ mockLog . error . reset ( )
319
+ mockRequest . payload = {
320
+ to : [ 'bogusid1' , 'bogusid2' ] ,
321
+ TTL : 60 ,
322
+ payload : {
323
+ isValid : true ,
324
+ version : 1 ,
325
+ command : 'fxaccounts:password_reset'
326
+ }
327
+ }
328
+ return runTest ( route , mockRequest , function ( response ) {
329
+ assert . equal ( mockPush . pushToDevices . callCount , 1 , 'mockPush.pushToDevices was called once' )
330
+ assert . equal ( mockLog . activityEvent . callCount , 0 , 'log.activityEvent was not called' )
331
+ assert . equal ( mockLog . error . callCount , 0 , 'log.error was not called' )
332
+ } )
333
+ } )
334
+
298
335
it ( 'device driven notifications disabled' , function ( ) {
299
336
config . deviceNotificationsEnabled = false
300
337
mockRequest . payload = {
@@ -367,7 +404,7 @@ describe('/account/device/destroy', function () {
367
404
var mockDB = mocks . mockDB ( )
368
405
var mockRequest = mocks . mockRequest ( {
369
406
credentials : {
370
- uid : uid . toString ( 'hex' ) ,
407
+ uid : uid
371
408
} ,
372
409
log : mockLog ,
373
410
payload : {
@@ -406,7 +443,7 @@ describe('/account/device/destroy', function () {
406
443
assert . equal ( args [ 0 ] , 'device:delete' )
407
444
assert . equal ( args [ 1 ] , mockRequest )
408
445
var details = args [ 2 ]
409
- assert . equal ( details . uid , uid . toString ( 'hex' ) )
446
+ assert . equal ( details . uid , uid )
410
447
assert . equal ( details . id , deviceId )
411
448
assert . ok ( Date . now ( ) - details . timestamp < 100 )
412
449
} )
0 commit comments