@@ -445,6 +445,8 @@ func TestAccountData(t *testing.T) {
445445func TestDevices (t * testing.T ) {
446446 ctx := context .Background ()
447447
448+ dupeAccessToken := util .RandomString (8 )
449+
448450 displayName := "testing"
449451
450452 creationTests := []struct {
@@ -455,25 +457,43 @@ func TestDevices(t *testing.T) {
455457 }{
456458 {
457459 name : "not a local user" ,
458- inputData : & api.PerformDeviceCreationRequest {Localpart : "test1" , ServerName : "notlocal" },
460+ inputData : & api.PerformDeviceCreationRequest {Localpart : "test1" , ServerName : "notlocal" , AccessTokenUniqueConstraintDisabled : true },
459461 wantErr : true ,
460462 },
461463 {
462464 name : "implicit local user" ,
463- inputData : & api.PerformDeviceCreationRequest {Localpart : "test1" , AccessToken : util .RandomString (8 ), NoDeviceListUpdate : true , DeviceDisplayName : & displayName },
465+ inputData : & api.PerformDeviceCreationRequest {Localpart : "test1" , AccessToken : util .RandomString (8 ), NoDeviceListUpdate : true , DeviceDisplayName : & displayName , AccessTokenUniqueConstraintDisabled : true },
464466 },
465467 {
466468 name : "explicit local user" ,
467- inputData : & api.PerformDeviceCreationRequest {Localpart : "test2" , ServerName : "test" , AccessToken : util .RandomString (8 ), NoDeviceListUpdate : true },
469+ inputData : & api.PerformDeviceCreationRequest {Localpart : "test2" , ServerName : "test" , AccessToken : util .RandomString (8 ), NoDeviceListUpdate : true , AccessTokenUniqueConstraintDisabled : true },
468470 },
469471 {
470472 name : "test3 second device" , // used to test deletion later
471- inputData : & api.PerformDeviceCreationRequest {Localpart : "test3" , ServerName : "test" , AccessToken : util .RandomString (8 ), NoDeviceListUpdate : true },
473+ inputData : & api.PerformDeviceCreationRequest {Localpart : "test3" , ServerName : "test" , AccessToken : util .RandomString (8 ), NoDeviceListUpdate : true , AccessTokenUniqueConstraintDisabled : true },
472474 },
473475 {
474476 name : "test3 third device" , // used to test deletion later
475477 wantNewDevID : true ,
476- inputData : & api.PerformDeviceCreationRequest {Localpart : "test3" , ServerName : "test" , AccessToken : util .RandomString (8 ), NoDeviceListUpdate : true },
478+ inputData : & api.PerformDeviceCreationRequest {Localpart : "test3" , ServerName : "test" , AccessToken : util .RandomString (8 ), NoDeviceListUpdate : true , AccessTokenUniqueConstraintDisabled : true },
479+ },
480+ {
481+ name : "dupe token - ok (unique constraint enabled)" ,
482+ inputData : & api.PerformDeviceCreationRequest {Localpart : "test3" , ServerName : "test" , AccessToken : dupeAccessToken , NoDeviceListUpdate : true , AccessTokenUniqueConstraintDisabled : false },
483+ },
484+ {
485+ name : "dupe token - not ok (unique constraint enabled)" ,
486+ inputData : & api.PerformDeviceCreationRequest {Localpart : "test3" , ServerName : "test" , AccessToken : dupeAccessToken , NoDeviceListUpdate : true , AccessTokenUniqueConstraintDisabled : false },
487+ wantErr : true ,
488+ },
489+ {
490+ name : "dupe token - ok (unique constraint disabled)" ,
491+ inputData : & api.PerformDeviceCreationRequest {Localpart : "test3" , ServerName : "test" , AccessToken : dupeAccessToken , NoDeviceListUpdate : true , AccessTokenUniqueConstraintDisabled : true },
492+ },
493+ {
494+ name : "dupe token - not ok (unique constraint disabled)" ,
495+ inputData : & api.PerformDeviceCreationRequest {Localpart : "test3" , ServerName : "test" , AccessToken : dupeAccessToken , NoDeviceListUpdate : true , AccessTokenUniqueConstraintDisabled : true },
496+ wantErr : true ,
477497 },
478498 }
479499
0 commit comments