make sure we don't try to load an iso into memory because of a user mistake

This commit is contained in:
Megan Marsh 2019-02-13 16:21:55 -08:00
parent 9fe1366eeb
commit 2a9f49a5c6
2 changed files with 15 additions and 0 deletions

View File

@ -58,6 +58,11 @@ func (c *ISOConfig) Prepare(ctx *interpolate.Context) (warnings []string, errs [
// If iso_checksum has no value use iso_checksum_url instead.
if c.ISOChecksum == "" {
if strings.HasSuffix(strings.ToLower(c.ISOChecksumURL), ".iso") {
errs = append(errs, fmt.Errorf("Error parsing checksum:"+
" .iso is not a valid checksum extension"))
return warnings, errs
}
u, err := url.Parse(c.ISOChecksumURL)
if err != nil {
errs = append(errs,

View File

@ -239,6 +239,16 @@ func TestISOConfigPrepare_ISOChecksumURL(t *testing.T) {
if i.ISOChecksum != "bar0" {
t.Fatalf("should've found \"bar0\" got: %s", i.ISOChecksum)
}
// Test that we won't try to read an iso into memory because of a user
// error
i = testISOConfig()
i.ISOChecksumURL = "file:///not_read.iso"
i.ISOChecksum = ""
warns, err = i.Prepare(nil)
if err == nil {
t.Fatalf("should have error because iso is bad filetype: %s", err)
}
}
func TestISOConfigPrepare_ISOChecksumType(t *testing.T) {