Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing ssl so that cert and cert_key can be manually set #49

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/httpi/auth/ssl.rb
Expand Up @@ -54,7 +54,7 @@ def verify_mode=(mode)

# Returns an <tt>OpenSSL::X509::Certificate</tt> 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.
Expand All @@ -70,7 +70,7 @@ def ca_cert

# Returns an <tt>OpenSSL::PKey::RSA</tt> 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.
Expand Down
14 changes: 14 additions & 0 deletions spec/httpi/auth/ssl_spec.rb
Expand Up @@ -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
Expand All @@ -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
Expand Down