Skip to content

Commit

Permalink
fix: add quotation marks to bucket name validation
Browse files Browse the repository at this point in the history
  • Loading branch information
AlirieGray committed Aug 5, 2020
1 parent e82f2d9 commit 827cf53
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 8 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
1. [19043](https://github.com/influxdata/influxdb/pull/19043): Enforce all influx CLI flag args are valid
1. [19188](https://github.com/influxdata/influxdb/pull/19188): Dashboard cells correctly map results when multiple queries exist
1. [19146](https://github.com/influxdata/influxdb/pull/19146): Dashboard cells and overlay use UTC as query time when toggling to UTC timezone
1. [19222](https://github.com/influxdata/influxdb/pull/19222): Bucket names may not include quotation marks

## v2.0.0-beta.15 [2020-07-23]

Expand Down
5 changes: 1 addition & 4 deletions http/bucket_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -361,10 +361,7 @@ func (b *postBucketRequest) OK() error {

// names starting with an underscore are reserved for system buckets
if err := validBucketName(b.toInfluxDB()); err != nil {
return &influxdb.Error{
Code: influxdb.EUnprocessableEntity,
Msg: err.Error(),
}
return err
}

return nil
Expand Down
13 changes: 9 additions & 4 deletions tenant/http_server_bucket.go
Original file line number Diff line number Diff line change
Expand Up @@ -313,10 +313,7 @@ func (b *postBucketRequest) OK() error {

// names starting with an underscore are reserved for system buckets
if err := validBucketName(b.toInfluxDB()); err != nil {
return &influxdb.Error{
Code: influxdb.EUnprocessableEntity,
Msg: err.Error(),
}
return err
}

return nil
Expand Down Expand Up @@ -498,5 +495,13 @@ func validBucketName(bucket *influxdb.Bucket) error {
Msg: fmt.Sprintf("bucket name %s is invalid. Buckets may not start with underscore", bucket.Name),
}
}
// quotation marks will cause queries to fail
if strings.Contains(bucket.Name, "\"") {
return &influxdb.Error{
Code: influxdb.EInvalid,
Op: "http/bucket",
Msg: fmt.Sprintf("bucket name %s is invalid. Bucket names may not include quotation marks", bucket.Name),
}
}
return nil
}
24 changes: 24 additions & 0 deletions testing/bucket_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,30 @@ func CreateBucket(
},
},
},
{
name: "create bucket with illegal quotation mark",
fields: BucketFields{
IDGenerator: mock.NewIDGenerator(bucketOneID, t),
OrgBucketIDs: mock.NewIDGenerator(bucketOneID, t),
TimeGenerator: mock.TimeGenerator{FakeValue: time.Date(2006, 5, 4, 1, 2, 3, 0, time.UTC)},
Buckets: []*influxdb.Bucket{},
Organizations: []*influxdb.Organization{},
},
args: args{
bucket: &influxdb.Bucket{
Name: "namewith\"quote",
OrgID: MustIDBase16(orgOneID),
},
},
wants: wants{
buckets: []*influxdb.Bucket{},
err: &influxdb.Error{
Code: influxdb.EInvalid,
Msg: "bucket name namewith\"quote is invalid. Bucket names may not include quotation marks",
Op: influxdb.OpCreateBucket,
},
},
},
}

for _, tt := range tests {
Expand Down

0 comments on commit 827cf53

Please sign in to comment.