Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds CA certificate store support #254

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion lib/restclient/request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class Request
:payload, :user, :password, :timeout, :max_redirects,
:open_timeout, :raw_response, :verify_ssl, :ssl_client_cert,
:ssl_client_key, :ssl_ca_file, :processed_headers, :args,
:ssl_version, :ssl_ca_path
:ssl_version, :ssl_ca_path, :ssl_ca_store

def self.execute(args, & block)
new(args).execute(& block)
Expand Down Expand Up @@ -58,6 +58,7 @@ def initialize args
@ssl_ca_file = args[:ssl_ca_file] || nil
@ssl_ca_path = args[:ssl_ca_path] || nil
@ssl_version = args[:ssl_version] || 'SSLv3'
@ssl_ca_store = args[:ssl_ca_store] || nil
@tf = nil # If you are a raw request, this is your tempfile
@max_redirects = args[:max_redirects] || 10
@processed_headers = make_headers headers
Expand Down Expand Up @@ -169,6 +170,7 @@ def transmit uri, req, payload, & block
net.ca_path = @ssl_ca_path if @ssl_ca_path
net.read_timeout = @timeout if @timeout
net.open_timeout = @open_timeout if @open_timeout
net.cert_store = @ssl_ca_store if @ssl_ca_store

# disable the timeout if the timeout value is -1
net.read_timeout = nil if @timeout == -1
Expand Down
34 changes: 34 additions & 0 deletions spec/unit/request_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
@net.stub(:start).and_yield(@http)
@net.stub(:use_ssl=)
@net.stub(:verify_mode=)
@net.stub(:ssl_version=)
RestClient.log = nil
end

Expand Down Expand Up @@ -592,6 +593,39 @@
end
end

it "should default to not having a ssl_ca_store" do
expect(@request.ssl_ca_store).to be_nil
end

it "should set the ssl_ca_store when provided" do
store = double("X509 Store")

@request = RestClient::Request.new(
:method => 'put',
:url => 'https://some/resource',
:ssl_ca_store => store
)

@net.should_receive(:cert_store=).with(store)
@http.stub(:request)
@request.stub(:process_result)
@request.stub(:response_log)
@request.transmit(@uri, 'req', 'payload')
end

it "should not set the ssl_ca_store when it is not provided" do
@request = RestClient::Request.new(
:method => 'put',
:url => 'https://some/resource'
)

@net.should_not_receive(:cert_store=)
@http.stub(:request)
@request.stub(:process_result)
@request.stub(:response_log)
@request.transmit(@uri, 'req', 'payload')
end

it "should still return a response object for 204 No Content responses" do
@request = RestClient::Request.new(
:method => :put,
Expand Down