From 8833c32f486dfc3a905f339a97e4cf423901ecbd Mon Sep 17 00:00:00 2001 From: mwagg Date: Thu, 8 Mar 2012 18:03:49 +0000 Subject: [PATCH] Fixing ssl so that manually setting the cert and cert_key works --- lib/httpi/auth/ssl.rb | 4 ++-- spec/httpi/auth/ssl_spec.rb | 14 ++++++++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/lib/httpi/auth/ssl.rb b/lib/httpi/auth/ssl.rb index ce410fb..f92c5c0 100644 --- a/lib/httpi/auth/ssl.rb +++ b/lib/httpi/auth/ssl.rb @@ -54,7 +54,7 @@ def verify_mode=(mode) # Returns an OpenSSL::X509::Certificate for the +cert_file+. def cert - @cert ||= OpenSSL::X509::Certificate.new File.read(cert_file) if cert_file + @cert ||= (OpenSSL::X509::Certificate.new File.read(cert_file) if cert_file) end # Sets the +OpenSSL+ certificate. @@ -70,7 +70,7 @@ def ca_cert # Returns an OpenSSL::PKey::RSA for the +cert_key_file+. def cert_key - @cert_key ||= OpenSSL::PKey::RSA.new(File.read(cert_key_file), cert_key_password) if cert_key_file + @cert_key ||= (OpenSSL::PKey::RSA.new(File.read(cert_key_file), cert_key_password) if cert_key_file) end # Sets the +OpenSSL+ certificate key. diff --git a/spec/httpi/auth/ssl_spec.rb b/spec/httpi/auth/ssl_spec.rb index acb4310..d7169fd 100644 --- a/spec/httpi/auth/ssl_spec.rb +++ b/spec/httpi/auth/ssl_spec.rb @@ -66,6 +66,13 @@ ssl = HTTPI::Auth::SSL.new ssl.cert.should be_nil end + + it "returns the explicitly given certificate if set" do + ssl = HTTPI::Auth::SSL.new + cert = OpenSSL::X509::Certificate.new + ssl.cert = cert + ssl.cert.should == cert + end end describe "#cert_key" do @@ -77,6 +84,13 @@ ssl = HTTPI::Auth::SSL.new ssl.cert_key.should be_nil end + + it "returns the explicitly given key if set" do + ssl = HTTPI::Auth::SSL.new + key = OpenSSL::PKey::RSA.new + ssl.cert_key = key + ssl.cert_key.should == key + end end describe "#ca_cert" do