diff options
-rw-r--r-- | spec/unit/http/ssl_policies_spec.rb | 23 |
1 files changed, 10 insertions, 13 deletions
diff --git a/spec/unit/http/ssl_policies_spec.rb b/spec/unit/http/ssl_policies_spec.rb index d665f94417..2eda19a4e2 100644 --- a/spec/unit/http/ssl_policies_spec.rb +++ b/spec/unit/http/ssl_policies_spec.rb @@ -164,20 +164,17 @@ describe "HTTP SSL Policy" do ssl_policy.set_custom_certs ssl_policy.set_custom_certs # should not raise an error end + end + + it "raises ConfigurationError with a bad cert file in the trusted_certs dir" do + ssl_policy = ssl_policy_class.new(Net::HTTP.new("example.com")) + + Dir.mktmpdir do |dir| + bad_cert_file = File.join(dir, "bad_cert_file.crt") + File.binwrite(bad_cert_file, File.read(__FILE__)) - context "with a bad cert file" do - around do |example| - bad_cert_file = File.join(Chef::Config.trusted_certs_dir, "bad_cert_file.crt") - File.write(bad_cert_file, File.read(__FILE__)) - example.run - ensure - FileUtils.rm(bad_cert_file) - end - - it "raises ConfigurationError" do - ssl_policy = ssl_policy_class.new(Net::HTTP.new("example.com")) - expect { ssl_policy.set_custom_certs }.to raise_error(Chef::Exceptions::ConfigurationError, /Error reading cert file/) - end + Chef::Config.trusted_certs_dir = dir + expect { ssl_policy.set_custom_certs }.to raise_error(Chef::Exceptions::ConfigurationError, /Error reading cert file/) end end end |