httpi 2.1.1 → 2.2.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5c23ccc97a8d193073d3796267e1cf8152c44d95
4
- data.tar.gz: 151683feedc6b3a4fbbc4564536a2e3fb0c426db
3
+ metadata.gz: 64f90cd54aeecb3d644ddc16fec7b315c1f3b04b
4
+ data.tar.gz: dfd7327d1ec9c29435c45225142e4d7dbb9f69f6
5
5
  SHA512:
6
- metadata.gz: 8fc7555afdfba157961116ba52ba8d1ff6db64d8cf62a02772d2030978be74ebb66f18fea45a21ad6089a0eae8b747735f696eebb625c8be8a99a74f22651ea4
7
- data.tar.gz: ec8e1195056d31a2a57bcaa5603ffad3e76190d7db423db303433ae94260fc1e812788cd658935011c064ed7b9b6780941a5e2c7e55318a357fabe6dc640413a
6
+ metadata.gz: ecd189b6104973f1286423bf498f37849ad37acaab443d108dda5d2d87d663bfd44171dd291506bd4dc8db45ac1fd57fbf90cd107e1b367dae0442e3b7d0f170
7
+ data.tar.gz: 904207471eed6b713d613f97453bc2a8e0abf156aadfde9ed228a93018c31ee3360b58a399f02c06833a769b3275bc3b483e5c69076f938c509617d288571145
@@ -1,11 +1,5 @@
1
1
  language: "ruby"
2
2
  script: "bundle exec rake ci"
3
3
  rvm:
4
- - 1.8.7
5
- - 1.9.2
6
4
  - 1.9.3
7
- - jruby-18mode
8
5
  - jruby-19mode
9
- - rbx-18mode
10
- - rbx-19mode
11
- - ree
@@ -1,3 +1,9 @@
1
+ ### 2.2.0 (edge)
2
+
3
+ * Fix: [#111](https://github.com/savonrb/httpi/pull/111) Check rubyntlm version in a 0.4.0+ compatible way. Thanks to [Carl Zulauf](https://github.com/carlzulauf).
4
+ * Fix: [#109](https://github.com/savonrb/httpi/pull/109) SSL version is set regardless of SSL auth settings. Thanks to [Mike Campbell](https://github.com/mikecmpbll).
5
+ * Feature: [#108](https://github.com/savonrb/httpi/pull/108) Make `rubyntlm` gem, an optional dependency. Thanks to [Tim Jarratt](https://github.com/tjarratt).
6
+
1
7
  ### 2.1.0 (2013-07-22)
2
8
 
3
9
  * Feature: [#75](https://github.com/savonrb/httpi/pull/75) Rack adapter.
@@ -1,27 +1,28 @@
1
- lib = File.expand_path("../lib/", __FILE__)
1
+ lib = File.expand_path('../lib/', __FILE__)
2
2
  $:.unshift lib unless $:.include?(lib)
3
3
 
4
- require "httpi/version"
4
+ require 'httpi/version'
5
5
 
6
6
  Gem::Specification.new do |s|
7
- s.name = "httpi"
7
+ s.name = 'httpi'
8
8
  s.version = HTTPI::VERSION
9
- s.authors = ["Daniel Harrington", "Martin Tepper"]
10
- s.email = "me@rubiii.com"
11
- s.homepage = "http://github.com/savonrb/#{s.name}"
9
+ s.authors = ['Daniel Harrington', 'Martin Tepper']
10
+ s.email = 'me@rubiii.com'
11
+ s.homepage = 'http://github.com/savonrb/#{s.name}'
12
12
  s.summary = "Common interface for Ruby's HTTP libraries"
13
13
  s.description = s.summary
14
14
 
15
15
  s.rubyforge_project = s.name
16
+ s.license = 'MIT'
16
17
 
17
- s.add_dependency "rack"
18
- s.add_dependency "rubyntlm", "~> 0.3.2"
18
+ s.add_dependency 'rack'
19
19
 
20
- s.add_development_dependency "rake", "~> 10.0"
21
- s.add_development_dependency "rspec", "~> 2.12"
22
- s.add_development_dependency "mocha", "~> 0.13"
23
- s.add_development_dependency "puma", "~> 2.3.2"
20
+ s.add_development_dependency 'rubyntlm', '~> 0.3.2'
21
+ s.add_development_dependency 'rake', '~> 10.0'
22
+ s.add_development_dependency 'rspec', '~> 2.14'
23
+ s.add_development_dependency 'mocha', '~> 0.13'
24
+ s.add_development_dependency 'puma', '~> 2.3.2'
24
25
 
25
26
  s.files = `git ls-files`.split("\n")
26
- s.require_path = "lib"
27
+ s.require_path = 'lib'
27
28
  end
@@ -29,7 +29,14 @@ module HTTPI
29
29
  arguments << (@request.body || "")
30
30
  end
31
31
 
32
- client.on_body(&@request.on_body) if @request.on_body
32
+ if @request.on_body
33
+ client.on_body do |data|
34
+ @request.on_body.call(data)
35
+ # curb requires you to return the length of the data read from the block.
36
+ # It allows you to abort the connection by returning a smaller value
37
+ data.length
38
+ end
39
+ end
33
40
 
34
41
  do_request { |client| client.send(*arguments) }
35
42
  rescue Curl::Err::SSLCACertificateError
@@ -58,7 +65,7 @@ module HTTPI
58
65
 
59
66
  setup_http_auth if @request.auth.http?
60
67
  setup_gssnegotiate_auth if @request.auth.gssnegotiate?
61
- setup_ssl_auth if @request.auth.ssl?
68
+ setup_ssl_auth if @request.auth.ssl? || @request.ssl?
62
69
  end
63
70
 
64
71
  def basic_setup
@@ -86,16 +93,19 @@ module HTTPI
86
93
  def setup_ssl_auth
87
94
  ssl = @request.auth.ssl
88
95
 
89
- unless ssl.verify_mode == :none
90
- @client.cacert = ssl.ca_cert_file if ssl.ca_cert_file
91
- @client.certtype = ssl.cert_type.to_s.upcase
92
- end
96
+ if @request.auth.ssl?
97
+ unless ssl.verify_mode == :none
98
+ @client.cacert = ssl.ca_cert_file if ssl.ca_cert_file
99
+ @client.certtype = ssl.cert_type.to_s.upcase
100
+ end
93
101
 
94
- # Send client-side certificate regardless of state of SSL verify mode
95
- @client.cert_key = ssl.cert_key_file
96
- @client.cert = ssl.cert_file
102
+ # Send client-side certificate regardless of state of SSL verify mode
103
+ @client.cert_key = ssl.cert_key_file
104
+ @client.cert = ssl.cert_file
97
105
 
98
- @client.ssl_verify_peer = ssl.verify_mode == :peer
106
+ @client.ssl_verify_peer = ssl.verify_mode == :peer
107
+ end
108
+
99
109
  @client.ssl_version = case ssl.ssl_version
100
110
  when :TLSv1 then 1
101
111
  when :SSLv2 then 2
@@ -66,7 +66,6 @@ module HTTPI
66
66
  opts[:ssl_ca_file] = ssl.ca_cert_file if ssl.ca_cert_file
67
67
  opts[:client_cert] = ssl.cert if ssl.cert
68
68
  opts[:client_key] = ssl.cert_key if ssl.cert_key
69
- opts[:ssl_version] = ssl.ssl_version if ssl.ssl_version
70
69
  end
71
70
 
72
71
  opts
@@ -41,7 +41,7 @@ module HTTPI
41
41
  end
42
42
 
43
43
  setup_auth if @request.auth.http?
44
- setup_ssl_auth if @request.auth.ssl?
44
+ setup_ssl_auth if @request.auth.ssl? || @request.ssl?
45
45
  end
46
46
 
47
47
  def basic_setup
@@ -57,15 +57,18 @@ module HTTPI
57
57
  def setup_ssl_auth
58
58
  ssl = @request.auth.ssl
59
59
 
60
- if ssl.ca_cert_file && ssl.verify_mode != :none
61
- @client.ssl_config.add_trust_ca(ssl.ca_cert_file)
62
- end
60
+ if @request.auth.ssl?
61
+ if ssl.ca_cert_file && ssl.verify_mode != :none
62
+ @client.ssl_config.add_trust_ca(ssl.ca_cert_file)
63
+ end
63
64
 
64
- # Send client-side certificate regardless of state of SSL verify mode
65
- @client.ssl_config.client_cert = ssl.cert
66
- @client.ssl_config.client_key = ssl.cert_key
65
+ # Send client-side certificate regardless of state of SSL verify mode
66
+ @client.ssl_config.client_cert = ssl.cert
67
+ @client.ssl_config.client_key = ssl.cert_key
68
+
69
+ @client.ssl_config.verify_mode = ssl.openssl_verify_mode
70
+ end
67
71
 
68
- @client.ssl_config.verify_mode = ssl.openssl_verify_mode
69
72
  @client.ssl_config.ssl_version = ssl.ssl_version.to_s if ssl.ssl_version
70
73
  end
71
74
 
@@ -2,10 +2,19 @@ require "uri"
2
2
 
3
3
  require "httpi/adapter/base"
4
4
  require "httpi/response"
5
- require 'net/ntlm'
6
5
  require 'kconv'
7
6
  require 'socket'
8
7
 
8
+ begin
9
+ require 'net/ntlm'
10
+ require 'net/ntlm/version' unless Net::NTLM.const_defined?(:VERSION)
11
+ unless Net::NTLM::VERSION::STRING >= '0.3.2'
12
+ raise ArgumentError('Invalid version of rubyntlm. Please use v0.3.2+.')
13
+ end
14
+ rescue LoadError => e
15
+ HTTPI.logger.debug('Net::NTLM is not available. Install via gem install rubyntlm.')
16
+ end
17
+
9
18
  module HTTPI
10
19
  module Adapter
11
20
 
@@ -72,10 +81,14 @@ module HTTPI
72
81
 
73
82
  def setup
74
83
  setup_client
75
- setup_ssl_auth if @request.auth.ssl?
84
+ setup_ssl_auth if @request.auth.ssl? || @request.ssl?
76
85
  end
77
86
 
78
87
  def negotiate_ntlm_auth(http, &requester)
88
+ unless Net.const_defined?(:NTLM)
89
+ HTTPI.logger.fatal('Cannot negotiate ntlm auth if net/ntlm is not present. Perhaps the net/ntlm gem is not installed?')
90
+ end
91
+
79
92
  # first figure out if we should use NTLM or Negotiate
80
93
  nego_auth_response = respond_with(requester.call(http, request_client(:head)))
81
94
  if nego_auth_response.headers['www-authenticate'].include? 'Negotiate'
@@ -102,7 +115,7 @@ module HTTPI
102
115
  if auth_response.headers["WWW-Authenticate"] =~ /(NTLM|Negotiate) (.+)/
103
116
  auth_token = $2
104
117
  ntlm_message = Net::NTLM::Message.decode64(auth_token)
105
-
118
+
106
119
  message_builder = {}
107
120
  # copy the username and password from the authorization parameters
108
121
  message_builder[:user] = @request.auth.ntlm[0]
@@ -110,15 +123,11 @@ module HTTPI
110
123
 
111
124
  # we need to provide a domain in the packet if an only if it was provided by the user in the auth request
112
125
  if @request.auth.ntlm[2]
113
- message_builder[:domain] = Net::NTLM::EncodeUtil.encode_utf16le(@request.auth.ntlm[2].upcase)
126
+ message_builder[:domain] = @request.auth.ntlm[2].upcase
114
127
  else
115
128
  message_builder[:domain] = ''
116
129
  end
117
130
 
118
- # we should also provide the workstation name, currently the rubyntlm provider does not automatically
119
- # set the workstation name
120
- message_builder[:workstation] = Net::NTLM::EncodeUtil.encode_utf16le(Socket.gethostname)
121
-
122
131
  ntlm_response = ntlm_message.response(message_builder ,
123
132
  {:ntlmv2 => true})
124
133
  # Finally add header of Authorization
@@ -137,15 +146,18 @@ module HTTPI
137
146
  def setup_ssl_auth
138
147
  ssl = @request.auth.ssl
139
148
 
140
- unless ssl.verify_mode == :none
141
- @client.ca_file = ssl.ca_cert_file if ssl.ca_cert_file
142
- end
149
+ if @request.auth.ssl?
150
+ unless ssl.verify_mode == :none
151
+ @client.ca_file = ssl.ca_cert_file if ssl.ca_cert_file
152
+ end
143
153
 
144
- # Send client-side certificate regardless of state of SSL verify mode
145
- @client.key = ssl.cert_key
146
- @client.cert = ssl.cert
154
+ # Send client-side certificate regardless of state of SSL verify mode
155
+ @client.key = ssl.cert_key
156
+ @client.cert = ssl.cert
157
+
158
+ @client.verify_mode = ssl.openssl_verify_mode
159
+ end
147
160
 
148
- @client.verify_mode = ssl.openssl_verify_mode
149
161
  @client.ssl_version = ssl.ssl_version if ssl.ssl_version
150
162
  end
151
163
 
@@ -1,5 +1,5 @@
1
1
  module HTTPI
2
2
 
3
- VERSION = "2.1.1"
3
+ VERSION = "2.2.0"
4
4
 
5
5
  end
@@ -21,7 +21,7 @@ unless RUBY_PLATFORM =~ /java/
21
21
  end
22
22
 
23
23
  it "returns a valid HTTPI::Response" do
24
- adapter.request(:get).should match_response(:body => Fixture.xml)
24
+ expect(adapter.request(:get)).to match_response(:body => Fixture.xml)
25
25
  end
26
26
  end
27
27
 
@@ -34,7 +34,7 @@ unless RUBY_PLATFORM =~ /java/
34
34
  end
35
35
 
36
36
  it "returns a valid HTTPI::Response" do
37
- adapter.request(:post).should match_response(:body => Fixture.xml)
37
+ expect(adapter.request(:post)).to match_response(:body => Fixture.xml)
38
38
  end
39
39
  end
40
40
 
@@ -56,7 +56,7 @@ unless RUBY_PLATFORM =~ /java/
56
56
  end
57
57
 
58
58
  it "returns a valid HTTPI::Response" do
59
- adapter.request(:head).should match_response(:body => Fixture.xml)
59
+ expect(adapter.request(:head)).to match_response(:body => Fixture.xml)
60
60
  end
61
61
  end
62
62
 
@@ -69,7 +69,7 @@ unless RUBY_PLATFORM =~ /java/
69
69
  end
70
70
 
71
71
  it "returns a valid HTTPI::Response" do
72
- adapter.request(:put).should match_response(:body => Fixture.xml)
72
+ expect(adapter.request(:put)).to match_response(:body => Fixture.xml)
73
73
  end
74
74
  end
75
75
 
@@ -91,7 +91,7 @@ unless RUBY_PLATFORM =~ /java/
91
91
  end
92
92
 
93
93
  it "returns a valid HTTPI::Response" do
94
- adapter.request(:delete).should match_response(:body => "")
94
+ expect(adapter.request(:delete)).to match_response(:body => "")
95
95
  end
96
96
  end
97
97
 
@@ -218,6 +218,42 @@ unless RUBY_PLATFORM =~ /java/
218
218
  end
219
219
  end
220
220
 
221
+ context "(for SSL without auth)" do
222
+ let(:request) do
223
+ request = HTTPI::Request.new("http://example.com")
224
+ request.ssl = true
225
+ request
226
+ end
227
+
228
+ context 'sets ssl_version' do
229
+ it 'defaults to nil when no ssl_version is specified' do
230
+ curb.expects(:ssl_version=).with(nil)
231
+ adapter.request(:get)
232
+ end
233
+
234
+ it 'to 1 when ssl_version is specified as TLSv1' do
235
+ request.auth.ssl.ssl_version = :TLSv1
236
+ curb.expects(:ssl_version=).with(1)
237
+
238
+ adapter.request(:get)
239
+ end
240
+
241
+ it 'to 2 when ssl_version is specified as SSLv2' do
242
+ request.auth.ssl.ssl_version = :SSLv2
243
+ curb.expects(:ssl_version=).with(2)
244
+
245
+ adapter.request(:get)
246
+ end
247
+
248
+ it 'to 3 when ssl_version is specified as SSLv3' do
249
+ request.auth.ssl.ssl_version = :SSLv3
250
+ curb.expects(:ssl_version=).with(3)
251
+
252
+ adapter.request(:get)
253
+ end
254
+ end
255
+ end
256
+
221
257
  context "(for SSL client auth)" do
222
258
  let(:request) do
223
259
  request = HTTPI::Request.new("http://example.com")
@@ -261,34 +297,6 @@ unless RUBY_PLATFORM =~ /java/
261
297
 
262
298
  adapter.request(:get)
263
299
  end
264
-
265
- context 'sets ssl_version' do
266
- it 'defaults to nil when no ssl_version is specified' do
267
- curb.expects(:ssl_version=).with(nil)
268
- adapter.request(:get)
269
- end
270
-
271
- it 'to 1 when ssl_version is specified as TLSv1' do
272
- request.auth.ssl.ssl_version = :TLSv1
273
- curb.expects(:ssl_version=).with(1)
274
-
275
- adapter.request(:get)
276
- end
277
-
278
- it 'to 2 when ssl_version is specified as SSLv2' do
279
- request.auth.ssl.ssl_version = :SSLv2
280
- curb.expects(:ssl_version=).with(2)
281
-
282
- adapter.request(:get)
283
- end
284
-
285
- it 'to 3 when ssl_version is specified as SSLv3' do
286
- request.auth.ssl.ssl_version = :SSLv3
287
- curb.expects(:ssl_version=).with(3)
288
-
289
- adapter.request(:get)
290
- end
291
- end
292
300
  end
293
301
  end
294
302
 
@@ -24,7 +24,7 @@ begin
24
24
  with(:query => nil, :head => {}, :body => nil).
25
25
  returns(http_message)
26
26
 
27
- adapter.request(:get).should match_response(:body => Fixture.xml)
27
+ expect(adapter.request(:get)).to match_response(:body => Fixture.xml)
28
28
  end
29
29
  end
30
30
 
@@ -35,7 +35,7 @@ begin
35
35
  returns(http_message)
36
36
 
37
37
  request.body = Fixture.xml
38
- adapter.request(:post).should match_response(:body => Fixture.xml)
38
+ expect(adapter.request(:post)).to match_response(:body => Fixture.xml)
39
39
  end
40
40
  end
41
41
 
@@ -45,7 +45,7 @@ begin
45
45
  with(:query => nil, :head => {}, :body => nil).
46
46
  returns(http_message)
47
47
 
48
- adapter.request(:head).should match_response(:body => Fixture.xml)
48
+ expect(adapter.request(:head)).to match_response(:body => Fixture.xml)
49
49
  end
50
50
  end
51
51
 
@@ -56,7 +56,7 @@ begin
56
56
  returns(http_message)
57
57
 
58
58
  request.body = Fixture.xml
59
- adapter.request(:put).should match_response(:body => Fixture.xml)
59
+ expect(adapter.request(:put)).to match_response(:body => Fixture.xml)
60
60
  end
61
61
  end
62
62
 
@@ -66,7 +66,7 @@ begin
66
66
  with(:query => nil, :head => {}, :body => nil).
67
67
  returns(http_message(""))
68
68
 
69
- adapter.request(:delete).should match_response(:body => "")
69
+ expect(adapter.request(:delete)).to match_response(:body => "")
70
70
  end
71
71
  end
72
72
 
@@ -76,7 +76,7 @@ begin
76
76
  with(:query => nil, :head => {}, :body => nil).
77
77
  returns(http_message(""))
78
78
 
79
- adapter.request(:custom).should match_response(:body => "")
79
+ expect(adapter.request(:custom)).to match_response(:body => "")
80
80
  end
81
81
  end
82
82
 
@@ -19,37 +19,37 @@ describe HTTPI::Adapter::Excon do
19
19
  request.headers["X-Header"] = "HTTPI"
20
20
 
21
21
  response = HTTPI.get(request, adapter)
22
- response.body.should include("HTTPI")
22
+ expect(response.body).to include("HTTPI")
23
23
  end
24
24
 
25
25
  it "executes GET requests" do
26
26
  response = HTTPI.get(@server.url, adapter)
27
- response.body.should eq("get")
28
- response.headers["Content-Type"].should eq("text/plain")
27
+ expect(response.body).to eq("get")
28
+ expect(response.headers["Content-Type"]).to eq("text/plain")
29
29
  end
30
30
 
31
31
  it "executes POST requests" do
32
32
  response = HTTPI.post(@server.url, "<some>xml</some>", adapter)
33
- response.body.should eq("post")
34
- response.headers["Content-Type"].should eq("text/plain")
33
+ expect(response.body).to eq("post")
34
+ expect(response.headers["Content-Type"]).to eq("text/plain")
35
35
  end
36
36
 
37
37
  it "executes HEAD requests" do
38
38
  response = HTTPI.head(@server.url, adapter)
39
- response.code.should == 200
40
- response.headers["Content-Type"].should eq("text/plain")
39
+ expect(response.code).to eq(200)
40
+ expect(response.headers["Content-Type"]).to eq("text/plain")
41
41
  end
42
42
 
43
43
  it "executes PUT requests" do
44
44
  response = HTTPI.put(@server.url, "<some>xml</some>", adapter)
45
- response.body.should eq("put")
46
- response.headers["Content-Type"].should eq("text/plain")
45
+ expect(response.body).to eq("put")
46
+ expect(response.headers["Content-Type"]).to eq("text/plain")
47
47
  end
48
48
 
49
49
  it "executes DELETE requests" do
50
50
  response = HTTPI.delete(@server.url, adapter)
51
- response.body.should eq("delete")
52
- response.headers["Content-Type"].should eq("text/plain")
51
+ expect(response.body).to eq("delete")
52
+ expect(response.headers["Content-Type"]).to eq("text/plain")
53
53
  end
54
54
 
55
55
  it "supports basic authentication" do
@@ -57,7 +57,7 @@ describe HTTPI::Adapter::Excon do
57
57
  request.auth.basic("admin", "secret")
58
58
 
59
59
  response = HTTPI.get(request, adapter)
60
- response.body.should eq("basic-auth")
60
+ expect(response.body).to eq("basic-auth")
61
61
  end
62
62
 
63
63
  it "does not support ntlm authentication" do