Merge pull request #11679 from xsellier/bugfix/11663-provider-aws-null-value

provider/aws: Add epsilon to the regex date validation
This commit is contained in:
Jake Champlin 2017-02-03 14:27:04 -05:00 committed by GitHub
commit 24c5d59f5c
2 changed files with 14 additions and 2 deletions

View File

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

View File

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