@@ -285,6 +285,26 @@ describe('AmplitudeClient', function () {
285
285
amplitude . _getUrlParams . restore ( ) ;
286
286
} ) ;
287
287
288
+ it ( 'should reject invalid device ids that contain periods' , function ( ) {
289
+ const spyErrorWarning = sinon . spy ( utils . log , 'error' ) ;
290
+ const badDeviceId = 'bad.device.id' ;
291
+ amplitude . init ( apiKey , null , { deviceId : badDeviceId } ) ;
292
+
293
+ assert . isTrue (
294
+ spyErrorWarning . calledWith (
295
+ `Device IDs may not contain '.' characters. Value will be ignored: "${ badDeviceId } "` ,
296
+ ) ,
297
+ ) ;
298
+ assert . isTrue (
299
+ spyErrorWarning . calledWith (
300
+ `Invalid device ID rejected. Randomly generated UUID will be used instead of "${ badDeviceId } "` ,
301
+ ) ,
302
+ ) ;
303
+ assert . notEqual ( amplitude . options . deviceId , badDeviceId ) ;
304
+
305
+ spyErrorWarning . restore ( ) ;
306
+ } ) ;
307
+
288
308
it ( 'should load device id from the cookie' , function ( ) {
289
309
// deviceId and sequenceNumber not set, init should load value from localStorage
290
310
var cookieData = {
@@ -1048,6 +1068,21 @@ describe('AmplitudeClient', function () {
1048
1068
var stored = amplitude . _metadataStorage . load ( ) ;
1049
1069
assert . propertyVal ( stored , 'deviceId' , 'deviceId' ) ;
1050
1070
} ) ;
1071
+
1072
+ it ( 'should not take periods in deviceId' , function ( ) {
1073
+ const spyErrorWarning = sinon . spy ( utils . log , 'error' ) ;
1074
+ amplitude . init ( apiKey , null , { deviceId : 'fakeDeviceId' } ) ;
1075
+ const badDeviceId = 'bad.device.id' ;
1076
+ amplitude . setDeviceId ( badDeviceId ) ;
1077
+ var stored = amplitude . _metadataStorage . load ( ) ;
1078
+ assert . propertyVal ( stored , 'deviceId' , 'fakeDeviceId' ) ;
1079
+ assert . isTrue (
1080
+ spyErrorWarning . calledWith (
1081
+ `Device IDs may not contain '.' characters. Value will be ignored: "${ badDeviceId } "` ,
1082
+ ) ,
1083
+ ) ;
1084
+ spyErrorWarning . restore ( ) ;
1085
+ } ) ;
1051
1086
} ) ;
1052
1087
1053
1088
describe ( 'resetSessionId' , function ( ) {
0 commit comments