diff --git a/builder/oracle/classic/config.go b/builder/oracle/classic/config.go index a483c8e50..da3a76460 100644 --- a/builder/oracle/classic/config.go +++ b/builder/oracle/classic/config.go @@ -6,6 +6,7 @@ import ( "io/ioutil" "net/url" "os" + "regexp" "time" "github.com/hashicorp/packer/common" @@ -94,6 +95,21 @@ func NewConfig(raws ...interface{}) (*Config, error) { } } + // Object names can contain only alphanumeric characters, hyphens, underscores, and periods + reValidObject := regexp.MustCompile("^[a-zA-Z0-9-._/]+$") + 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 != "" { errs = packer.MultiErrorAppend(errs, fmt.Errorf("Only one of user_data or user_data_file can be specified.")) } else if c.AttributesFile != "" { diff --git a/builder/oracle/classic/config_test.go b/builder/oracle/classic/config_test.go index 214365731..ff6bf2a00 100644 --- a/builder/oracle/classic/config_test.go +++ b/builder/oracle/classic/config_test.go @@ -2,6 +2,8 @@ package classic import ( "testing" + + "github.com/stretchr/testify/assert" ) func testConfig() map[string]interface{} { @@ -59,3 +61,27 @@ func TestValidationsIgnoresOptional(t *testing.T) { t.Fatalf("Shouldn't care if ssh_username is missing: err: %#v", err.Error()) } } + +func TestConfigValidatesObjects(t *testing.T) { + var objectTests = []struct { + object string + valid bool + }{ + {"foo-BAR.0_9", true}, + {"%", false}, + {"Matt...?", false}, + {"/Config-thing/myuser/myimage", true}, + } + 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) + } + } + } +}