mirror of
https://github.com/rest-client/rest-client.git
synced 2022-11-09 13:49:40 -05:00
fixed failing integration/request_spec.rb. All tests are passing now
This commit is contained in:
parent
178a0d82c8
commit
e03e5e6ce9
3 changed files with 15 additions and 10 deletions
|
@ -149,13 +149,6 @@ module RestClient
|
||||||
net.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
net.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
||||||
elsif @verify_ssl.is_a? Integer
|
elsif @verify_ssl.is_a? Integer
|
||||||
net.verify_mode = @verify_ssl
|
net.verify_mode = @verify_ssl
|
||||||
net.verify_callback = lambda do |preverify_ok, ssl_context|
|
|
||||||
if (!preverify_ok) || ssl_context.error != 0
|
|
||||||
err_msg = "SSL Verification failed -- Preverify: #{preverify_ok}, Error: #{ssl_context.error_string} (#{ssl_context.error})"
|
|
||||||
raise SSLCertificateNotVerified.new(err_msg)
|
|
||||||
end
|
|
||||||
true
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
net.cert = @ssl_client_cert if @ssl_client_cert
|
net.cert = @ssl_client_cert if @ssl_client_cert
|
||||||
net.key = @ssl_client_key if @ssl_client_key
|
net.key = @ssl_client_key if @ssl_client_key
|
||||||
|
@ -186,6 +179,11 @@ module RestClient
|
||||||
raise RestClient::ServerBrokeConnection
|
raise RestClient::ServerBrokeConnection
|
||||||
rescue Timeout::Error
|
rescue Timeout::Error
|
||||||
raise RestClient::RequestTimeout
|
raise RestClient::RequestTimeout
|
||||||
|
rescue OpenSSL::SSL::SSLError => error
|
||||||
|
# UGH. Not sure if this is needed at all. SSLCertificateNotVerified is not being used internally.
|
||||||
|
# I think it would be better to leave SSLError processing to the client (they'd have to do that anyway...)
|
||||||
|
raise SSLCertificateNotVerified.new(error.message) if error.message.include?("certificate verify failed")
|
||||||
|
raise error
|
||||||
end
|
end
|
||||||
|
|
||||||
def setup_credentials(req)
|
def setup_credentials(req)
|
||||||
|
|
|
@ -12,8 +12,16 @@ describe RestClient::Request do
|
||||||
expect { request.execute }.to_not raise_error
|
expect { request.execute }.to_not raise_error
|
||||||
end
|
end
|
||||||
|
|
||||||
# This doesn't works any more (under 1.9.3 at the very least). Exceptions in verify_callback are ignored.
|
# I don' think this feature is useful anymore (under 1.9.3 at the very least).
|
||||||
# see https://github.com/ruby/ruby/blob/trunk/ext/openssl/ossl.c#L237
|
#
|
||||||
|
# Exceptions in verify_callback are ignored; RestClient has to catch OpenSSL::SSL::SSLError
|
||||||
|
# and either re-throw it as is, or throw SSLCertificateNotVerified
|
||||||
|
# based on the contents of the message field of the original exception
|
||||||
|
#.
|
||||||
|
# The client has to handle OpenSSL::SSL::SSLError exceptions anyway,
|
||||||
|
# why make them handle both OpenSSL *AND* RestClient exceptions???
|
||||||
|
#
|
||||||
|
# also see https://github.com/ruby/ruby/blob/trunk/ext/openssl/ossl.c#L237
|
||||||
it "is unsuccessful with an incorrect ca_file" do
|
it "is unsuccessful with an incorrect ca_file" do
|
||||||
request = RestClient::Request.new(
|
request = RestClient::Request.new(
|
||||||
:method => :get,
|
:method => :get,
|
||||||
|
|
|
@ -435,7 +435,6 @@ describe RestClient::Request do
|
||||||
:payload => 'payload',
|
:payload => 'payload',
|
||||||
:verify_ssl => mode )
|
:verify_ssl => mode )
|
||||||
@net.should_receive(:verify_mode=).with(mode)
|
@net.should_receive(:verify_mode=).with(mode)
|
||||||
@net.should_receive(:verify_callback=)
|
|
||||||
@http.stub!(:request)
|
@http.stub!(:request)
|
||||||
@request.stub!(:process_result)
|
@request.stub!(:process_result)
|
||||||
@request.stub!(:response_log)
|
@request.stub!(:response_log)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue