diff options
-rw-r--r-- | lib/chef/config.rb | 31 | ||||
-rw-r--r-- | spec/unit/config_spec.rb | 30 |
2 files changed, 60 insertions, 1 deletions
diff --git a/lib/chef/config.rb b/lib/chef/config.rb index feb7e4ea94..f8148d939e 100644 --- a/lib/chef/config.rb +++ b/lib/chef/config.rb @@ -356,7 +356,14 @@ class Chef # Path to the default CA bundle files. default :ssl_ca_path, nil - default :ssl_ca_file, nil + default(:ssl_ca_file) do + if on_windows? and embedded_path = embedded_dir + cacert_path = File.join(embedded_path, "ssl/certs/cacert.pem") + cacert_path if File.exist?(cacert_path) + else + nil + end + end # A directory that contains additional SSL certificates to trust. Any # certificates in this directory will be added to whatever CA bundle ruby @@ -507,5 +514,27 @@ class Chef # created under ENV['TMP'] otherwise tempfiles will be created in # the directory that files are going to reside. default :file_staging_uses_destdir, false + + # If installed via an omnibus installer, this gives the path to the + # "embedded" directory which contains all of the software packaged with + # omnibus. This is used to locate the cacert.pem file on windows. + def self.embedded_dir + find_embedded_dir_in(_this_file) + end + + def self.find_embedded_dir_in(path) + if File.basename(path) == "embedded" + path + elsif File.basename(path) == path + nil + else + find_embedded_dir_in(File.dirname(path)) + end + end + + # Path to this file in the current install. + def self._this_file + File.expand_path(__FILE__) + end end end diff --git a/spec/unit/config_spec.rb b/spec/unit/config_spec.rb index cb48ab5bcc..3771b853a1 100644 --- a/spec/unit/config_spec.rb +++ b/spec/unit/config_spec.rb @@ -266,6 +266,36 @@ describe Chef::Config do end end + + describe "finding the windows embedded dir" do + let(:default_config_location) { "c:/opscode/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.6.0/lib/chef/config.rb" } + let(:alternate_install_location) { "c:/my/alternate/install/place/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.6.0/lib/chef/config.rb" } + let(:non_omnibus_location) { "c:/my/dev/stuff/lib/ruby/gems/1.9.1/gems/chef-11.6.0/lib/chef/config.rb" } + + let(:default_ca_file) { "c:/opscode/chef/embedded/ssl/certs/cacert.pem" } + + it "finds the embedded dir in the default location" do + Chef::Config.stub(:_this_file).and_return(default_config_location) + Chef::Config.embedded_dir.should == "c:/opscode/chef/embedded" + end + + it "finds the embedded dir in a custom install location" do + Chef::Config.stub(:_this_file).and_return(alternate_install_location) + Chef::Config.embedded_dir.should == "c:/my/alternate/install/place/chef/embedded" + end + + it "doesn't error when not in an omnibus install" do + Chef::Config.stub(:_this_file).and_return(non_omnibus_location) + Chef::Config.embedded_dir.should be_nil + end + + it "sets the ssl_ca_cert path if the cert file is available" do + Chef::Config.stub(:_this_file).and_return(default_config_location) + Chef::Config.stub(:on_windows?).and_return(true) + File.stub(:exist?).with(default_ca_file).and_return(true) + Chef::Config.ssl_ca_file.should == default_ca_file + end + end end describe "Chef::Config[:user_home]" do |