Skip to content

Commit

Permalink
Rename #pem_file to simply #pem
Browse files Browse the repository at this point in the history
  • Loading branch information
sandro committed Nov 20, 2009
1 parent 7d92dce commit 58fd4fa
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 20 deletions.
6 changes: 3 additions & 3 deletions lib/httparty.rb
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,10 @@ def format(f)
#
# 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.
Expand Down
6 changes: 3 additions & 3 deletions lib/httparty/request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ def http
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
Expand Down
33 changes: 19 additions & 14 deletions spec/httparty/request_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,20 +46,25 @@ def stub_response(body, code = 200)
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)

http = mock("http", :null_object => true)
http.should_receive(:cert=).with(cert)
http.should_receive(:key=).with(key)

Net::HTTP.stub(:new => http)
@request.options[:pem_file] = pem_file
@request.perform
context "PEM certificates" do
before do
OpenSSL::X509::Certificate.stub(:new)
OpenSSL::PKey::RSA.stub(:new)
end

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)

@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
Expand Down

0 comments on commit 58fd4fa

Please sign in to comment.