httpi 2.4.0 → 2.4.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (42) hide show
  1. checksums.yaml +5 -5
  2. data/.travis.yml +3 -5
  3. data/CHANGELOG.md +42 -0
  4. data/Gemfile +5 -1
  5. data/README.md +7 -7
  6. data/Rakefile +5 -3
  7. data/httpi.gemspec +2 -1
  8. data/lib/httpi.rb +5 -4
  9. data/lib/httpi/adapter.rb +1 -1
  10. data/lib/httpi/adapter/curb.rb +18 -5
  11. data/lib/httpi/adapter/em_http.rb +5 -4
  12. data/lib/httpi/adapter/excon.rb +16 -5
  13. data/lib/httpi/adapter/http.rb +88 -0
  14. data/lib/httpi/adapter/httpclient.rb +15 -4
  15. data/lib/httpi/adapter/net_http.rb +43 -16
  16. data/lib/httpi/adapter/net_http_persistent.rb +10 -1
  17. data/lib/httpi/adapter/rack.rb +13 -6
  18. data/lib/httpi/auth/ssl.rb +49 -2
  19. data/lib/httpi/logger.rb +6 -1
  20. data/lib/httpi/request.rb +12 -5
  21. data/lib/httpi/response.rb +2 -0
  22. data/lib/httpi/version.rb +1 -1
  23. data/spec/httpi/adapter/curb_spec.rb +56 -18
  24. data/spec/httpi/adapter/em_http_spec.rb +21 -13
  25. data/spec/httpi/adapter/excon_spec.rb +28 -90
  26. data/spec/httpi/adapter/http_spec.rb +28 -0
  27. data/spec/httpi/adapter/httpclient_spec.rb +39 -4
  28. data/spec/httpi/adapter/net_http_persistent_spec.rb +31 -81
  29. data/spec/httpi/adapter/net_http_spec.rb +39 -99
  30. data/spec/httpi/adapter/rack_spec.rb +6 -8
  31. data/spec/httpi/auth/ssl_spec.rb +32 -1
  32. data/spec/httpi/httpi_spec.rb +17 -1
  33. data/spec/httpi/request_spec.rb +5 -0
  34. data/spec/integration/curb_spec.rb +11 -0
  35. data/spec/integration/em_http_spec.rb +17 -0
  36. data/spec/integration/excon_spec.rb +165 -0
  37. data/spec/integration/http_spec.rb +147 -0
  38. data/spec/integration/httpclient_spec.rb +11 -0
  39. data/spec/integration/net_http_persistent_spec.rb +22 -1
  40. data/spec/integration/net_http_spec.rb +127 -1
  41. data/spec/integration/support/application.rb +4 -2
  42. metadata +35 -4
@@ -4,6 +4,8 @@ require "httpi/adapter/base"
4
4
  require "httpi/response"
5
5
  require 'kconv'
6
6
  require 'socket'
7
+ require "socksify"
8
+ require 'socksify/http'
7
9
 
8
10
  module HTTPI
9
11
  module Adapter
@@ -16,8 +18,7 @@ module HTTPI
16
18
 
17
19
  register :net_http, :deps => %w(net/https)
18
20
  def initialize(request)
19
- check_net_ntlm_version!
20
-
21
+ check_net_ntlm_version! if request.auth.ntlm?
21
22
  @request = request
22
23
  @client = create_client
23
24
  end
@@ -27,8 +28,12 @@ module HTTPI
27
28
  # Executes arbitrary HTTP requests.
28
29
  # @see HTTPI.request
29
30
  def request(method)
30
- unless REQUEST_METHODS.include? method
31
- raise NotSupportedError, "Net::HTTP does not support custom HTTP methods"
31
+ # Determine if Net::HTTP supports the method using reflection
32
+ unless Net::HTTP.const_defined?(:"#{method.to_s.capitalize}") &&
33
+ Net::HTTP.const_get(:"#{method.to_s.capitalize}").class == Class
34
+
35
+ raise NotSupportedError, "Net::HTTP does not support "\
36
+ "#{method.to_s.upcase}"
32
37
  end
33
38
  do_request(method) do |http, http_request|
34
39
  http_request.body = @request.body
@@ -50,11 +55,15 @@ module HTTPI
50
55
  end
51
56
 
52
57
  private
58
+ def ntlm_version
59
+ Net::NTLM::VERSION::STRING
60
+ end
61
+
53
62
  def check_net_ntlm_version!
54
63
  begin
55
64
  require 'net/ntlm'
56
- require 'net/ntlm/version' unless Net::NTLM.const_defined?(:VERSION)
57
- unless Net::NTLM::VERSION::STRING >= '0.3.2'
65
+ require 'net/ntlm/version' unless Net::NTLM.const_defined?(:VERSION, false)
66
+ unless ntlm_version >= '0.3.2'
58
67
  raise ArgumentError, 'Invalid version of rubyntlm. Please use v0.3.2+.'
59
68
  end
60
69
  rescue LoadError
@@ -67,7 +76,11 @@ module HTTPI
67
76
 
68
77
  def create_client
69
78
  proxy_url = @request.proxy || URI("")
70
- proxy = Net::HTTP::Proxy(proxy_url.host, proxy_url.port, proxy_url.user, proxy_url.password)
79
+ if URI(proxy_url).scheme == 'socks'
80
+ proxy =Net::HTTP.SOCKSProxy(proxy_url.host, proxy_url.port)
81
+ else
82
+ proxy = Net::HTTP::Proxy(proxy_url.host, proxy_url.port, proxy_url.user, proxy_url.password)
83
+ end
71
84
  proxy.new(@request.url.host, @request.url.port)
72
85
  end
73
86
 
@@ -92,9 +105,9 @@ module HTTPI
92
105
 
93
106
  # first figure out if we should use NTLM or Negotiate
94
107
  nego_auth_response = respond_with(requester.call(http, request_client(:head)))
95
- if nego_auth_response.headers['www-authenticate'].include? 'Negotiate'
108
+ if nego_auth_response.headers['www-authenticate'] && nego_auth_response.headers['www-authenticate'].include?('Negotiate')
96
109
  auth_method = 'Negotiate'
97
- elsif nego_auth_response.headers['www-authenticate'].include? 'NTLM'
110
+ elsif nego_auth_response.headers['www-authenticate'] && nego_auth_response.headers['www-authenticate'].include?('NTLM')
98
111
  auth_method = 'NTLM'
99
112
  else
100
113
  auth_method = 'NTLM'
@@ -142,6 +155,13 @@ module HTTPI
142
155
  @client.use_ssl = @request.ssl?
143
156
  @client.open_timeout = @request.open_timeout if @request.open_timeout
144
157
  @client.read_timeout = @request.read_timeout if @request.read_timeout
158
+ if @request.write_timeout
159
+ if @client.respond_to?(:write_timeout=) # Expected to appear in Ruby 2.6
160
+ @client.write_timeout = @request.write_timeout
161
+ else
162
+ raise NotSupportedError, "Net::HTTP supports write_timeout starting from Ruby 2.6"
163
+ end
164
+ end
145
165
  end
146
166
 
147
167
  def setup_ssl_auth
@@ -150,6 +170,8 @@ module HTTPI
150
170
  if @request.auth.ssl?
151
171
  unless ssl.verify_mode == :none
152
172
  @client.ca_file = ssl.ca_cert_file if ssl.ca_cert_file
173
+ @client.ca_path = ssl.ca_cert_path if ssl.ca_cert_path
174
+ @client.cert_store = ssl_cert_store(ssl)
153
175
  end
154
176
 
155
177
  # Send client-side certificate regardless of state of SSL verify mode
@@ -160,16 +182,21 @@ module HTTPI
160
182
  end
161
183
 
162
184
  @client.ssl_version = ssl.ssl_version if ssl.ssl_version
185
+ @client.min_version = ssl.min_version if ssl.min_version
186
+ @client.max_version = ssl.max_version if ssl.max_version
187
+ end
188
+
189
+ def ssl_cert_store(ssl)
190
+ return ssl.cert_store if ssl.cert_store
191
+
192
+ # Use the default cert store by default, i.e. system ca certs
193
+ cert_store = OpenSSL::X509::Store.new
194
+ cert_store.set_default_paths
195
+ cert_store
163
196
  end
164
197
 
165
198
  def request_client(type)
166
- request_class = case type
167
- when :get then Net::HTTP::Get
168
- when :post then Net::HTTP::Post
169
- when :head then Net::HTTP::Head
170
- when :put then Net::HTTP::Put
171
- when :delete then Net::HTTP::Delete
172
- end
199
+ request_class = Net::HTTP.const_get(:"#{type.to_s.capitalize}")
173
200
 
174
201
  request_client = request_class.new @request.url.request_uri, @request.headers
175
202
  request_client.basic_auth(*@request.auth.credentials) if @request.auth.basic?
@@ -12,7 +12,11 @@ module HTTPI
12
12
  private
13
13
 
14
14
  def create_client
15
- Net::HTTP::Persistent.new thread_key
15
+ if is_v3
16
+ Net::HTTP::Persistent.new name: thread_key
17
+ else
18
+ Net::HTTP::Persistent.new thread_key
19
+ end
16
20
  end
17
21
 
18
22
  def perform(http, http_request, &on_body)
@@ -32,12 +36,17 @@ module HTTPI
32
36
 
33
37
  @client.open_timeout = @request.open_timeout if @request.open_timeout
34
38
  @client.read_timeout = @request.read_timeout if @request.read_timeout
39
+ raise NotSupportedError, "Net::HTTP::Persistent does not support write_timeout" if @request.write_timeout
35
40
  end
36
41
 
37
42
  def thread_key
38
43
  @request.url.host.split(/\W/).reject{|p|p == ""}.join('-')
39
44
  end
40
45
 
46
+ def is_v3
47
+ Net::HTTP::Persistent::VERSION.start_with? "3."
48
+ end
49
+
41
50
  end
42
51
  end
43
52
  end
@@ -1,3 +1,4 @@
1
+ require 'base64'
1
2
  require 'httpi/adapter/base'
2
3
  require 'httpi/response'
3
4
 
@@ -61,17 +62,18 @@ module HTTPI
61
62
  raise NotSupportedError, "Rack adapter does not support custom HTTP methods"
62
63
  end
63
64
 
64
- env = {}
65
- @request.headers.each do |header, value|
66
- env["HTTP_#{header.gsub('-', '_').upcase}"] = value
67
- end
68
-
69
65
  if @request.proxy
70
66
  raise NotSupportedError, "Rack adapter does not support proxying"
71
67
  end
72
68
 
73
69
  if @request.auth.http?
74
- raise NotSupportedError, "Rack adapter does not support HTTP auth"
70
+ if @request.auth.basic?
71
+ basic_auth = @request.auth.basic.join(':')
72
+ encoded = Base64.encode64(basic_auth).gsub('\n', '')
73
+ @request.headers['Authorization'] = "Basic #{encoded}"
74
+ else
75
+ raise NotSupportedError, "Rack adapter does not support HTTP #{@request.auth.type} auth"
76
+ end
75
77
  end
76
78
 
77
79
  if @request.auth.ssl?
@@ -82,6 +84,11 @@ module HTTPI
82
84
  raise NotSupportedError, "Rack adapter does not support response streaming"
83
85
  end
84
86
 
87
+ env = {}
88
+ @request.headers.each do |header, value|
89
+ env["HTTP_#{header.gsub('-', '_').upcase}"] = value
90
+ end
91
+
85
92
  response = @client.request(method.to_s.upcase, @request.url.to_s,
86
93
  { :fatal => true, :input => @request.body.to_s }.merge(env))
87
94
 
@@ -10,7 +10,18 @@ module HTTPI
10
10
 
11
11
  VERIFY_MODES = [:none, :peer, :fail_if_no_peer_cert, :client_once]
12
12
  CERT_TYPES = [:pem, :der]
13
- SSL_VERSIONS = OpenSSL::SSL::SSLContext::METHODS.reject { |method| method.match /server|client/ }.sort.reverse
13
+
14
+ # Fix for
15
+ # httpi/auth/ssl.rb:13: warning: constant OpenSSL::SSL::SSLContext::METHODS is deprecated
16
+ ssl_context = OpenSSL::SSL::SSLContext
17
+ SSL_VERSIONS = if ssl_context.const_defined? :METHODS_MAP
18
+ ssl_context.const_get(:METHODS_MAP).keys
19
+ else
20
+ ssl_context::METHODS.reject { |method| method.match(/server|client/) }
21
+ end.sort.reverse
22
+
23
+ # Returns OpenSSL::SSL::*_VERSION values for min_version and max_version
24
+ MIN_MAX_VERSIONS = OpenSSL::SSL.constants.select{|constant| constant =~/_VERSION$/}.map{|version| version.to_s.gsub(/_VERSION$/,'').to_sym}.reverse
14
25
 
15
26
  # Returns whether SSL configuration is present.
16
27
  def present?
@@ -31,6 +42,12 @@ module HTTPI
31
42
  # Accessor for the cacert file to validate SSL certificates.
32
43
  attr_accessor :ca_cert_file
33
44
 
45
+ # Accessor for the ca_path to validate SSL certificates.
46
+ attr_accessor :ca_cert_path
47
+
48
+ # Certificate store holds trusted CA certificates used to verify peer certificates.
49
+ attr_accessor :cert_store
50
+
34
51
  # Returns the cert type to validate SSL certificates PEM|DER.
35
52
  def cert_type
36
53
  @cert_type ||= :pem
@@ -63,7 +80,7 @@ module HTTPI
63
80
 
64
81
  # Returns the SSL version number. Defaults to <tt>nil</tt> (auto-negotiate).
65
82
  def ssl_version
66
- @ssl_version
83
+ @ssl_version ||= nil
67
84
  end
68
85
 
69
86
  # Sets the SSL version number. Expects one of <tt>HTTPI::Auth::SSL::SSL_VERSIONS</tt>.
@@ -76,6 +93,36 @@ module HTTPI
76
93
  @ssl_version = version
77
94
  end
78
95
 
96
+ # Returns the SSL min_version number. Defaults to <tt>nil</tt> (auto-negotiate).
97
+ def min_version
98
+ @min_version ||= nil
99
+ end
100
+
101
+ # Sets the SSL min_version number. Expects one of <tt>HTTPI::Auth::SSL::MIN_MAX_VERSIONS</tt>.
102
+ def min_version=(version)
103
+ unless MIN_MAX_VERSIONS.include? version
104
+ raise ArgumentError, "Invalid SSL min_version #{version.inspect}\n" +
105
+ "Please specify one of #{MIN_MAX_VERSIONS.inspect}"
106
+ end
107
+
108
+ @min_version = version
109
+ end
110
+
111
+ # Returns the SSL min_version number. Defaults to <tt>nil</tt> (auto-negotiate).
112
+ def max_version
113
+ @max_version ||= nil
114
+ end
115
+
116
+ # Sets the SSL min_version number. Expects one of <tt>HTTPI::Auth::SSL::MIN_MAX_VERSIONS</tt>.
117
+ def max_version=(version)
118
+ unless MIN_MAX_VERSIONS.include? version
119
+ raise ArgumentError, "Invalid SSL max_version #{version.inspect}\n" +
120
+ "Please specify one of #{MIN_MAX_VERSIONS.inspect}"
121
+ end
122
+
123
+ @max_version = version
124
+ end
125
+
79
126
  # Returns an <tt>OpenSSL::X509::Certificate</tt> for the +cert_file+.
80
127
  def cert
81
128
  @cert ||= (OpenSSL::X509::Certificate.new File.read(cert_file) if cert_file)
@@ -43,8 +43,13 @@ module HTTPI
43
43
  protected
44
44
 
45
45
  def log_request(method, request, adapter)
46
- log("HTTPI #{method.to_s.upcase} request to #{request.url.host} (#{adapter})")
46
+ log("HTTPI #{request_ssl_info(request)} #{method.to_s.upcase} request to #{request.url.host} (#{adapter})")
47
47
  end
48
48
 
49
+ def request_ssl_info(request)
50
+ if request.auth && request.auth.ssl
51
+ "#{request.auth.ssl.ssl_version}/#{request.auth.ssl.verify_mode}"
52
+ end
53
+ end
49
54
  end
50
55
  end
@@ -11,7 +11,7 @@ module HTTPI
11
11
  class Request
12
12
 
13
13
  # Available attribute writers.
14
- ATTRIBUTES = [:url, :proxy, :headers, :body, :open_timeout, :read_timeout, :follow_redirect, :query]
14
+ ATTRIBUTES = [:url, :proxy, :headers, :body, :open_timeout, :read_timeout, :write_timeout, :follow_redirect, :redirect_limit, :query]
15
15
 
16
16
  # Accepts a Hash of +args+ to mass assign attributes and authentication credentials.
17
17
  def initialize(args = {})
@@ -56,8 +56,7 @@ module HTTPI
56
56
 
57
57
  # Returns whether to use SSL.
58
58
  def ssl?
59
- return @ssl unless @ssl.nil?
60
- !!(url.to_s =~ /^https/)
59
+ @ssl ||= !!(url.to_s =~ /^https/)
61
60
  end
62
61
 
63
62
  # Sets whether to use SSL.
@@ -91,7 +90,7 @@ module HTTPI
91
90
  headers["Cookie"] = cookies if cookies
92
91
  end
93
92
 
94
- attr_accessor :open_timeout, :read_timeout
93
+ attr_accessor :open_timeout, :read_timeout, :write_timeout
95
94
  attr_reader :body
96
95
 
97
96
  # Sets a body request given a String or a Hash.
@@ -102,6 +101,7 @@ module HTTPI
102
101
  # Sets the block to be called while processing the response. The block
103
102
  # accepts a single parameter - the chunked response body.
104
103
  def on_body(&block)
104
+ @on_body ||= nil
105
105
  if block_given? then
106
106
  @on_body = block
107
107
  end
@@ -130,6 +130,13 @@ module HTTPI
130
130
  @follow_redirect ||= false
131
131
  end
132
132
 
133
+ attr_writer :redirect_limit
134
+
135
+ # Returns how many redirects should be followed - defaults to 3 if not set.
136
+ def redirect_limit
137
+ @redirect_limit ||= 3
138
+ end
139
+
133
140
  private
134
141
 
135
142
  # Stores the cookies from past requests.
@@ -139,7 +146,7 @@ module HTTPI
139
146
 
140
147
  # Expects a +url+, validates its validity and returns a +URI+ object.
141
148
  def normalize_url!(url)
142
- raise ArgumentError, "Invalid URL: #{url}" unless url.to_s =~ /^http/
149
+ raise ArgumentError, "Invalid URL: #{url}" unless url.to_s =~ /^http|socks/
143
150
  url.kind_of?(URI) ? url : URI(url)
144
151
  end
145
152
 
@@ -44,12 +44,14 @@ module HTTPI
44
44
 
45
45
  # Returns any DIME attachments.
46
46
  def attachments
47
+ @body ||= nil
47
48
  decode_body unless @body
48
49
  @attachments ||= []
49
50
  end
50
51
 
51
52
  # Returns the HTTP response body.
52
53
  def body
54
+ @body ||= nil
53
55
  decode_body unless @body
54
56
  @body
55
57
  end
@@ -1,3 +1,3 @@
1
1
  module HTTPI
2
- VERSION = '2.4.0'
2
+ VERSION = '2.4.5'
3
3
  end
@@ -2,10 +2,30 @@ require "spec_helper"
2
2
  require "httpi/adapter/curb"
3
3
  require "httpi/request"
4
4
 
5
+ require "integration/support/server"
6
+
5
7
  # curb does not run on jruby
6
8
  unless RUBY_PLATFORM =~ /java/
7
9
  HTTPI::Adapter.load_adapter(:curb)
8
10
 
11
+ describe "NTLM authentication" do
12
+ before :all do
13
+ @server = IntegrationServer.run
14
+ end
15
+
16
+ after :all do
17
+ @server.stop
18
+ end
19
+
20
+ it "supports ntlm authentication" do
21
+ request = HTTPI::Request.new(@server.url + "ntlm-auth")
22
+ adapter = HTTPI::Adapter::Curb.new(request)
23
+
24
+ request.auth.ntlm("tester", "vReqSoafRe5O")
25
+ expect(adapter.request(:get).body).to eq("ntlm-auth")
26
+ end
27
+ end
28
+
9
29
  describe HTTPI::Adapter::Curb do
10
30
 
11
31
  let(:adapter) { HTTPI::Adapter::Curb.new(request) }
@@ -126,29 +146,36 @@ unless RUBY_PLATFORM =~ /java/
126
146
  end
127
147
  end
128
148
 
129
- describe "timeout" do
149
+ describe "timeout_ms" do
130
150
  it "is not set unless it's specified" do
131
- curb.expects(:timeout=).never
151
+ curb.expects(:timeout_ms=).never
132
152
  adapter.request(:get)
133
153
  end
134
154
 
135
- it "is set if specified" do
155
+ it "is set if specified read_timeout" do
136
156
  request.read_timeout = 30
137
- curb.expects(:timeout=).with(request.read_timeout)
157
+ curb.expects(:timeout_ms=).with(30_000)
158
+
159
+ adapter.request(:get)
160
+ end
161
+
162
+ it "is set if specified write_timeout" do
163
+ request.write_timeout = 30
164
+ curb.expects(:timeout_ms=).with(30_000)
138
165
 
139
166
  adapter.request(:get)
140
167
  end
141
168
  end
142
169
 
143
- describe "connect_timeout" do
170
+ describe "connect_timeout_ms" do
144
171
  it "is not set unless it's specified" do
145
- curb.expects(:connect_timeout=).never
172
+ curb.expects(:connect_timeout_ms=).never
146
173
  adapter.request(:get)
147
174
  end
148
175
 
149
176
  it "is set if specified" do
150
177
  request.open_timeout = 30
151
- curb.expects(:connect_timeout=).with(30)
178
+ curb.expects(:connect_timeout_ms=).with(30_000)
152
179
 
153
180
  adapter.request(:get)
154
181
  end
@@ -168,15 +195,6 @@ unless RUBY_PLATFORM =~ /java/
168
195
  end
169
196
  end
170
197
 
171
- describe "NTLM authentication" do
172
- it "is not supported" do
173
- request.auth.ntlm("tester", "vReqSoafRe5O")
174
-
175
- expect { adapter.request(:get) }.
176
- to raise_error(HTTPI::NotSupportedError, /does not support NTLM authentication/)
177
- end
178
- end
179
-
180
198
  describe "http_auth_types" do
181
199
  it "is set to :basic for HTTP basic auth" do
182
200
  request.auth.basic "username", "password"
@@ -198,6 +216,13 @@ unless RUBY_PLATFORM =~ /java/
198
216
 
199
217
  adapter.request(:get)
200
218
  end
219
+
220
+ it "is set to :ntlm for HTTP NTLM auth" do
221
+ request.auth.ntlm("tester", "vReqSoafRe5O")
222
+ curb.expects(:http_auth_types=).with(:ntlm)
223
+
224
+ adapter.request(:get)
225
+ end
201
226
  end
202
227
 
203
228
  describe "username and password" do
@@ -239,8 +264,7 @@ unless RUBY_PLATFORM =~ /java/
239
264
  end
240
265
 
241
266
  it 'to 2 when ssl_version is specified as SSLv2/SSLv23' do
242
- version = OpenSSL::SSL::SSLContext::METHODS.reject { |method| method.match /server|client/ }
243
- version = version.select { |method| method.to_s.match /SSLv2|SSLv23/ }.first
267
+ version = HTTPI::Auth::SSL::SSL_VERSIONS.select { |method| method.to_s.match(/SSLv2|SSLv23/) }.first
244
268
  request.auth.ssl.ssl_version = version
245
269
  curb.expects(:ssl_version=).with(2)
246
270
 
@@ -254,6 +278,16 @@ unless RUBY_PLATFORM =~ /java/
254
278
  adapter.request(:get)
255
279
  end
256
280
  end
281
+ it 'raises error when min_version not nil' do
282
+ request.auth.ssl.min_version = :TLS1_2
283
+ expect{ adapter.request(:get) }.
284
+ to raise_error(HTTPI::NotSupportedError, 'Curb adapter does not support #min_version or #max_version. Please, use #ssl_version instead.')
285
+ end
286
+ it 'raises error when max_version not nil' do
287
+ request.auth.ssl.max_version = :TLS1_2
288
+ expect{ adapter.request(:get) }.
289
+ to raise_error(HTTPI::NotSupportedError, 'Curb adapter does not support #min_version or #max_version. Please, use #ssl_version instead.')
290
+ end
257
291
  end
258
292
 
259
293
  context "(for SSL client auth)" do
@@ -261,13 +295,16 @@ unless RUBY_PLATFORM =~ /java/
261
295
  request = HTTPI::Request.new("http://example.com")
262
296
  request.auth.ssl.cert_key_file = "spec/fixtures/client_key.pem"
263
297
  request.auth.ssl.cert_file = "spec/fixtures/client_cert.pem"
298
+ request.auth.ssl.cert_key_password = 'example'
264
299
  request
265
300
  end
266
301
 
267
302
  it "send certificate regardless of state of SSL verify mode" do
268
303
  request.auth.ssl.verify_mode = :none
304
+ curb.expects(:ssl_verify_host=).with(0) # avoid "SSL peer certificate" error
269
305
  curb.expects(:cert_key=).with(request.auth.ssl.cert_key_file)
270
306
  curb.expects(:cert=).with(request.auth.ssl.cert_file)
307
+ curb.expects(:certpassword=).with(request.auth.ssl.cert_key_password)
271
308
 
272
309
  adapter.request(:get)
273
310
  end
@@ -275,6 +312,7 @@ unless RUBY_PLATFORM =~ /java/
275
312
  it "cert_key, cert and ssl_verify_peer should be set" do
276
313
  curb.expects(:cert_key=).with(request.auth.ssl.cert_key_file)
277
314
  curb.expects(:cert=).with(request.auth.ssl.cert_file)
315
+ curb.expects(:certpassword=).with(request.auth.ssl.cert_key_password)
278
316
  curb.expects(:ssl_verify_peer=).with(true)
279
317
  curb.expects(:certtype=).with(request.auth.ssl.cert_type.to_s.upcase)
280
318