mirror of
https://github.com/rest-client/rest-client.git
synced 2022-11-09 13:49:40 -05:00
Add tests for SSL CA path behavior.
This commit is contained in:
parent
a9062f7050
commit
fe5b5bb201
10 changed files with 63 additions and 0 deletions
1
spec/integration/capath_equifax/578d5c04.0
Symbolic link
1
spec/integration/capath_equifax/578d5c04.0
Symbolic link
|
@ -0,0 +1 @@
|
|||
equifax.crt
|
1
spec/integration/capath_equifax/594f1775.0
Symbolic link
1
spec/integration/capath_equifax/594f1775.0
Symbolic link
|
@ -0,0 +1 @@
|
|||
equifax.crt
|
1
spec/integration/capath_equifax/README
Normal file
1
spec/integration/capath_equifax/README
Normal file
|
@ -0,0 +1 @@
|
|||
These symlinks are created by c_rehash(1ssl).
|
1
spec/integration/capath_equifax/equifax.crt
Symbolic link
1
spec/integration/capath_equifax/equifax.crt
Symbolic link
|
@ -0,0 +1 @@
|
|||
../certs/equifax.crt
|
1
spec/integration/capath_verisign/415660c1.0
Symbolic link
1
spec/integration/capath_verisign/415660c1.0
Symbolic link
|
@ -0,0 +1 @@
|
|||
verisign.crt
|
1
spec/integration/capath_verisign/7651b327.0
Symbolic link
1
spec/integration/capath_verisign/7651b327.0
Symbolic link
|
@ -0,0 +1 @@
|
|||
verisign.crt
|
1
spec/integration/capath_verisign/README
Normal file
1
spec/integration/capath_verisign/README
Normal file
|
@ -0,0 +1 @@
|
|||
These symlinks are created by c_rehash(1ssl).
|
1
spec/integration/capath_verisign/verisign.crt
Symbolic link
1
spec/integration/capath_verisign/verisign.crt
Symbolic link
|
@ -0,0 +1 @@
|
|||
../certs/verisign.crt
|
|
@ -12,6 +12,16 @@ describe RestClient::Request do
|
|||
expect { request.execute }.to_not raise_error
|
||||
end
|
||||
|
||||
it "is successful with the correct ca_path" do
|
||||
request = RestClient::Request.new(
|
||||
:method => :get,
|
||||
:url => 'https://www.mozilla.com',
|
||||
:verify_ssl => OpenSSL::SSL::VERIFY_PEER,
|
||||
:ssl_ca_path => File.join(File.dirname(__FILE__), "capath_equifax")
|
||||
)
|
||||
expect { request.execute }.to_not raise_error
|
||||
end
|
||||
|
||||
# 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
|
||||
|
@ -31,5 +41,15 @@ describe RestClient::Request do
|
|||
)
|
||||
expect { request.execute }.to raise_error(RestClient::SSLCertificateNotVerified)
|
||||
end
|
||||
|
||||
it "is unsuccessful with an incorrect ca_path" do
|
||||
request = RestClient::Request.new(
|
||||
:method => :get,
|
||||
:url => 'https://www.mozilla.com',
|
||||
:verify_ssl => OpenSSL::SSL::VERIFY_PEER,
|
||||
:ssl_ca_path => File.join(File.dirname(__FILE__), "capath_verisign")
|
||||
)
|
||||
expect { request.execute }.to raise_error(RestClient::SSLCertificateNotVerified)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -558,6 +558,41 @@ describe RestClient::Request do
|
|||
@request.stub!(:response_log)
|
||||
@request.transmit(@uri, 'req', 'payload')
|
||||
end
|
||||
|
||||
it "should default to not having an ssl_ca_path" do
|
||||
@request.ssl_ca_path.should be(nil)
|
||||
end
|
||||
|
||||
it "should set the ssl_ca_path if provided" do
|
||||
@request = RestClient::Request.new(
|
||||
:method => :put,
|
||||
:url => 'https://some/resource',
|
||||
:payload => 'payload',
|
||||
:ssl_version => 'SSLv3',
|
||||
:ssl_ca_path => "Certificate Authority Path"
|
||||
)
|
||||
@net.should_receive(:ca_path=).with("Certificate Authority Path")
|
||||
@net.should_receive(:ssl_version=).with('SSLv3')
|
||||
@http.stub!(:request)
|
||||
@request.stub!(:process_result)
|
||||
@request.stub!(:response_log)
|
||||
@request.transmit(@uri, 'req', 'payload')
|
||||
end
|
||||
|
||||
it "should not set the ssl_sa_path if it is not provided" do
|
||||
@request = RestClient::Request.new(
|
||||
:method => :put,
|
||||
:url => 'https://some/resource',
|
||||
:ssl_version => 'TSLv1',
|
||||
:payload => 'payload'
|
||||
)
|
||||
@net.should_not_receive(:sa_path=).with("Certificate Authority File")
|
||||
@net.should_receive(:ssl_version=).with('TSLv1')
|
||||
@http.stub!(:request)
|
||||
@request.stub!(:process_result)
|
||||
@request.stub!(:response_log)
|
||||
@request.transmit(@uri, 'req', 'payload')
|
||||
end
|
||||
end
|
||||
|
||||
it "should still return a response object for 204 No Content responses" do
|
||||
|
|
Loading…
Reference in a new issue