@@ -498,6 +498,38 @@ func TestSessionAPI(t *testing.T) {
498
498
499
499
}
500
500
501
+ func TestSessionResponseWithRoleChannels (t * testing.T ) {
502
+ // The /db/_session endpoint only returns info about the default collection
503
+ rt := NewRestTesterDefaultCollection (t , nil )
504
+ defer rt .Close ()
505
+
506
+ // create session test users
507
+ response := rt .SendAdminRequest ("POST" , "/db/_user/" , `{"name":"user1", "password":"1234", "admin_channels":["userChan1"], "admin_roles":["role1"]}` )
508
+ RequireStatus (t , response , 201 )
509
+
510
+ // create role for user with a channel
511
+ response = rt .SendAdminRequest ("POST" , "/db/_role/" , `{"name":"role1", "admin_channels":["roleChan1"]}` )
512
+ RequireStatus (t , response , 201 )
513
+
514
+ // create a session for the user
515
+ response = rt .SendRequest ("POST" , "/db/_session" , `{"name":"user1", "password":"1234"}` )
516
+ RequireStatus (t , response , 200 )
517
+
518
+ var body struct {
519
+ UserCtx struct {
520
+ Channels map [string ]uint64 `json:"channels"`
521
+ } `json:"userCtx"`
522
+ }
523
+ require .NoError (t , base .JSONUnmarshal (response .Body .Bytes (), & body ))
524
+
525
+ // Check that the response contains userCtx with channels populated from the role
526
+ require .NotNil (t , body .UserCtx .Channels )
527
+ require .Equal (t , 3 , len (body .UserCtx .Channels ))
528
+ assert .Contains (t , body .UserCtx .Channels , "!" )
529
+ assert .Contains (t , body .UserCtx .Channels , "userChan1" )
530
+ assert .Contains (t , body .UserCtx .Channels , "roleChan1" )
531
+ }
532
+
501
533
func TestSessionPasswordInvalidation (t * testing.T ) {
502
534
testCases := []struct {
503
535
name string
0 commit comments