diff options
author | Tim Smith <tsmith@chef.io> | 2019-03-04 10:43:41 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-03-04 10:43:41 -0800 |
commit | 3bd619d0a34a6262dac45153b4f6e3187552702e (patch) | |
tree | 5e75d6404d265ded2bc03ee5acf6c0c985af32ca | |
parent | 9eb88a0d67da2449fc7c6d5df3a5bcc8ffd7afe2 (diff) | |
parent | 6e1b0e04a2bac0749c88f8044a97eaf40cf4c0e6 (diff) | |
download | chef-3bd619d0a34a6262dac45153b4f6e3187552702e.tar.gz |
Merge pull request #8263 from chef/choco_14
chocolatey_package: use provided options when determing available options to allow using private sources
-rw-r--r-- | lib/chef/provider/package/chocolatey.rb | 2 | ||||
-rw-r--r-- | spec/unit/provider/package/chocolatey_spec.rb | 31 |
2 files changed, 32 insertions, 1 deletions
diff --git a/lib/chef/provider/package/chocolatey.rb b/lib/chef/provider/package/chocolatey.rb index 4c35d13a07..f9e5027097 100644 --- a/lib/chef/provider/package/chocolatey.rb +++ b/lib/chef/provider/package/chocolatey.rb @@ -236,6 +236,8 @@ EOS begin cmd = [ "list -r #{pkg}" ] cmd.push( "-source #{new_resource.source}" ) if new_resource.source + cmd.push( new_resource.options ) if new_resource.options + raw = parse_list_output(*cmd) raw.keys.each_with_object({}) do |name, available| available[name] = desired_name_versions[name] || raw[name] diff --git a/spec/unit/provider/package/chocolatey_spec.rb b/spec/unit/provider/package/chocolatey_spec.rb index 48f8a562de..ac800212d8 100644 --- a/spec/unit/provider/package/chocolatey_spec.rb +++ b/spec/unit/provider/package/chocolatey_spec.rb @@ -282,7 +282,7 @@ describe Chef::Provider::Package::Chocolatey do end it "should pass options into the install command" do - allow_remote_list(["git"]) + allow_remote_list(["git"], " -force") new_resource.options("-force") provider.load_current_resource expect(provider).to receive(:shell_out_compacted!).with("#{choco_exe} install -y -force git", { returns: [0], timeout: timeout }).and_return(double) @@ -313,6 +313,35 @@ describe Chef::Provider::Package::Chocolatey do expect { provider.run_action(:install) }.to raise_error(Chef::Exceptions::Package) end end + + context "private source" do + it "installing a package without auth options throws an error" do + allow_remote_list(["package-without-auth"], " -source auth_source") + new_resource.package_name("package-without-auth") + new_resource.source("auth_source") + provider.load_current_resource + expect { provider.run_action(:install) }.to raise_error(Chef::Exceptions::Package) + end + + it "installing a package with invalid credentials throws an error" do + allow_remote_list(["package-invalid-auth"], " -source auth_source -u user -p password") + new_resource.package_name("package-invalid-auth") + new_resource.source("auth_source") + new_resource.options("-u user -p password") + provider.load_current_resource + expect { provider.run_action(:install) }.to raise_error(Chef::Exceptions::Package) + end + + it "installing a package with valid credentials" do + allow_remote_list(["git"], " -source auth_source -u user -p password") + new_resource.source("auth_source") + new_resource.options("-u user -p password") + provider.load_current_resource + expect(provider).to receive(:shell_out_compacted!).with("#{choco_exe} install -y -u user -p password -source auth_source git", { returns: [0], timeout: timeout }).and_return(double) + provider.run_action(:install) + expect(new_resource).to be_updated_by_last_action + end + end end describe "#action_upgrade" do |