Cloud 1475 (#2371)

* working on incorporating regex logic

* Implemented a validation check for database name with given rules in doc within controller

* fixing tests to pass

* reflecting changes to match docs

* fixed tests further, hopefully

* for sure fixed integration tests, and moved validation check

* integration tests passed, go test now will pass

* fixed name size to 230 due to previous commit acknowledgement

* fixed field test negative validations

* added missing comma
This commit is contained in:
David Kagan 2023-04-07 15:08:07 -04:00 committed by GitHub
parent 7f75193cf2
commit 24a45bc30d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 8 additions and 3 deletions

View file

@ -28,7 +28,7 @@ func NewErrDatabaseIDInvalid(databaseID dax.DatabaseID) error {
func NewErrDatabaseNameInvalid(databaseName dax.DatabaseName) error {
return errors.New(
ErrCodeDatabaseNameInvalid,
fmt.Sprintf("database name '%s' is invalid", databaseName),
fmt.Sprintf("invalid database name %s", databaseName),
)
}

View file

@ -7,6 +7,7 @@ import (
"github.com/pkg/errors"
featurebase "github.com/featurebasedb/featurebase/v3"
"github.com/featurebasedb/featurebase/v3/dax"
"github.com/featurebasedb/featurebase/v3/dax/controller/schemar"
"github.com/featurebasedb/featurebase/v3/dax/models"
@ -34,8 +35,8 @@ func (s *Schemar) CreateDatabase(tx dax.Transaction, qdb *dax.QualifiedDatabase)
return schemar.NewErrDatabaseIDInvalid(qdb.ID)
}
// Ensure the database name is not blank.
if qdb.Name == "" {
// Sanitizing database name
if err := featurebase.ValidateName(string(qdb.Name)); err != nil {
return schemar.NewErrDatabaseNameInvalid(qdb.Name)
}

View file

@ -135,6 +135,10 @@ func newPreconditionFailedError(err error) PreconditionFailedError {
}
// Regular expression to validate index and field names.
// The lowest limitation I've seen on any filesystem we care about is 255
// characters. 230 leaves enough space that an index or field could be
// backed up and have a timestamp and file extension appended while
// still allowing for much longer index and field names. --Jaffee
var nameRegexp = regexp.MustCompile(`^[a-z][a-z0-9Θ_-]{0,229}$`)
// TimeFormat is the go-style time format used to parse string dates.