Skip to content

Commit

Permalink
Fix #447. Update username validation to only disallow %.
Browse files Browse the repository at this point in the history
  • Loading branch information
pauldix committed Apr 22, 2014
1 parent 2d982f6 commit 89aa0c6
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
12 changes: 12 additions & 0 deletions src/api/http/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -639,6 +639,18 @@ func (self *ApiSuite) TestDbUserOperations(c *C) {
defer resp.Body.Close()
c.Assert(resp.StatusCode, Equals, libhttp.StatusBadRequest)

// Fix #477 - Username should support @ character - https://github.com/influxdb/influxdb/issues/447
url = self.formatUrl("/db/db1/users?u=root&p=root")
resp, err = libhttp.Post(url, "", bytes.NewBufferString(`{"name":"paul@influxdb.com", "password": "password"}`))
c.Assert(err, IsNil)
defer resp.Body.Close()
c.Assert(resp.StatusCode, Equals, libhttp.StatusOK)
c.Assert(self.manager.ops, HasLen, 1)
c.Assert(self.manager.ops[0].operation, Equals, "db_user_add")
c.Assert(self.manager.ops[0].username, Equals, "paul@influxdb.com")
c.Assert(self.manager.ops[0].password, Equals, "password")
self.manager.ops = nil

// set and unset the db admin flag
url = self.formatUrl("/db/db1/users/dbuser?u=root&p=root")
resp, err = libhttp.Post(url, "", bytes.NewBufferString(`{"admin": true}`))
Expand Down
13 changes: 1 addition & 12 deletions src/coordinator/coordinator.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,17 +55,6 @@ type SeriesWriter interface {
Close()
}

// usernames and db names should match this regex
var VALID_NAMES *regexp.Regexp

func init() {
var err error
VALID_NAMES, err = regexp.Compile("^[a-zA-Z0-9_][a-zA-Z0-9\\._-]*$")
if err != nil {
panic(err)
}
}

func NewCoordinatorImpl(config *configuration.Configuration, raftServer ClusterConsensus, clusterConfiguration *cluster.ClusterConfiguration) *CoordinatorImpl {
coordinator := &CoordinatorImpl{
config: config,
Expand Down Expand Up @@ -910,5 +899,5 @@ func (self *CoordinatorImpl) ConnectToProtobufServers(localConnectionString stri
}

func isValidName(name string) bool {
return VALID_NAMES.MatchString(name)
return !strings.Contains(name, "%")
}

0 comments on commit 89aa0c6

Please sign in to comment.