diff --git a/provisioner/chef-solo/provisioner.go b/provisioner/chef-solo/provisioner.go index 7bf8da23d..2a9a08522 100644 --- a/provisioner/chef-solo/provisioner.go +++ b/provisioner/chef-solo/provisioner.go @@ -257,7 +257,7 @@ func (p *Provisioner) Provision(ui packer.Ui, comm packer.Communicator) error { } } - encryptedDataBagSecret := "" + encryptedDataBagSecretPath := "" if p.config.EncryptedDataBagSecretPath != "" { encryptedDataBagSecretPath = fmt.Sprintf("%s/encrypted_data_bag_secret", p.config.StagingDir) if err := p.uploadFile(ui, comm, encryptedDataBagSecretPath, p.config.EncryptedDataBagSecretPath); err != nil { diff --git a/provisioner/chef-solo/provisioner_test.go b/provisioner/chef-solo/provisioner_test.go index 46da3c465..f7094103e 100644 --- a/provisioner/chef-solo/provisioner_test.go +++ b/provisioner/chef-solo/provisioner_test.go @@ -155,6 +155,49 @@ func TestProvisionerPrepare_dataBagsPath(t *testing.T) { } } +func TestProvisionerPrepare_encryptedDataBagSecretPath(t *testing.T) { + var err error + var p Provisioner + + // Test no config template + config := testConfig() + delete(config, "encrypted_data_bag_secret_path") + err = p.Prepare(config) + if err != nil { + t.Fatalf("err: %s", err) + } + + // Test with a file + tf, err := ioutil.TempFile("", "packer") + if err != nil { + t.Fatalf("err: %s", err) + } + defer os.Remove(tf.Name()) + + config = testConfig() + config["encrypted_data_bag_secret_path"] = tf.Name() + p = Provisioner{} + err = p.Prepare(config) + if err != nil { + t.Fatalf("err: %s", err) + } + + // Test with a directory + td, err := ioutil.TempDir("", "packer") + if err != nil { + t.Fatalf("err: %s", err) + } + defer os.RemoveAll(td) + + config = testConfig() + config["encrypted_data_bag_secret_path"] = td + p = Provisioner{} + err = p.Prepare(config) + if err == nil { + t.Fatal("should have err") + } +} + func TestProvisionerPrepare_environmentsPath(t *testing.T) { var p Provisioner