Skip to content
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
18 changes: 18 additions & 0 deletions pkg/infoschema/test/clustertablestest/cluster_tables_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -908,6 +908,24 @@ func TestMDLView(t *testing.T) {
}
}

func TestMDLViewPrivilege(t *testing.T) {
store := testkit.CreateMockStore(t)
tk := testkit.NewTestKit(t, store)
require.NoError(t, tk.Session().Auth(&auth.UserIdentity{Username: "root", Hostname: "%"}, nil, nil, nil))
tk.MustQuery("select * from mysql.tidb_mdl_view;").Check(testkit.Rows())
tk.MustExec("create user 'test'@'%' identified by '';")
require.NoError(t, tk.Session().Auth(&auth.UserIdentity{Username: "test", Hostname: "%"}, nil, nil, nil))
_, err := tk.Exec("select * from mysql.tidb_mdl_view;")
require.ErrorContains(t, err, "view lack rights")

// grant all privileges to test user.
require.NoError(t, tk.Session().Auth(&auth.UserIdentity{Username: "root", Hostname: "%"}, nil, nil, nil))
tk.MustExec("grant all privileges on *.* to 'test'@'%';")
tk.MustExec("flush privileges;")
require.NoError(t, tk.Session().Auth(&auth.UserIdentity{Username: "test", Hostname: "%"}, nil, nil, nil))
tk.MustQuery("select * from mysql.tidb_mdl_view;").Check(testkit.Rows())
}

func TestQuickBinding(t *testing.T) {
s := new(clusterTablesSuite)
s.store, s.dom = testkit.CreateMockStoreAndDomain(t)
Expand Down
2 changes: 1 addition & 1 deletion pkg/session/bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,7 @@ const (
lock_name VARCHAR(64) NOT NULL PRIMARY KEY
);`
// CreateMDLView is a view about metadata locks.
CreateMDLView = `CREATE OR REPLACE VIEW mysql.tidb_mdl_view as (
CreateMDLView = `CREATE OR REPLACE SQL SECURITY INVOKER VIEW mysql.tidb_mdl_view as (
SELECT tidb_mdl_info.job_id,
JSON_UNQUOTE(JSON_EXTRACT(cast(cast(job_meta as char) as json), "$.schema_name")) as db_name,
JSON_UNQUOTE(JSON_EXTRACT(cast(cast(job_meta as char) as json), "$.table_name")) as table_name,
Expand Down