@@ -147,6 +147,7 @@ func (s *testPrivilegeSuite) TestCheckTablePrivilege(c *C) {
147
147
148
148
func (s * testPrivilegeSuite ) TestShowGrants (c * C ) {
149
149
se := newSession (c , s .store , s .dbName )
150
+ ctx , _ := se .(sessionctx.Context )
150
151
mustExec (c , se , `CREATE USER 'show'@'localhost' identified by '123';` )
151
152
mustExec (c , se , `GRANT Index ON *.* TO 'show'@'localhost';` )
152
153
mustExec (c , se , `FLUSH PRIVILEGES;` )
@@ -222,16 +223,23 @@ func (s *testPrivilegeSuite) TestShowGrants(c *C) {
222
223
`GRANT Update ON test.test TO 'show'@'localhost'` }
223
224
c .Assert (testutil .CompareUnorderedStringSlice (gs , expected ), IsTrue )
224
225
225
- // Fix a issue that empty privileges is displayed when revoke after grant.
226
- mustExec (c , se , "TRUNCATE TABLE mysql.db" )
227
- mustExec (c , se , "TRUNCATE TABLE mysql.user" )
228
- mustExec (c , se , "TRUNCATE TABLE mysql.tables_priv" )
229
- mustExec (c , se , `GRANT ALL PRIVILEGES ON ` + "`" + `te%` + "`" + `.* TO 'show'@'localhost'` )
230
- mustExec (c , se , `REVOKE ALL PRIVILEGES ON ` + "`" + `te%` + "`" + `.* FROM 'show'@'localhost'` )
226
+ // Expected behavior: Usage still exists after revoking all privileges
227
+ mustExec (c , se , `REVOKE ALL PRIVILEGES ON *.* FROM 'show'@'localhost'` )
228
+ mustExec (c , se , `REVOKE Select on test.* FROM 'show'@'localhost'` )
229
+ mustExec (c , se , `REVOKE ALL ON test1.* FROM 'show'@'localhost'` )
230
+ mustExec (c , se , `REVOKE UPDATE on test.test FROM 'show'@'localhost'` )
231
231
mustExec (c , se , `FLUSH PRIVILEGES;` )
232
232
gs , err = pc .ShowGrants (se , & auth.UserIdentity {Username : "show" , Hostname : "localhost" })
233
233
c .Assert (err , IsNil )
234
- // It should not be "GRANT ON `te%`.* to 'show'@'localhost'"
234
+ c .Assert (gs , HasLen , 1 )
235
+ c .Assert (gs [0 ], Equals , `GRANT USAGE ON *.* TO 'show'@'localhost'` )
236
+
237
+ // Usage should not exist after dropping the user
238
+ // Which we need privileges to do so!
239
+ ctx .GetSessionVars ().User = & auth.UserIdentity {Username : "root" , Hostname : "localhost" }
240
+ mustExec (c , se , `DROP USER 'show'@'localhost'` )
241
+ mustExec (c , se , `FLUSH PRIVILEGES;` )
242
+ gs , err = pc .ShowGrants (se , & auth.UserIdentity {Username : "show" , Hostname : "localhost" })
235
243
c .Assert (gs , HasLen , 0 )
236
244
237
245
}
0 commit comments