2013-08-06 11:44:47 -04:00
|
|
|
require 'spec_helper'
|
2010-05-13 12:56:56 -04:00
|
|
|
|
|
|
|
describe RestClient::Request do
|
2013-08-06 11:44:47 -04:00
|
|
|
before(:all) do
|
|
|
|
WebMock.disable!
|
|
|
|
end
|
|
|
|
|
|
|
|
after(:all) do
|
|
|
|
WebMock.enable!
|
|
|
|
end
|
|
|
|
|
2010-05-13 12:56:56 -04:00
|
|
|
describe "ssl verification" do
|
|
|
|
it "is successful with the correct ca_file" do
|
|
|
|
request = RestClient::Request.new(
|
|
|
|
:method => :get,
|
2014-02-11 16:10:10 -05:00
|
|
|
:url => 'https://www.mozilla.org',
|
|
|
|
:ssl_ca_file => File.join(File.dirname(__FILE__), "certs", "digicert.crt")
|
2010-05-13 12:56:56 -04:00
|
|
|
)
|
|
|
|
expect { request.execute }.to_not raise_error
|
|
|
|
end
|
|
|
|
|
2013-07-30 21:22:51 -04:00
|
|
|
it "is successful with the correct ca_path" do
|
|
|
|
request = RestClient::Request.new(
|
|
|
|
:method => :get,
|
2014-02-11 16:10:10 -05:00
|
|
|
:url => 'https://www.mozilla.org',
|
|
|
|
:ssl_ca_path => File.join(File.dirname(__FILE__), "capath_digicert")
|
2013-07-30 21:22:51 -04:00
|
|
|
)
|
|
|
|
expect { request.execute }.to_not raise_error
|
|
|
|
end
|
|
|
|
|
2012-11-16 07:36:25 -05:00
|
|
|
# I don' think this feature is useful anymore (under 1.9.3 at the very least).
|
|
|
|
#
|
|
|
|
# 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
|
2010-05-13 12:56:56 -04:00
|
|
|
it "is unsuccessful with an incorrect ca_file" do
|
|
|
|
request = RestClient::Request.new(
|
|
|
|
:method => :get,
|
2011-08-15 05:01:43 -04:00
|
|
|
:url => 'https://www.mozilla.com',
|
|
|
|
:ssl_ca_file => File.join(File.dirname(__FILE__), "certs", "verisign.crt")
|
2010-05-13 12:56:56 -04:00
|
|
|
)
|
|
|
|
expect { request.execute }.to raise_error(RestClient::SSLCertificateNotVerified)
|
|
|
|
end
|
2013-07-30 21:22:51 -04:00
|
|
|
|
|
|
|
it "is unsuccessful with an incorrect ca_path" do
|
|
|
|
request = RestClient::Request.new(
|
|
|
|
:method => :get,
|
|
|
|
:url => 'https://www.mozilla.com',
|
|
|
|
:ssl_ca_path => File.join(File.dirname(__FILE__), "capath_verisign")
|
|
|
|
)
|
|
|
|
expect { request.execute }.to raise_error(RestClient::SSLCertificateNotVerified)
|
|
|
|
end
|
2010-05-13 12:56:56 -04:00
|
|
|
end
|
|
|
|
end
|