From 0e8f0f34fab3c06cb5a5f31a7fc036704511bfbf Mon Sep 17 00:00:00 2001 From: Dan Falcone Date: Wed, 29 Nov 2017 21:00:42 -0500 Subject: [PATCH] Add a client cert spec for the http client --- spec/jira/http_client_spec.rb | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/spec/jira/http_client_spec.rb b/spec/jira/http_client_spec.rb index be71d642..fdc13766 100644 --- a/spec/jira/http_client_spec.rb +++ b/spec/jira/http_client_spec.rb @@ -28,6 +28,15 @@ JIRA::HttpClient.new(options) end + let(:basic_client_cert_client) do + options = JIRA::Client::DEFAULT_OPTIONS.merge(JIRA::HttpClient::DEFAULT_OPTIONS).merge( + :use_client_cert => true, + :cert => 'public certificate contents', + :key => 'private key contents' + ) + JIRA::HttpClient.new(options) + end + let(:response) do response = double("response") allow(response).to receive(:kind_of?).with(Net::HTTPSuccess).and_return(true) @@ -170,6 +179,22 @@ expect(basic_client.http_conn(uri)).to eq(http_conn) end + it 'can use client certificates' do + http_conn = double + uri = double + host = double + port = double + expect(Net::HTTP).to receive(:new).with(host, port).and_return(http_conn) + expect(uri).to receive(:host).and_return(host) + expect(uri).to receive(:port).and_return(port) + expect(http_conn).to receive(:use_ssl=).with(basic_client.options[:use_ssl]) + expect(http_conn).to receive(:verify_mode=).with(basic_client.options[:ssl_verify_mode]) + expect(http_conn).to receive(:read_timeout=).with(basic_client.options[:read_timeout]) + expect(http_conn).to receive(:cert=).with(basic_client_cert_client.options[:cert]) + expect(http_conn).to receive(:key=).with(basic_client_cert_client.options[:key]) + expect(basic_client_cert_client.http_conn(uri)).to eq(http_conn) + end + it "returns a http connection" do http_conn = double() uri = double()