1
0
Fork 0
mirror of https://github.com/jnunemaker/httparty synced 2023-03-27 23:23:07 -04:00

Pass contents of PEM file rather than file location

This commit is contained in:
Chris Lowis 2009-11-19 23:03:59 +00:00 committed by Sandro Turriate
parent 9109712c47
commit fb33aeabe4
3 changed files with 28 additions and 0 deletions

View file

@ -110,6 +110,16 @@ module HTTParty
default_options[:format] = f
end
# Allows setting a PEM file to be used
#
# class Foo
# include HTTParty
# pem_file File.read('/home/user/my.pem')
# end
def pem_file(pem_file_contents)
default_options[:pem_file] = pem_file_contents
end
# Allows setting a custom parser for the response.
#
# class Foo

View file

@ -56,6 +56,12 @@ module HTTParty
http.open_timeout = options[:timeout]
http.read_timeout = options[:timeout]
end
if options[:pem_file]
http.cert = OpenSSL::X509::Certificate.new(options[:pem_file])
http.key = OpenSSL::PKey::RSA.new(options[:pem_file])
end
http
end

View file

@ -46,6 +46,18 @@ describe HTTParty::Request do
request.send(:http).use_ssl?.should == true
end
it "should use a PEM certificate when provided" do
http = mock("http", :null_object => true)
http.should_receive(:cert=)
http.should_receive(:key=)
Net::HTTP.stub(:new => http)
pem_file = :contents_of_pem_file
OpenSSL::X509::Certificate.stub!(:new).with(pem_file)
OpenSSL::PKey::RSA.stub!(:new).with(pem_file)
@request.options[:pem_file] = pem_file
@request.perform
end
it "should use basic auth when configured" do
@request.options[:basic_auth] = {:username => 'foobar', :password => 'secret'}
@request.send(:setup_raw_request)