Skip to content

Commit

Permalink
added tests for SHOW GRANTS FOR statements
Browse files Browse the repository at this point in the history
  • Loading branch information
dgolja committed May 28, 2015
1 parent 1469cc1 commit 95c0f09
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
10 changes: 9 additions & 1 deletion influxql/parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -531,6 +531,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`,
Expand Down Expand Up @@ -1219,8 +1225,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`},
Expand Down
31 changes: 31 additions & 0 deletions server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -570,6 +570,37 @@ func TestServer_NonExistingUsers(t *testing.T) {
}
}

// Ensure the server does return valid users grant data
func TestServer_GetGrantPrivileges(t *testing.T) {
c := test.NewDefaultMessagingClient()
defer c.Close()
s := OpenServer(c)
defer s.Close()

// Create some users.
s.CreateUser("susy", "pass", false)

// Grant normal user write privileges on database "bar".
s.SetPrivilege(influxql.WritePrivilege, "susy", "bar")

s.Restart()

p, err := s.UserPrivileges("susy")
if err != nil {
t.Fatalf("unexpected missing data for user")
}

if p["bar"] != influxql.WritePrivilege {
t.Fatalf("unexpected missing privilege for user")
}

_, err = s.UserPrivileges("Boby")

if err == nil {
t.Fatalf("unexpected grant user data found")
}
}

// Ensure the database can create a new retention policy.
func TestServer_CreateRetentionPolicy(t *testing.T) {
c := test.NewDefaultMessagingClient()
Expand Down

0 comments on commit 95c0f09

Please sign in to comment.