mirror of
https://github.com/jnunemaker/httparty
synced 2023-03-27 23:23:07 -04:00
Rename #pem_file to simply #pem
This commit is contained in:
parent
7d92dce9a8
commit
58fd4fab71
3 changed files with 23 additions and 18 deletions
|
@ -114,10 +114,10 @@ module HTTParty
|
|||
#
|
||||
# class Foo
|
||||
# include HTTParty
|
||||
# pem_file File.read('/home/user/my.pem')
|
||||
# pem File.read('/home/user/my.pem')
|
||||
# end
|
||||
def pem_file(pem_file_contents)
|
||||
default_options[:pem_file] = pem_file_contents
|
||||
def pem(pem_contents)
|
||||
default_options[:pem] = pem_contents
|
||||
end
|
||||
|
||||
# Allows setting a custom parser for the response.
|
||||
|
|
|
@ -57,9 +57,9 @@ module HTTParty
|
|||
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])
|
||||
if options[:pem]
|
||||
http.cert = OpenSSL::X509::Certificate.new(options[:pem])
|
||||
http.key = OpenSSL::PKey::RSA.new(options[:pem])
|
||||
end
|
||||
|
||||
http
|
||||
|
|
|
@ -46,20 +46,25 @@ describe HTTParty::Request do
|
|||
request.send(:http).use_ssl?.should == true
|
||||
end
|
||||
|
||||
it "should use a PEM certificate when provided" do
|
||||
pem_file = :contents_of_pem_file
|
||||
cert = mock("OpenSSL::X509::Certificate")
|
||||
key = mock("OpenSSL::PKey::RSA")
|
||||
OpenSSL::X509::Certificate.stub(:new).with(pem_file).and_return(cert)
|
||||
OpenSSL::PKey::RSA.stub(:new).with(pem_file).and_return(key)
|
||||
context "PEM certificates" do
|
||||
before do
|
||||
OpenSSL::X509::Certificate.stub(:new)
|
||||
OpenSSL::PKey::RSA.stub(:new)
|
||||
end
|
||||
|
||||
http = mock("http", :null_object => true)
|
||||
http.should_receive(:cert=).with(cert)
|
||||
http.should_receive(:key=).with(key)
|
||||
it "should use a PEM certificate when provided" do
|
||||
@request.stub!(:uri).and_return(URI.parse("https://google.com"))
|
||||
pem = :pem_contents
|
||||
cert = mock("OpenSSL::X509::Certificate")
|
||||
key = mock("OpenSSL::PKey::RSA")
|
||||
OpenSSL::X509::Certificate.should_receive(:new).with(pem).and_return(cert)
|
||||
OpenSSL::PKey::RSA.should_receive(:new).with(pem).and_return(key)
|
||||
|
||||
Net::HTTP.stub(:new => http)
|
||||
@request.options[:pem_file] = pem_file
|
||||
@request.perform
|
||||
@request.options[:pem] = pem
|
||||
pem_http = @request.send(:http)
|
||||
pem_http.cert.should == cert
|
||||
pem_http.key.should == key
|
||||
end
|
||||
end
|
||||
|
||||
it "should use basic auth when configured" do
|
||||
|
|
Loading…
Reference in a new issue