From 57137c6e3336a3ec9c5ff65b152dfa6d46e6b5ec Mon Sep 17 00:00:00 2001 From: DanHam Date: Wed, 21 Aug 2019 13:02:42 +0100 Subject: [PATCH] Should return an error if the value of the provider key is empty --- .../vagrant-cloud/post-processor.go | 3 +++ .../vagrant-cloud/post-processor_test.go | 20 +++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/post-processor/vagrant-cloud/post-processor.go b/post-processor/vagrant-cloud/post-processor.go index 90e885ffc..e5b6afe27 100644 --- a/post-processor/vagrant-cloud/post-processor.go +++ b/post-processor/vagrant-cloud/post-processor.go @@ -273,6 +273,9 @@ func providerFromVagrantBox(boxfile string) (providerName string, err error) { if err != nil { return "", fmt.Errorf("Error parsing metadata.json file: %s", err) } + if md.ProviderName == "" { + return "", fmt.Errorf("Error: Could not determine Vagrant provider from box metadata.json file") + } break } } diff --git a/post-processor/vagrant-cloud/post-processor_test.go b/post-processor/vagrant-cloud/post-processor_test.go index 97150dad2..c63dd910e 100644 --- a/post-processor/vagrant-cloud/post-processor_test.go +++ b/post-processor/vagrant-cloud/post-processor_test.go @@ -307,6 +307,26 @@ func TestProviderFromVagrantBox_metadata_empty(t *testing.T) { t.Logf("%s", err) } +func TestProviderFromVagrantBox_metadata_provider_value_empty(t *testing.T) { + // Bad: The boxes metadata.json file 'provider' key has an empty value + files := tarFiles{ + {"foo.txt", "This is a foo file"}, + {"bar.txt", "This is a bar file"}, + {"metadata.json", `{"provider":""}`}, + } + boxfile, err := createBox(files) + if err != nil { + t.Fatalf("Error creating test box: %s", err) + } + defer os.Remove(boxfile.Name()) + + _, err = providerFromVagrantBox(boxfile.Name()) + if err == nil { + t.Fatalf("Should have error as boxes metadata.json file 'provider' key is empty") + } + t.Logf("%s", err) +} + func TestProviderFromVagrantBox_metadata_ok(t *testing.T) { // Good: The boxes metadata.json file has the 'provider' key/value pair expectedProvider := "virtualbox"