@@ -22,6 +22,7 @@ import (
2222 "github.com/pingcap/tidb/pkg/parser/mysql"
2323 "github.com/pingcap/tidb/pkg/parser/terror"
2424 "github.com/pingcap/tidb/pkg/testkit"
25+ "github.com/pingcap/tidb/pkg/util/collate"
2526 "github.com/pingcap/tidb/pkg/util/dbterror/exeerrors"
2627 "github.com/stretchr/testify/require"
2728)
@@ -103,6 +104,23 @@ func TestGrantDBScope(t *testing.T) {
103104 require .True (t , terror .ErrorEqual (err , exeerrors .ErrWrongUsage .GenWithStackByArgs ("DB GRANT" , "NON-DB PRIVILEGES" )))
104105}
105106
107+ func TestGrantDBScopeCaseInsensitiveWithNewCollationDisabled (t * testing.T ) {
108+ oldNewCollationEnabled := collate .NewCollationEnabled ()
109+ collate .SetNewCollationEnabledForTest (false )
110+ defer collate .SetNewCollationEnabledForTest (oldNewCollationEnabled )
111+
112+ store := testkit .CreateMockStore (t )
113+ tk := testkit .NewTestKit (t , store )
114+
115+ tk .MustExec (`DROP USER IF EXISTS 'testDBCase'@'%'` )
116+ tk .MustExec (`CREATE USER 'testDBCase'@'%' IDENTIFIED BY '123'` )
117+
118+ tk .MustExec (`GRANT SELECT ON test.* TO 'testDBCase'@'%'` )
119+ tk .MustExec (`GRANT SELECT ON TEST.* TO 'testDBCase'@'%'` )
120+ tk .MustQuery (`SELECT DB, Select_priv FROM mysql.db WHERE User='testDBCase' AND Host='%' ORDER BY DB` ).
121+ Check (testkit .Rows ("test Y" ))
122+ }
123+
106124func TestGrantTableScope (t * testing.T ) {
107125 store := testkit .CreateMockStore (t )
108126
@@ -146,6 +164,25 @@ func TestGrantTableScope(t *testing.T) {
146164 "[executor:1144]Illegal GRANT/REVOKE command; please consult the manual to see which privileges can be used" )
147165}
148166
167+ func TestGrantTableScopeCaseInsensitiveWithNewCollationDisabled (t * testing.T ) {
168+ oldNewCollationEnabled := collate .NewCollationEnabled ()
169+ collate .SetNewCollationEnabledForTest (false )
170+ defer collate .SetNewCollationEnabledForTest (oldNewCollationEnabled )
171+
172+ store := testkit .CreateMockStore (t )
173+ tk := testkit .NewTestKit (t , store )
174+
175+ tk .MustExec (`DROP USER IF EXISTS 'testTblCase'@'%'` )
176+ tk .MustExec (`CREATE USER 'testTblCase'@'%' IDENTIFIED BY '123'` )
177+ tk .MustExec (`DROP TABLE IF EXISTS test.issue66867_grant` )
178+ tk .MustExec (`CREATE TABLE test.issue66867_grant(c1 int)` )
179+
180+ tk .MustExec (`GRANT SELECT ON test.issue66867_grant TO 'testTblCase'@'%'` )
181+ tk .MustExec (`GRANT SELECT ON test.ISSUE66867_GRANT TO 'testTblCase'@'%'` )
182+ tk .MustQuery (`SELECT Table_name, Table_priv FROM mysql.tables_priv WHERE User='testTblCase' AND Host='%' AND DB='test' ORDER BY Table_name` ).
183+ Check (testkit .Rows ("issue66867_grant Select" ))
184+ }
185+
149186func TestGrantColumnScope (t * testing.T ) {
150187 store := testkit .CreateMockStore (t )
151188
0 commit comments