Skip to content

Commit

Permalink
do not allow empty database name, closes #1950
Browse files Browse the repository at this point in the history
  • Loading branch information
dullgiulio committed Mar 14, 2015
1 parent 5a2b042 commit 38bb2cf
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 0 deletions.
4 changes: 4 additions & 0 deletions database.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ func (db *database) UnmarshalJSON(data []byte) error {
return err
}

if o.Name == "" {
return ErrDatabaseNameRequired
}

// Copy over properties from intermediate type.
db.name = o.Name
db.defaultRetentionPolicy = o.DefaultRetentionPolicy
Expand Down
3 changes: 3 additions & 0 deletions server.go
Original file line number Diff line number Diff line change
Expand Up @@ -747,6 +747,9 @@ func (s *Server) Databases() (a []string) {

// CreateDatabase creates a new database.
func (s *Server) CreateDatabase(name string) error {
if name == "" {
return ErrDatabaseNameRequired
}
c := &createDatabaseCommand{Name: name}
_, err := s.broadcast(createDatabaseMessageType, c)
return err
Expand Down
5 changes: 5 additions & 0 deletions server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,11 @@ func TestServer_CreateDatabase(t *testing.T) {
s := OpenServer(NewMessagingClient())
defer s.Close()

// Attempt creating empty name database.
if err := s.CreateDatabase(""); err != influxdb.ErrDatabaseNameRequired {
t.Fatal("expected error on empty database name")
}

// Create the "foo" database.
if err := s.CreateDatabase("foo"); err != nil {
t.Fatal(err)
Expand Down

0 comments on commit 38bb2cf

Please sign in to comment.