Skip to content

Commit

Permalink
privilege: use internal session to run SET DEFAULT ROL ALL (pingcap…
Browse files Browse the repository at this point in the history
  • Loading branch information
Lingyu Song committed Mar 31, 2020
1 parent 8750363 commit b28219b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
7 changes: 6 additions & 1 deletion executor/simple.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,12 @@ func (e *SimpleExec) setDefaultRoleAll(s *ast.SetDefaultRoleStmt) error {
return ErrCannotUser.GenWithStackByArgs("SET DEFAULT ROLE", user.String())
}
}
sqlExecutor := e.ctx.(sqlexec.SQLExecutor)
restrictedCtx, err := e.getSysSession()
if err != nil {
return err
}
defer e.releaseSysSession(restrictedCtx)
sqlExecutor := restrictedCtx.(sqlexec.SQLExecutor)
if _, err := sqlExecutor.Execute(context.Background(), "begin"); err != nil {
return err
}
Expand Down
13 changes: 13 additions & 0 deletions executor/simple_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,19 @@ func (s *testSuite3) TestDefaultRole(c *C) {
tk.MustExec(dropRoleSQL)
}

func (s *testSuite3) TestSetDefaultRoleAll(c *C) {
tk := testkit.NewTestKit(c, s.store)
tk.MustExec("create user test_all;")
se, err := session.CreateSession4Test(s.store)
c.Check(err, IsNil)
defer se.Close()
c.Assert(se.Auth(&auth.UserIdentity{Username: "test_all", Hostname: "localhost"}, nil, nil), IsTrue)

ctx := context.Background()
_, err = se.Execute(ctx, "set default role all to test_all;")
c.Assert(err, IsNil)
}

func (s *testSuite3) TestUser(c *C) {
tk := testkit.NewTestKit(c, s.store)
// Make sure user test not in mysql.User.
Expand Down

0 comments on commit b28219b

Please sign in to comment.