Skip to content

Commit

Permalink
privilege: fix compatibility of DBIsVisible (#14862) (#14939)
Browse files Browse the repository at this point in the history
  • Loading branch information
sre-bot authored Mar 14, 2020
1 parent 9855c8f commit 7026c86
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
2 changes: 1 addition & 1 deletion privilege/privileges/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ var (
columnPrivMask = computePrivMask(mysql.AllColumnPrivs)
)

const globalDBVisible = mysql.CreatePriv | mysql.SelectPriv | mysql.InsertPriv | mysql.UpdatePriv | mysql.DeletePriv | mysql.ShowDBPriv | mysql.DropPriv | mysql.AlterPriv | mysql.IndexPriv | mysql.CreateViewPriv | mysql.ShowViewPriv | mysql.GrantPriv
const globalDBVisible = mysql.CreatePriv | mysql.SelectPriv | mysql.InsertPriv | mysql.UpdatePriv | mysql.DeletePriv | mysql.ShowDBPriv | mysql.DropPriv | mysql.AlterPriv | mysql.IndexPriv | mysql.CreateViewPriv | mysql.ShowViewPriv | mysql.GrantPriv | mysql.TriggerPriv | mysql.ReferencesPriv | mysql.ExecutePriv

func computePrivMask(privs []mysql.PrivilegeType) mysql.PrivilegeType {
var mask mysql.PrivilegeType
Expand Down
21 changes: 21 additions & 0 deletions privilege/privileges/cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -493,4 +493,25 @@ func (s *testCacheSuite) TestDBIsVisible(c *C) {
isVisible = p.DBIsVisible("testvisdb6", "%", "visdb")
c.Assert(isVisible, IsTrue)
mustExec(c, se, "TRUNCATE TABLE mysql.user")

mustExec(c, se, `INSERT INTO mysql.user (Host, User, Trigger_priv) VALUES ("%", "testvisdb7", "Y")`)
err = p.LoadUserTable(se)
c.Assert(err, IsNil)
isVisible = p.DBIsVisible("testvisdb7", "%", "visdb")
c.Assert(isVisible, IsTrue)
mustExec(c, se, "TRUNCATE TABLE mysql.user")

mustExec(c, se, `INSERT INTO mysql.user (Host, User, References_priv) VALUES ("%", "testvisdb8", "Y")`)
err = p.LoadUserTable(se)
c.Assert(err, IsNil)
isVisible = p.DBIsVisible("testvisdb8", "%", "visdb")
c.Assert(isVisible, IsTrue)
mustExec(c, se, "TRUNCATE TABLE mysql.user")

mustExec(c, se, `INSERT INTO mysql.user (Host, User, Execute_priv) VALUES ("%", "testvisdb9", "Y")`)
err = p.LoadUserTable(se)
c.Assert(err, IsNil)
isVisible = p.DBIsVisible("testvisdb9", "%", "visdb")
c.Assert(isVisible, IsTrue)
mustExec(c, se, "TRUNCATE TABLE mysql.user")
}

0 comments on commit 7026c86

Please sign in to comment.