mirror of
https://github.com/rest-client/rest-client.git
synced 2022-11-09 13:49:40 -05:00
Making it possible to actually set OpenSSL's verify_mode using OpenSSL constants. This makes the example in the README function and makes it possible to set more complex schemes like :verify_mode => OpenSSL::SSL::VERIFY_PEER | OpenSSL::SSL::VERIFY_FAIL_IF_NO_PEER_CERT.
This commit is contained in:
parent
d24758aaf5
commit
97698bcd63
2 changed files with 26 additions and 8 deletions
|
@ -105,7 +105,11 @@ module RestClient
|
|||
|
||||
net = net_http_class.new(uri.host, uri.port)
|
||||
net.use_ssl = uri.is_a?(URI::HTTPS)
|
||||
net.verify_mode = OpenSSL::SSL::VERIFY_NONE if @verify_ssl == false
|
||||
if @verify_ssl == false
|
||||
net.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
||||
elsif @verify_ssl.is_a? Integer
|
||||
net.verify_mode = @verify_ssl
|
||||
end
|
||||
net.cert = @ssl_client_cert if @ssl_client_cert
|
||||
net.key = @ssl_client_key if @ssl_client_key
|
||||
net.ca_file = @ssl_ca_file if @ssl_ca_file
|
||||
|
|
|
@ -330,13 +330,13 @@ describe RestClient::Request do
|
|||
@request.verify_ssl.should == false
|
||||
end
|
||||
|
||||
it "should set net.verify_mode to OpenSSL::SSL::VERIFY_NONE if verify_ssl is false" do
|
||||
@net.should_receive(:verify_mode=).with(OpenSSL::SSL::VERIFY_NONE)
|
||||
@http.stub!(:request)
|
||||
@request.stub!(:process_result)
|
||||
@request.stub!(:response_log)
|
||||
@request.transmit(@uri, 'req', 'payload')
|
||||
end
|
||||
it "should set net.verify_mode to OpenSSL::SSL::VERIFY_NONE if verify_ssl is false" do
|
||||
@net.should_receive(:verify_mode=).with(OpenSSL::SSL::VERIFY_NONE)
|
||||
@http.stub!(:request)
|
||||
@request.stub!(:process_result)
|
||||
@request.stub!(:response_log)
|
||||
@request.transmit(@uri, 'req', 'payload')
|
||||
end
|
||||
|
||||
it "should not set net.verify_mode to OpenSSL::SSL::VERIFY_NONE if verify_ssl is true" do
|
||||
@request = RestClient::Request.new(:method => :put, :url => 'https://some/resource', :payload => 'payload', :verify_ssl => true)
|
||||
|
@ -347,6 +347,20 @@ describe RestClient::Request do
|
|||
@request.transmit(@uri, 'req', 'payload')
|
||||
end
|
||||
|
||||
it "should set net.verify_mode to the passed value if verify_ssl is an OpenSSL constant" do
|
||||
mode = OpenSSL::SSL::VERIFY_PEER |
|
||||
OpenSSL::SSL::VERIFY_FAIL_IF_NO_PEER_CERT
|
||||
@request = RestClient::Request.new( :method => :put,
|
||||
:url => 'https://some/resource',
|
||||
:payload => 'payload',
|
||||
:verify_ssl => mode )
|
||||
@net.should_receive(:verify_mode=).with(mode)
|
||||
@http.stub!(:request)
|
||||
@request.stub!(:process_result)
|
||||
@request.stub!(:response_log)
|
||||
@request.transmit(@uri, 'req', 'payload')
|
||||
end
|
||||
|
||||
it "should default to not having an ssl_client_cert" do
|
||||
@request.ssl_client_cert.should be(nil)
|
||||
end
|
||||
|
|
Loading…
Add table
Reference in a new issue