mirror of
https://github.com/rest-client/rest-client.git
synced 2022-11-09 13:49:40 -05:00
Add some tests around ssl_verify_callback.
This commit is contained in:
parent
9815fddcf3
commit
72a5b19a9b
2 changed files with 68 additions and 0 deletions
|
@ -62,5 +62,43 @@ describe RestClient::Request do
|
|||
)
|
||||
expect {request.execute }.to_not raise_error
|
||||
end
|
||||
|
||||
it "executes the verify_callack" do
|
||||
ran_callback = false
|
||||
request = RestClient::Request.new(
|
||||
:method => :get,
|
||||
:url => 'https://www.mozilla.org',
|
||||
:verify_ssl => true,
|
||||
:ssl_verify_callback => lambda { |preverify_ok, store_ctx|
|
||||
ran_callback = true
|
||||
preverify_ok
|
||||
},
|
||||
)
|
||||
expect {request.execute }.to_not raise_error
|
||||
ran_callback.should eq(true)
|
||||
end
|
||||
|
||||
it "fails verification when the callback returns false",
|
||||
:unless => RestClient::Platform.mac? do
|
||||
request = RestClient::Request.new(
|
||||
:method => :get,
|
||||
:url => 'https://www.mozilla.com',
|
||||
:verify_ssl => true,
|
||||
:ssl_verify_callback => lambda { |preverify_ok, store_ctx| false },
|
||||
)
|
||||
expect { request.execute }.to raise_error(RestClient::SSLCertificateNotVerified)
|
||||
end
|
||||
|
||||
it "succeeds verification when the callback returns true",
|
||||
:unless => RestClient::Platform.mac? do
|
||||
request = RestClient::Request.new(
|
||||
:method => :get,
|
||||
:url => 'https://www.mozilla.com',
|
||||
:verify_ssl => true,
|
||||
:ssl_ca_file => File.join(File.dirname(__FILE__), "certs", "verisign.crt"),
|
||||
:ssl_verify_callback => lambda { |preverify_ok, store_ctx| true },
|
||||
)
|
||||
expect { request.execute }.to_not raise_error
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -834,6 +834,36 @@ describe RestClient::Request do
|
|||
@request.stub(:response_log)
|
||||
@request.transmit(@uri, 'req', 'payload')
|
||||
end
|
||||
|
||||
it "should not set the ssl_verify_callback by default" do
|
||||
@request = RestClient::Request.new(
|
||||
:method => :put,
|
||||
:url => 'https://some/resource',
|
||||
:payload => 'payload',
|
||||
)
|
||||
@net.should_not_receive(:verify_callback=)
|
||||
@http.stub(:request)
|
||||
@request.stub(:process_result)
|
||||
@request.stub(:response_log)
|
||||
@request.transmit(@uri, 'req', 'payload')
|
||||
end
|
||||
|
||||
it "should set the ssl_verify_callback if passed" do
|
||||
callback = lambda {}
|
||||
@request = RestClient::Request.new(
|
||||
:method => :put,
|
||||
:url => 'https://some/resource',
|
||||
:payload => 'payload',
|
||||
:ssl_verify_callback => callback,
|
||||
)
|
||||
@net.should_receive(:verify_callback=).with(callback)
|
||||
@http.stub(:request)
|
||||
@request.stub(:process_result)
|
||||
@request.stub(:response_log)
|
||||
@request.transmit(@uri, 'req', 'payload')
|
||||
end
|
||||
|
||||
# </ssl>
|
||||
end
|
||||
|
||||
it "should still return a response object for 204 No Content responses" do
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue