provider/aws: improve redshift cluster validation (#12313)

* provider/aws: improve redshift cluster validation

* aws/provider: redshift cluster mixed case name should be an invalid name
This commit is contained in:
netjunki 2017-03-01 15:56:22 -08:00 committed by Paul Stack
parent c5da896d22
commit 2cfe385653
2 changed files with 7 additions and 3 deletions

View File

@ -863,9 +863,9 @@ func validateRedshiftClusterIdentifier(v interface{}, k string) (ws []string, er
func validateRedshiftClusterDbName(v interface{}, k string) (ws []string, errors []error) {
value := v.(string)
if !regexp.MustCompile(`^[0-9A-Za-z_$]+$`).MatchString(value) {
if !regexp.MustCompile(`^[0-9a-z_$]+$`).MatchString(value) {
errors = append(errors, fmt.Errorf(
"only alphanumeric characters, underscores, and dollar signs are allowed in %q", k))
"only lowercase alphanumeric characters, underscores, and dollar signs are allowed in %q", k))
}
if !regexp.MustCompile(`^[a-zA-Z_]`).MatchString(value) {
errors = append(errors, fmt.Errorf(
@ -931,6 +931,10 @@ func validateRedshiftClusterMasterPassword(v interface{}, k string) (ws []string
errors = append(errors, fmt.Errorf(
"%q must contain at least one number", k))
}
if !regexp.MustCompile(`^[^\@\/'" ]*$`).MatchString(value) {
errors = append(errors, fmt.Errorf(
"%q cannot contain [/@\"' ]", k))
}
if len(value) < 8 {
errors = append(errors, fmt.Errorf("%q must be at least 8 characters", k))
}

View File

@ -22,7 +22,6 @@ func TestValidateRedshiftClusterDbName(t *testing.T) {
"testdbname",
"test_dbname",
"testdbname123",
"TestDBname",
"testdbname$hashicorp",
"_dbname",
}
@ -44,6 +43,7 @@ func TestValidateRedshiftClusterDbName(t *testing.T) {
"slash-at-the-end/",
"",
randomString(100),
"TestDBname",
}
for _, v := range invalidNames {
_, errors := validateRedshiftClusterDbName(v, "name")