Skip to content
This repository was archived by the owner on Jan 28, 2021. It is now read-only.

Commit a006ec7

Browse files
Check permissions on CREATE VIEW statements
Signed-off-by: Alejandro García Montoro <alejandro.garciamontoro@gmail.com>
1 parent 685c869 commit a006ec7

File tree

2 files changed

+12
-11
lines changed

2 files changed

+12
-11
lines changed

engine.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ func (e *Engine) Query(
120120
case *plan.CreateIndex:
121121
typ = sql.CreateIndexProcess
122122
perm = auth.ReadPerm | auth.WritePerm
123-
case *plan.InsertInto, *plan.DeleteFrom, *plan.Update, *plan.DropIndex, *plan.UnlockTables, *plan.LockTables:
123+
case *plan.InsertInto, *plan.DeleteFrom, *plan.Update, *plan.DropIndex, *plan.UnlockTables, *plan.LockTables, *plan.CreateView:
124124
perm = auth.ReadPerm | auth.WritePerm
125125
}
126126

engine_test.go

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3144,17 +3144,18 @@ func TestReadOnly(t *testing.T) {
31443144
_, _, err := e.Query(newCtx(), `SELECT i FROM mytable`)
31453145
require.NoError(err)
31463146

3147-
_, _, err = e.Query(newCtx(), `CREATE INDEX foo ON mytable USING pilosa (i, s)`)
3148-
require.Error(err)
3149-
require.True(auth.ErrNotAuthorized.Is(err))
3150-
3151-
_, _, err = e.Query(newCtx(), `DROP INDEX foo ON mytable`)
3152-
require.Error(err)
3153-
require.True(auth.ErrNotAuthorized.Is(err))
3147+
writingQueries := []string{
3148+
`CREATE INDEX foo ON mytable USING pilosa (i, s)`,
3149+
`DROP INDEX foo ON mytable`,
3150+
`INSERT INTO mytable (i, s) VALUES(42, 'yolo')`,
3151+
`CREATE VIEW myview AS SELECT i FROM mytable`,
3152+
}
31543153

3155-
_, _, err = e.Query(newCtx(), `INSERT INTO mytable (i, s) VALUES(42, 'yolo')`)
3156-
require.Error(err)
3157-
require.True(auth.ErrNotAuthorized.Is(err))
3154+
for _, query := range writingQueries {
3155+
_, _, err = e.Query(newCtx(), query)
3156+
require.Error(err)
3157+
require.True(auth.ErrNotAuthorized.Is(err))
3158+
}
31583159
}
31593160

31603161
func TestSessionVariables(t *testing.T) {

0 commit comments

Comments
 (0)