spec/unit/berkshelf/downloader_spec.rb in berkshelf-5.6.5 vs spec/unit/berkshelf/downloader_spec.rb in berkshelf-6.0.0

- old
+ new

@@ -36,27 +36,53 @@ end let(:name) { "fake" } let(:version) { "1.0.0" } it "supports the 'opscode' location type" do + allow(source).to receive(:type) { :supermarket } allow(remote_cookbook).to receive(:location_type) { :opscode } allow(remote_cookbook).to receive(:location_path) { "http://api.opscode.com" } rest = double("community-rest") - expect(CommunityREST).to receive(:new).with("http://api.opscode.com") { rest } + expect(CommunityREST).to receive(:new).with("http://api.opscode.com", {}) { rest } expect(rest).to receive(:download).with(name, version) subject.try_download(source, name, version) end it "supports the 'supermarket' location type" do + allow(source).to receive(:type) { :supermarket } allow(remote_cookbook).to receive(:location_type) { :supermarket } allow(remote_cookbook).to receive(:location_path) { "http://api.supermarket.com" } rest = double("community-rest") - expect(CommunityREST).to receive(:new).with("http://api.supermarket.com") { rest } + expect(CommunityREST).to receive(:new).with("http://api.supermarket.com", {}) { rest } expect(rest).to receive(:download).with(name, version) subject.try_download(source, name, version) end + context "with an artifactory source" do + it "supports the 'opscode' location type" do + allow(source).to receive(:type) { :artifactory } + allow(source).to receive(:options) { {api_key: 'secret'} } + allow(remote_cookbook).to receive(:location_type) { :opscode } + allow(remote_cookbook).to receive(:location_path) { "http://artifactory/" } + rest = double("community-rest") + expect(CommunityREST).to receive(:new).with("http://artifactory/", {headers: {'X-Jfrog-Art-Api' => 'secret'}}) { rest } + expect(rest).to receive(:download).with(name, version) + subject.try_download(source, name, version) + end + + it "supports the 'supermarket' location type" do + allow(source).to receive(:type) { :artifactory } + allow(source).to receive(:options) { {api_key: 'secret'} } + allow(remote_cookbook).to receive(:location_type) { :supermarket } + allow(remote_cookbook).to receive(:location_path) { "http://artifactory/" } + rest = double("community-rest") + expect(CommunityREST).to receive(:new).with("http://artifactory/", {headers: {'X-Jfrog-Art-Api' => 'secret'}}) { rest } + expect(rest).to receive(:download).with(name, version) + subject.try_download(source, name, version) + end + end + describe "chef_server location type" do let(:chef_server_url) { "http://configured-chef-server/" } let(:ridley_client) do double(Ridley::Client, cookbook: double("cookbook", download: "fake") @@ -89,10 +115,11 @@ before do allow(Berkshelf).to receive(:config).and_return(berkshelf_config) allow(subject).to receive(:ssl_policy).and_return(ssl_policy) allow(remote_cookbook).to receive(:location_type) { :chef_server } allow(remote_cookbook).to receive(:location_path) { chef_server_url } + allow(source).to receive(:options) { {read_timeout: 30, open_timeout: 3, ssl: {verify: true, cert_store: cert_store}} } end it "uses the berkshelf config and provides a custom cert_store" do credentials = { server_url: chef_server_url, @@ -103,9 +130,47 @@ cert_store: cert_store, }, } expect(Ridley).to receive(:open).with(credentials) { ridley_client } subject.try_download(source, name, version) + end + + context "with a source option for client_name" do + before do + allow(source).to receive(:options) { {client_name: "other-client", read_timeout: 30, open_timeout: 3, ssl: {verify: true, cert_store: cert_store}} } + end + it "uses the override" do + credentials = { + server_url: chef_server_url, + client_name: "other-client", + client_key: chef_config.client_key, + ssl: { + verify: berkshelf_config.ssl.verify, + cert_store: cert_store, + }, + } + expect(Ridley).to receive(:open).with(credentials) { ridley_client } + subject.try_download(source, name, version) + end + end + + context "with a source option for client_key" do + before do + allow(source).to receive(:options) { {client_key: "other-key", read_timeout: 30, open_timeout: 3, ssl: {verify: true, cert_store: cert_store}} } + end + it "uses the override" do + credentials = { + server_url: chef_server_url, + client_name: chef_config.node_name, + client_key: "other-key", + ssl: { + verify: berkshelf_config.ssl.verify, + cert_store: cert_store, + }, + } + expect(Ridley).to receive(:open).with(credentials) { ridley_client } + subject.try_download(source, name, version) + end end end it "supports the 'file_store' location type" do skip