added tests for SHOW GRANTS FOR statements

pull/2650/head
Dejan Golja 2015-05-24 23:02:42 +10:00
parent f133ceb350
commit 000d6b8b0b
3 changed files with 67 additions and 2 deletions

View File

@ -2,7 +2,7 @@
### Features
- [2650](https://github.com/influxdb/influxdb/pull/2650): Add SHOW GRANTS FOR USER statement. Thanks @n1tr0g
- [2650](https://github.com/influxdb/influxdb/pull/2650): Add SHOW GRANTS FOR USER statement. Thanks @n1tr0g.
### Bugfixes
@ -55,6 +55,30 @@
- [2865](https://github.com/influxdb/influxdb/pull/2865) -- Return an empty set of results if database does not exist in shard metadata.
### Features
- [2858](https://github.com/influxdb/influxdb/pull/2858): Support setting openTSDB write consistency.
## v0.9.0-rc32 [2015-06-07]
### Release Notes
This released introduced an updated write path and clustering design. The data format has also changed, so you'll need to wipe out your data to upgrade from RC31. There should be no other data changes before v0.9.0 is released.
### Features
- [#1997](https://github.com/influxdb/influxdb/pull/1997): Update SELECT * to return tag values.
- [#2599](https://github.com/influxdb/influxdb/issues/2599): Add "epoch" URL param and return JSON time values as epoch instead of date strings.
- [#2682](https://github.com/influxdb/influxdb/issues/2682): Adding pr checklist to CONTRIBUTING.md
- [#2683](https://github.com/influxdb/influxdb/issues/2683): Add batching support to Graphite inputs.
- [#2687](https://github.com/influxdb/influxdb/issues/2687): Add batching support to Collectd inputs.
- [#2696](https://github.com/influxdb/influxdb/pull/2696): Add line protocol. This is now the preferred way to write data.
- [#2751](https://github.com/influxdb/influxdb/pull/2751): Add UDP input. UDP only supports the line protocol now.
- [#2684](https://github.com/influxdb/influxdb/pull/2684): Include client timeout configuration. Thanks @vladlopes!
### Bugfixes
- [#2776](https://github.com/influxdb/influxdb/issues/2776): Re-implement retention policy enforcement.
- [#2635](https://github.com/influxdb/influxdb/issues/2635): Fix querying against boolean field in WHERE clause.
- [#2644](https://github.com/influxdb/influxdb/issues/2644): Make SHOW queries work with FROM /<regex>/.
- [#2501](https://github.com/influxdb/influxdb/issues/2501): Name the FlagSet for the shell and add a version flag. Thanks @neonstalwart
- [#2647](https://github.com/influxdb/influxdb/issues/2647): Fixes typos in sample config file - thanks @claws!
## v0.9.0-rc31 [2015-05-21]

View File

@ -534,6 +534,12 @@ func TestParser_ParseStatement(t *testing.T) {
stmt: &influxql.ShowServersStatement{},
},
// SHOW GRANTS
{
s: `SHOW GRANTS FOR jdoe`,
stmt: &influxql.ShowGrantsForUserStatement{Name: "jdoe"},
},
// SHOW DATABASES
{
s: `SHOW DATABASES`,
@ -1228,8 +1234,10 @@ func TestParser_ParseStatement(t *testing.T) {
{s: `SHOW CONTINUOUS`, err: `found EOF, expected QUERIES at line 1, char 17`},
{s: `SHOW RETENTION`, err: `found EOF, expected POLICIES at line 1, char 16`},
{s: `SHOW RETENTION POLICIES`, err: `found EOF, expected identifier at line 1, char 25`},
{s: `SHOW FOO`, err: `found FOO, expected CONTINUOUS, DATABASES, FIELD, MEASUREMENTS, RETENTION, SERIES, SERVERS, TAG, USERS at line 1, char 6`},
{s: `SHOW FOO`, err: `found FOO, expected CONTINUOUS, DATABASES, FIELD, GRANTS, MEASUREMENTS, RETENTION, SERIES, SERVERS, TAG, USERS at line 1, char 6`},
{s: `SHOW STATS ON`, err: `found EOF, expected string at line 1, char 15`},
{s: `SHOW GRANTS`, err: `found EOF, expected FOR at line 1, char 13`},
{s: `SHOW GRANTS FOR`, err: `found EOF, expected identifier at line 1, char 17`},
{s: `DROP CONTINUOUS`, err: `found EOF, expected QUERY at line 1, char 17`},
{s: `DROP CONTINUOUS QUERY`, err: `found EOF, expected identifier at line 1, char 23`},
{s: `DROP CONTINUOUS QUERY myquery`, err: `found EOF, expected ON at line 1, char 31`},

View File

@ -83,6 +83,34 @@ func TestStatementExecutor_ExecuteStatement_ShowDatabases_Err(t *testing.T) {
}
}
// Ensure a SHOW GRANTS FOR statement can be executed.
func TestStatementExecutor_ExecuteStatement_ShowGrantsFor(t *testing.T) {
e := NewStatementExecutor()
e.Store.UserPrivilegesFn = func(username string) (map[string]influxql.Privilege, error) {
if username != "dejan" {
t.Fatalf("unexpected username: %s", username)
}
return map[string]influxql.Privilege{
"dejan": influxql.ReadPrivilege,
"golja": influxql.WritePrivilege,
}, nil
}
if res := e.ExecuteStatement(influxql.MustParseStatement(`SHOW GRANTS FOR dejan`)); res.Err != nil {
t.Fatal(res.Err)
} else if !reflect.DeepEqual(res.Series, influxql.Rows{
{
Columns: []string{"database", "privilege"},
Values: [][]interface{}{
{"dejan", "READ"},
{"golja", "WRITE"},
},
},
}) {
t.Fatalf("unexpected rows: %s", spew.Sdump(res.Series))
}
}
// Ensure a SHOW SERVERS statement can be executed.
func TestStatementExecutor_ExecuteStatement_ShowServers(t *testing.T) {
e := NewStatementExecutor()
@ -701,6 +729,7 @@ type StatementExecutorStore struct {
UpdateUserFn func(name, password string) error
DropUserFn func(name string) error
SetPrivilegeFn func(username, database string, p influxql.Privilege) error
UserPrivilegesFn func(username string) (map[string]influxql.Privilege, error)
ContinuousQueriesFn func() ([]meta.ContinuousQueryInfo, error)
CreateContinuousQueryFn func(database, name, query string) error
DropContinuousQueryFn func(database, name string) error
@ -766,6 +795,10 @@ func (s *StatementExecutorStore) SetPrivilege(username, database string, p influ
return s.SetPrivilegeFn(username, database, p)
}
func (s *StatementExecutorStore) UserPrivileges(username string) (map[string]influxql.Privilege, error) {
return s.UserPrivilegesFn(username)
}
func (s *StatementExecutorStore) ContinuousQueries() ([]meta.ContinuousQueryInfo, error) {
return s.ContinuousQueriesFn()
}