Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

privilege: fix select current_role() error #15534

Merged
merged 3 commits into from
Mar 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions executor/simple_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,22 @@ func (s *testSuite3) TestDo(c *C) {
tk.MustQuery("select @a").Check(testkit.Rows("1"))
}

func (s *testSuite3) TestSetRoleAllCorner(c *C) {
// For user with no role, `SET ROLE ALL` should active
// a empty slice, rather than nil.
tk := testkit.NewTestKit(c, s.store)
tk.MustExec("create user set_role_all")
se, err := session.CreateSession4Test(s.store)
c.Check(err, IsNil)
defer se.Close()
c.Assert(se.Auth(&auth.UserIdentity{Username: "set_role_all", Hostname: "localhost"}, nil, nil), IsTrue)
ctx := context.Background()
_, err = se.Execute(ctx, `set role all`)
c.Assert(err, IsNil)
_, err = se.Execute(ctx, `select current_role`)
c.Assert(err, IsNil)
}

func (s *testSuite3) TestCreateRole(c *C) {
tk := testkit.NewTestKit(c, s.store)
tk.MustExec("create user testCreateRole;")
Expand Down
9 changes: 4 additions & 5 deletions privilege/privileges/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -1253,11 +1253,10 @@ func (p *MySQLPrivilege) getAllRoles(user, host string) []*auth.RoleIdentity {
key := user + "@" + host
edgeTable, ok := p.RoleGraph[key]
ret := make([]*auth.RoleIdentity, 0, len(edgeTable.roleList))
if !ok {
return nil
}
for _, r := range edgeTable.roleList {
ret = append(ret, r)
if ok {
for _, r := range edgeTable.roleList {
ret = append(ret, r)
}
}
return ret
}
Expand Down