Skip to content

Commit

Permalink
Merge pull request #11679 from xsellier/bugfix/11663-provider-aws-nul…
Browse files Browse the repository at this point in the history
…l-value

provider/aws: Add epsilon to the regex date validation
  • Loading branch information
grubernaut authored Feb 3, 2017
2 parents ae002bf + dbe647d commit 24c5d59
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
6 changes: 4 additions & 2 deletions builtin/providers/aws/validators.go
Original file line number Diff line number Diff line change
Expand Up @@ -641,9 +641,10 @@ func validateSecurityRuleType(v interface{}, k string) (ws []string, errors []er
func validateOnceAWeekWindowFormat(v interface{}, k string) (ws []string, errors []error) {
// valid time format is "ddd:hh24:mi"
validTimeFormat := "(sun|mon|tue|wed|thu|fri|sat):([0-1][0-9]|2[0-3]):([0-5][0-9])"
validTimeFormatConsolidated := "^(" + validTimeFormat + "-" + validTimeFormat + "|)$"

value := strings.ToLower(v.(string))
if !regexp.MustCompile(validTimeFormat + "-" + validTimeFormat).MatchString(value) {
if !regexp.MustCompile(validTimeFormatConsolidated).MatchString(value) {
errors = append(errors, fmt.Errorf(
"%q must satisfy the format of \"ddd:hh24:mi-ddd:hh24:mi\".", k))
}
Expand All @@ -653,9 +654,10 @@ func validateOnceAWeekWindowFormat(v interface{}, k string) (ws []string, errors
func validateOnceADayWindowFormat(v interface{}, k string) (ws []string, errors []error) {
// valid time format is "hh24:mi"
validTimeFormat := "([0-1][0-9]|2[0-3]):([0-5][0-9])"
validTimeFormatConsolidated := "^(" + validTimeFormat + "-" + validTimeFormat + "|)$"

value := v.(string)
if !regexp.MustCompile(validTimeFormat + "-" + validTimeFormat).MatchString(value) {
if !regexp.MustCompile(validTimeFormatConsolidated).MatchString(value) {
errors = append(errors, fmt.Errorf(
"%q must satisfy the format of \"hh24:mi-hh24:mi\".", k))
}
Expand Down
10 changes: 10 additions & 0 deletions builtin/providers/aws/validators_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1006,6 +1006,11 @@ func TestValidateOnceAWeekWindowFormat(t *testing.T) {
Value: "Sun:04:00-Sun:05:00",
ErrCount: 0,
},
{
// valid format
Value: "",
ErrCount: 0,
},
}

for _, tc := range cases {
Expand Down Expand Up @@ -1042,6 +1047,11 @@ func TestValidateOnceADayWindowFormat(t *testing.T) {
Value: "04:00-05:00",
ErrCount: 0,
},
{
// valid format
Value: "",
ErrCount: 0,
},
}

for _, tc := range cases {
Expand Down

0 comments on commit 24c5d59

Please sign in to comment.