Skip to content

Commit

Permalink
This is an automated cherry-pick of pingcap#38461
Browse files Browse the repository at this point in the history
Signed-off-by: ti-chi-bot <ti-community-prow-bot@tidb.io>
  • Loading branch information
CbcWestwolf authored and ti-chi-bot committed Oct 20, 2022
1 parent 1acd0b6 commit b8f054f
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
1 change: 1 addition & 0 deletions executor/grant.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ func (e *GrantExec) Next(ctx context.Context, req *chunk.Chunk) error {
// Create internal session to start internal transaction.
isCommit := false
internalSession, err := e.getSysSession()
internalSession.GetSessionVars().User = e.ctx.GetSessionVars().User
if err != nil {
return err
}
Expand Down
34 changes: 34 additions & 0 deletions executor/grant_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -595,3 +595,37 @@ func TestNonExistTableIllegalGrant(t *testing.T) {
// Column level, not existing table, illegal privilege
tk.MustGetErrCode("grant create temporary tables (NotExistsCol) on NotExistsD29302.NotExistsT29302 to u29302;", mysql.ErrWrongUsage)
}
<<<<<<< HEAD
=======

func TestIssue34610(t *testing.T) {
store := testkit.CreateMockStore(t)
tk := testkit.NewTestKit(t, store)
tk.MustExec("DROP DATABASE IF EXISTS d1;")
tk.MustExec("CREATE DATABASE d1;")
tk.MustExec("USE d1;")
tk.MustExec("CREATE USER user_1@localhost;")
defer func() {
tk.MustExec("DROP DATABASE d1;")
tk.MustExec("DROP USER user_1@localhost;")
}()

tk.MustExec("CREATE TABLE T1(f1 INT);")
tk.MustGetErrCode("CREATE TABLE t1(f1 INT);", mysql.ErrTableExists)
tk.MustExec("GRANT SELECT ON T1 to user_1@localhost;")
tk.MustExec("GRANT SELECT ON t1 to user_1@localhost;")
}

func TestIssue38293(t *testing.T) {
store := testkit.CreateMockStore(t)
tk := testkit.NewTestKit(t, store)
tk.Session().GetSessionVars().User = &auth.UserIdentity{Username: "root", Hostname: "localhost"}
tk.MustExec("DROP USER IF EXISTS test")
tk.MustExec("CREATE USER test")
defer func() {
tk.MustExec("DROP USER test")
}()
tk.MustExec("GRANT SELECT ON `mysql`.`db` TO test")
tk.MustQuery("SELECT `Grantor` FROM `mysql`.`tables_priv` WHERE User = 'test'").Check(testkit.Rows("root@localhost"))
}
>>>>>>> 17c7bcc85e (executor: fix the missing `Grantor` when querying `mysql`.`tables_priv` (#38461))

0 comments on commit b8f054f

Please sign in to comment.