Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions lib/httparty.rb
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,11 @@ def pkcs12(p12_contents, password)
default_options[:p12_password] = password
end

# Allow using a full certificate chain (http.extra_chain_cert)
def extra_chain_cert(value = false)
default_options[:extra_chain_cert] = value
end

# Override the way query strings are normalized.
# Helpful for overriding the default rails normalization of Array queries.
#
Expand Down
6 changes: 6 additions & 0 deletions lib/httparty/connection_adapter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,12 @@ def attach_ssl_certificates(http, options)
if options[:ssl_version] && http.respond_to?(:ssl_version=)
http.ssl_version = options[:ssl_version]
end

# Include full certificate chain
# Only Ruby 3.0+
if options[:extra_chain_cert] && options[:p12] && http.respond_to?(:extra_chain_cert=)
http.extra_chain_cert = [p12.certificate] + p12.ca_certs
end
end
end
end
Expand Down
18 changes: 18 additions & 0 deletions spec/httparty/connection_adapter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -628,6 +628,24 @@
expect(subject.verify_mode).to eq(OpenSSL::SSL::VERIFY_NONE)
end
end

context "when using extra_chain_cert and p12" do
let(:options) { { p12: p12, p12_password: "password", extra_chain_cert: true } }

before { allow(pkcs12).to receive(:ca_certs).and_return([double("OpenSSL::X509::Certificate")]) }

it "does not set extra_chain_cert on unsupported ruby versions" do
if !(subject.respond_to?(:extra_chain_cert=))
expect(subject).to_not receive(:extra_chain_cert=)
end
end

it "sets extra_chain_cert on http object in Ruby 3.0+" do
if subject.respond_to?(:extra_chain_cert=)
expect(subject.extra_chain_cert).to eq([cert] + pkcs12.ca_certs)
end
end
end
end

context "when scheme is not https" do
Expand Down
7 changes: 7 additions & 0 deletions spec/httparty_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,13 @@
end
end

describe "extra_chain_cert" do
it 'should set the extra_chain_cert option' do
@klass.extra_chain_cert true
expect(@klass.default_options[:extra_chain_cert]).to eq(true)
end
end

describe 'ssl_version' do
it 'should set the ssl_version content' do
@klass.ssl_version :SSLv3
Expand Down