Skip to content

Commit

Permalink
remove GrantPriv from AllGlobalPrivs/AllDBPrivs/AllTablePrivs (#581) (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
Lingyu Song authored and jackysp committed Dec 9, 2019
1 parent 91f36bd commit 9504797
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 3 deletions.
6 changes: 3 additions & 3 deletions mysql/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ var Col2PrivType = map[string]PrivilegeType{
}

// AllGlobalPrivs is all the privileges in global scope.
var AllGlobalPrivs = []PrivilegeType{SelectPriv, InsertPriv, UpdatePriv, DeletePriv, CreatePriv, DropPriv, ProcessPriv, GrantPriv, ReferencesPriv, AlterPriv, ShowDBPriv, SuperPriv, ExecutePriv, IndexPriv, CreateUserPriv, TriggerPriv, CreateViewPriv, ShowViewPriv, CreateRolePriv, DropRolePriv}
var AllGlobalPrivs = []PrivilegeType{SelectPriv, InsertPriv, UpdatePriv, DeletePriv, CreatePriv, DropPriv, ProcessPriv, ReferencesPriv, AlterPriv, ShowDBPriv, SuperPriv, ExecutePriv, IndexPriv, CreateUserPriv, TriggerPriv, CreateViewPriv, ShowViewPriv, CreateRolePriv, DropRolePriv}

// Priv2Str is the map for privilege to string.
var Priv2Str = map[PrivilegeType]string{
Expand Down Expand Up @@ -423,10 +423,10 @@ var SetStr2Priv = map[string]PrivilegeType{
}

// AllDBPrivs is all the privileges in database scope.
var AllDBPrivs = []PrivilegeType{SelectPriv, InsertPriv, UpdatePriv, DeletePriv, CreatePriv, DropPriv, GrantPriv, AlterPriv, ExecutePriv, IndexPriv, CreateViewPriv, ShowViewPriv}
var AllDBPrivs = []PrivilegeType{SelectPriv, InsertPriv, UpdatePriv, DeletePriv, CreatePriv, DropPriv, AlterPriv, ExecutePriv, IndexPriv, CreateViewPriv, ShowViewPriv}

// AllTablePrivs is all the privileges in table scope.
var AllTablePrivs = []PrivilegeType{SelectPriv, InsertPriv, UpdatePriv, DeletePriv, CreatePriv, DropPriv, GrantPriv, AlterPriv, IndexPriv}
var AllTablePrivs = []PrivilegeType{SelectPriv, InsertPriv, UpdatePriv, DeletePriv, CreatePriv, DropPriv, AlterPriv, IndexPriv}

// AllColumnPrivs is all the privileges in column scope.
var AllColumnPrivs = []PrivilegeType{SelectPriv, InsertPriv, UpdatePriv}
Expand Down
54 changes: 54 additions & 0 deletions mysql/const_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// Copyright 2017 PingCAP, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// See the License for the specific language governing permissions and
// limitations under the License.

package mysql

import (
"testing"

. "github.com/pingcap/check"
)

var _ = Suite(&testConstSuite{})

type testConstSuite struct{}

func TestT(t *testing.T) {
TestingT(t)
}

func (s *testConstSuite) TestPrivAllConsistency(c *C) {
// AllPriv in mysql.user columns.
for priv := PrivilegeType(CreatePriv); priv != AllPriv; priv = priv << 1 {
_, ok := Priv2UserCol[priv]
c.Assert(ok, IsTrue, Commentf("priv fail %d", priv))
}

for _, v := range AllGlobalPrivs {
_, ok := Priv2UserCol[v]
c.Assert(ok, IsTrue)
}

c.Assert(len(Priv2UserCol), Equals, len(AllGlobalPrivs)+1)

for _, v := range Priv2UserCol {
_, ok := Col2PrivType[v]
c.Assert(ok, IsTrue)
}
for _, v := range Col2PrivType {
_, ok := Priv2UserCol[v]
c.Assert(ok, IsTrue)
}

c.Assert(len(Priv2Str), Equals, len(Priv2UserCol))
}

0 comments on commit 9504797

Please sign in to comment.