@@ -30,6 +30,14 @@ func TestRole_Create(t *testing.T) {
3030 "member_of_groups" : "role1-group" ,
3131 },
3232 },
33+ {
34+ ExpectedToSucceed ,
35+ "role-without-groups" ,
36+ map [string ]interface {}{
37+ "username" : "user" ,
38+ "member_of_groups" : "" ,
39+ },
40+ },
3341 {
3442 FailWithLogicalError ,
3543 "role-with-invalid-ttl" ,
@@ -41,10 +49,7 @@ func TestRole_Create(t *testing.T) {
4149 {
4250 FailWithLogicalError ,
4351 "role-without-groups" ,
44- map [string ]interface {}{
45- "username" : "user" ,
46- "member_of_groups" : "" ,
47- },
52+ map [string ]interface {}{},
4853 },
4954 }
5055
@@ -63,6 +68,37 @@ func TestRole_Create(t *testing.T) {
6368 }
6469}
6570
71+ func TestRole_Create_UserScoped (t * testing.T ) {
72+ b , storage := newBackend (t )
73+
74+ roleData := map [string ]interface {}{"username" : "user" }
75+
76+ req := & logical.Request {
77+ Operation : logical .CreateOperation ,
78+ Path : "roles/test" ,
79+ Storage : storage ,
80+ Data : roleData ,
81+ }
82+ resp , err := b .HandleRequest (context .Background (), req )
83+ assertLogicalResponse (t , ExpectedToSucceed , err , resp )
84+
85+ req = & logical.Request {
86+ Operation : logical .ReadOperation ,
87+ Path : "roles/test" ,
88+ Storage : storage ,
89+ }
90+ resp , err = b .HandleRequest (context .Background (), req )
91+ assertLogicalResponse (t , ExpectedToSucceed , err , resp )
92+
93+ groups := resp .Data ["member_of_groups" ].([]string )
94+ if len (groups ) != 1 {
95+ t .Fatalf ("Expected exactly 1 group set on role, got: %v\n " , groups )
96+ }
97+ if groups [0 ] != "*" {
98+ t .Fatalf ("Expected group '*', got: %v\n " , groups )
99+ }
100+ }
101+
66102func TestRole_Update (t * testing.T ) {
67103 b , storage := newBackend (t )
68104
0 commit comments