diff --git a/lib/restclient/request.rb b/lib/restclient/request.rb index 7d69bd8..b7ff76b 100644 --- a/lib/restclient/request.rb +++ b/lib/restclient/request.rb @@ -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 diff --git a/spec/request_spec.rb b/spec/request_spec.rb index 461ebe9..c56f158 100644 --- a/spec/request_spec.rb +++ b/spec/request_spec.rb @@ -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