From 52f69cd91a749bc90ac9fc817c6e7a3cf4eb7a25 Mon Sep 17 00:00:00 2001 From: Matthew Hooker Date: Mon, 2 Apr 2018 11:12:07 -0700 Subject: [PATCH] Validate image name. --- builder/oracle/classic/config.go | 13 +++++++++++-- builder/oracle/classic/config_test.go | 18 ++++++++++-------- 2 files changed, 21 insertions(+), 10 deletions(-) diff --git a/builder/oracle/classic/config.go b/builder/oracle/classic/config.go index 78fb42085..da3a76460 100644 --- a/builder/oracle/classic/config.go +++ b/builder/oracle/classic/config.go @@ -97,8 +97,17 @@ func NewConfig(raws ...interface{}) (*Config, error) { // Object names can contain only alphanumeric characters, hyphens, underscores, and periods reValidObject := regexp.MustCompile("^[a-zA-Z0-9-._/]+$") - if !reValidObject.MatchString(c.DestImageList) { - errs = packer.MultiErrorAppend(errs, fmt.Errorf("dest_image_list can contain only alphanumeric characters, hyphens, underscores, and periods.")) + var objectValidation = []struct { + name string + value string + }{ + {"dest_image_list", c.DestImageList}, + {"image_name", c.ImageName}, + } + for _, ov := range objectValidation { + if !reValidObject.MatchString(ov.value) { + errs = packer.MultiErrorAppend(errs, fmt.Errorf("%s can contain only alphanumeric characters, hyphens, underscores, and periods.", ov.name)) + } } if c.Attributes != "" && c.AttributesFile != "" { diff --git a/builder/oracle/classic/config_test.go b/builder/oracle/classic/config_test.go index 7351af0d3..ff6bf2a00 100644 --- a/builder/oracle/classic/config_test.go +++ b/builder/oracle/classic/config_test.go @@ -72,14 +72,16 @@ func TestConfigValidatesObjects(t *testing.T) { {"Matt...?", false}, {"/Config-thing/myuser/myimage", true}, } - for _, tt := range objectTests { - tc := testConfig() - tc["dest_image_list"] = tt.object - _, err := NewConfig(tc) - if tt.valid { - assert.NoError(t, err, tt.object) - } else { - assert.Error(t, err, tt.object) + for _, s := range []string{"dest_image_list", "image_name"} { + for _, tt := range objectTests { + tc := testConfig() + tc[s] = tt.object + _, err := NewConfig(tc) + if tt.valid { + assert.NoError(t, err, tt.object) + } else { + assert.Error(t, err, tt.object) + } } } }