@@ -356,6 +356,67 @@ func (st *StoreTest) TestOAuthStore(t *T) {
356356	})
357357}
358358
359+ // TestOAuthStoreSupportUser tests the behavior of AccessTokens with the unique support userID. 
360+ func  (st  * StoreTest ) TestOAuthStoreSupportUser (t  * T ) {
361+ 	supportUsr  :=  st .population .NewUser ()
362+ 	supportUsr .Ids .UserId  =  ttnpb .SupportUserID 
363+ 	supportUsr .Name  =  "support" 
364+ 	supportUsr .
PrimaryEmailAddress  =  "[email protected] "  365+ 
366+ 	ses1  :=  st .population .NewUserSession (supportUsr .GetIds ())
367+ 	cli1  :=  st .population .NewClient (nil )
368+ 	cli1 .SkipAuthorization  =  true 
369+ 
370+ 	s , ok  :=  st .PrepareDB (t ).(interface  {
371+ 		Store 
372+ 		is.OAuthStore 
373+ 	})
374+ 	defer  st .DestroyDB (t , true , "users" , "accounts" , "user_sessions" , "clients" )
375+ 	if  ! ok  {
376+ 		t .Skip ("Store does not implement OAuthStore" )
377+ 	}
378+ 	defer  s .Close ()
379+ 
380+ 	var  createdAccessToken  * ttnpb.OAuthAccessToken 
381+ 
382+ 	t .Run ("CreateAccessToken" , func (t  * T ) {
383+ 		a , ctx  :=  test .New (t )
384+ 		var  err  error 
385+ 		start  :=  time .Now ().Truncate (time .Second )
386+ 
387+ 		createdAccessToken , err  =  s .CreateAccessToken (ctx , & ttnpb.OAuthAccessToken {
388+ 			UserIds :       supportUsr .GetIds (),
389+ 			UserSessionId : ses1 .GetSessionId (),
390+ 			ClientIds :     cli1 .GetIds (),
391+ 			Id :            "token_id" ,
392+ 			AccessToken :   "access_token" ,
393+ 			RefreshToken :  "refresh_token" ,
394+ 			Rights :        []ttnpb.Right {ttnpb .Right_RIGHT_ALL },
395+ 			ExpiresAt :     timestamppb .New (start .Add (5  *  time .Minute )),
396+ 		}, "" )
397+ 		if  a .So (err , should .BeNil ) &&  a .So (createdAccessToken , should .NotBeNil ) {
398+ 			a .So (createdAccessToken .UserIds , should .Resemble , supportUsr .GetIds ())
399+ 			a .So (createdAccessToken .UserSessionId , should .Equal , ses1 .GetSessionId ())
400+ 			a .So (createdAccessToken .ClientIds , should .Resemble , cli1 .GetIds ())
401+ 			a .So (createdAccessToken .Id , should .Equal , "token_id" )
402+ 			a .So (createdAccessToken .AccessToken , should .Equal , "access_token" )
403+ 			a .So (createdAccessToken .RefreshToken , should .Equal , "refresh_token" )
404+ 			a .So (createdAccessToken .Rights , should .Resemble , []ttnpb.Right {ttnpb .Right_RIGHT_ALL })
405+ 			a .So (* ttnpb .StdTime (createdAccessToken .ExpiresAt ), should .Equal , start .Add (5 * time .Minute ))
406+ 			a .So (* ttnpb .StdTime (createdAccessToken .CreatedAt ), should .HappenWithin , 5 * time .Second , start )
407+ 		}
408+ 	})
409+ 
410+ 	t .Run ("GetAccessToken" , func (t  * T ) {
411+ 		a , ctx  :=  test .New (t )
412+ 		got , err  :=  s .GetAccessToken (ctx , "token_id" )
413+ 		if  a .So (err , should .BeNil ) &&  a .So (got , should .NotBeNil ) {
414+ 			// NOTE: This should be limited due to referencing the unique support userID. 
415+ 			a .So (got .Rights , should .Resemble , ttnpb .AllReadAdminRights .GetRights ())
416+ 		}
417+ 	})
418+ }
419+ 
359420func  (st  * StoreTest ) TestOAuthStorePagination (t  * T ) {
360421	a , ctx  :=  test .New (t )
361422
0 commit comments