From b86efe7604e11c7bd4fcb54712e0953d199b0b3d Mon Sep 17 00:00:00 2001 From: Ryan Hartje Date: Thu, 7 May 2020 18:08:52 -0500 Subject: [PATCH] Vbox Checksum Bugfix (#9101) * attempting to repro github issue 9049 * update vbox ovf configtest to table test for mixedcase bug --- builder/virtualbox/ovf/config.go | 2 -- builder/virtualbox/ovf/config_test.go | 37 +++++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 2 deletions(-) diff --git a/builder/virtualbox/ovf/config.go b/builder/virtualbox/ovf/config.go index f0fd2fb9e..63d8f28bb 100644 --- a/builder/virtualbox/ovf/config.go +++ b/builder/virtualbox/ovf/config.go @@ -155,8 +155,6 @@ func (c *Config) Prepare(raws ...interface{}) ([]string, error) { errs = packer.MultiErrorAppend(errs, c.GuestAdditionsConfig.Prepare(&c.ctx)...) c.ChecksumType = strings.ToLower(c.ChecksumType) - c.Checksum = strings.ToLower(c.Checksum) - if c.SourcePath == "" { errs = packer.MultiErrorAppend(errs, fmt.Errorf("source_path is required")) } diff --git a/builder/virtualbox/ovf/config_test.go b/builder/virtualbox/ovf/config_test.go index f00d5bdfc..3adf15c5f 100644 --- a/builder/virtualbox/ovf/config_test.go +++ b/builder/virtualbox/ovf/config_test.go @@ -110,3 +110,40 @@ func TestNewConfig_shutdown_timeout(t *testing.T) { t.Fatalf("bad: %s", err) } } + +// TestChecksumFileNameMixedCaseBug reproduces Github issue #9049: +// https://github.com/hashicorp/packer/issues/9049 +func TestChecksumFileNameMixedCaseBug(t *testing.T) { + tt := []struct { + Name string + ChecksumPath string + }{ + {"Lowercase", "/tmp/random/file.md5"}, + {"MiXeDcAsE", "/tmp/RaNdOm/FiLe.Md5"}, + } + + for _, tc := range tt { + + cfg := testConfig(t) + cfg["source_path"] = "bug.ovf" + cfg["checksum_type"] = "file" + cfg["checksum"] = tc.ChecksumPath + cfg["type"] = "virtualbox-ovf" + cfg["guest_additions_mode"] = "disable" + cfg["headless"] = false + + var c Config + warns, err := c.Prepare(cfg) + if err != nil { + t.Errorf("config failed to Prepare, %s", err.Error()) + } + + if len(warns) != 0 { + t.Errorf("Encountered warnings during config preparation: %s", warns) + } + + if c.Checksum != tc.ChecksumPath { + t.Errorf("%s test failed, Checksum and ChecksumPath are expected to be equal, expected: %s, got: %s", tc.Name, tc.ChecksumPath, c.Checksum) + } + } +}