@@ -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,42 @@ 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 },
477496 },
478497 }
479498
@@ -618,7 +637,13 @@ func TestDeviceIDReuse(t *testing.T) {
618637 res := api.PerformDeviceCreationResponse {}
619638 // create a first device
620639 deviceID := util .RandomString (8 )
621- req := api.PerformDeviceCreationRequest {Localpart : "alice" , ServerName : "test" , DeviceID : & deviceID , NoDeviceListUpdate : true }
640+ req := api.PerformDeviceCreationRequest {
641+ Localpart : "alice" ,
642+ ServerName : "test" ,
643+ DeviceID : & deviceID ,
644+ NoDeviceListUpdate : true ,
645+ AccessTokenUniqueConstraintDisabled : true ,
646+ }
622647 err := intAPI .PerformDeviceCreation (ctx , & req , & res )
623648 if err != nil {
624649 t .Fatal (err )
0 commit comments