add affirmative test case for #4762

This commit is contained in:
Matthew Hooker 2017-04-04 22:08:09 -07:00
parent dba189f587
commit 3f6b5165f2
No known key found for this signature in database
GPG Key ID: 7B5F933D9CE8C6A1
2 changed files with 8 additions and 2 deletions

View File

@ -73,8 +73,8 @@ func (c *AMIConfig) Prepare(ctx *interpolate.Context) []error {
errs = append(errs, fmt.Errorf("AMIName must be between 3 and 128 characters long")) errs = append(errs, fmt.Errorf("AMIName must be between 3 and 128 characters long"))
} }
var IsValidName = regexp.MustCompile(`^[a-zA-Z().-/_]+$`).MatchString amiNameRe := regexp.MustCompile(`^[a-zA-Z().\-/_]+$`)
if !IsValidName(c.AMIName) { if !amiNameRe.MatchString(c.AMIName) {
errs = append(errs, fmt.Errorf("AMIName should only contain letters, numbers, '(', ')', '.', '-', '/' and '_'")) errs = append(errs, fmt.Errorf("AMIName should only contain letters, numbers, '(', ')', '.', '-', '/' and '_'"))
} }

View File

@ -96,4 +96,10 @@ func TestAMINameValidation(t *testing.T) {
if err := c.Prepare(nil); err == nil { if err := c.Prepare(nil); err == nil {
t.Fatal("shouldn't be able to have an ami name with invalid characters") t.Fatal("shouldn't be able to have an ami name with invalid characters")
} }
c.AMIName = "foo().-/_bar"
if err := c.Prepare(nil); err != nil {
t.Fatal("expected 'foobar' to be a valid ami name")
}
} }