webmock 3.12.0 → 3.14.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6a63f193f9a6fb608fd8e50b8484cd06bf2ee29765cbe0347b74a6a8e82677be
4
- data.tar.gz: bf7b5341dc79029a57c793feb7a7fee2a411a5187f05b1240a3e890842b6300d
3
+ metadata.gz: a8f150fbeccca419468dfebe632e3b5d365cb8c2df9a5e2a31e65591298786fb
4
+ data.tar.gz: d92950bc5ae3510e599c40545f3e7a0ebaafa54a698f79a3c82243e240d35948
5
5
  SHA512:
6
- metadata.gz: fbde90987073665a627807880917906602ad10f661f2df95ae038e0e465839bcf98ef76bbc889d0368aa037518ffc0a85239e8cb66a6538600702b0ab72e9cfd
7
- data.tar.gz: b47709a8f994adee29b5d6808580af3980dd45b2dd5a539b678897da4779ee306da8d1137bdca324ad8d314e2d0e8f14cb04ce8ea27de4932002c6b2763f3ec1
6
+ metadata.gz: f58d569f7c633d758cee725e5dafb39edacb74e0017ba9c29de0cad8fe16d1f7740cc30847a9f129f6571232d2ca8172d7fb76a1eb3383e31ee8371472f141f9
7
+ data.tar.gz: 52191c4e12ac3bf79b575f36d58823ea37ab17f83c7a62602889f361eafadabfa4b0b8ffc1f466eee6de53ea77578fc0149a60e14abdd8a7459b651afbeb85d0
data/CHANGELOG.md CHANGED
@@ -1,5 +1,29 @@
1
1
  # Changelog
2
2
 
3
+ # 3.14.0
4
+
5
+ * Bump Addressable from 2.3.6 to 2.8.0
6
+
7
+ Thanks to [Eduardo Hernandez](https://github.com/EduardoGHdez)
8
+
9
+ # 3.13.0
10
+
11
+ * Support http.rb 5.x
12
+
13
+ Thanks to [Will Storey](https://github.com/horgh)
14
+
15
+ # 3.12.2
16
+
17
+ * Fixed em-http-request adapter to avoid calling middleware twice.
18
+
19
+ Thanks to [Alex Vondrak](https://github.com/ajvondrak)
20
+
21
+ # 3.12.1
22
+
23
+ * Fixed handling of URIs with IPv6 addresses with square brackets when in Net::HTTP adapter.
24
+
25
+ Thanks to [Johanna Hartmann](https://github.com/JohannaHartmann)
26
+
3
27
  # 3.12.0
4
28
 
5
29
  * Added support for handling custom JSON and XML content types e.g. 'application/vnd.api+json'
data/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  WebMock
2
2
  =======
3
3
  [![Gem Version](https://badge.fury.io/rb/webmock.svg)](http://badge.fury.io/rb/webmock)
4
- [![Build Status](https://secure.travis-ci.org/bblimke/webmock.svg?branch=master)](http://travis-ci.org/bblimke/webmock)
4
+ [![Build Status](https://github.com/bblimke/webmock/workflows/CI/badge.svg?branch=master)](https://github.com/bblimke/webmock/actions)
5
5
  [![Code Climate](https://codeclimate.com/github/bblimke/webmock/badges/gpa.svg)](https://codeclimate.com/github/bblimke/webmock)
6
6
  [![Mentioned in Awesome Ruby](https://awesome.re/mentioned-badge.svg)](https://github.com/markets/awesome-ruby)
7
7
  [![Inline docs](http://inch-ci.org/github/bblimke/webmock.svg?branch=master)](http://inch-ci.org/github/bblimke/webmock)
@@ -24,19 +24,19 @@ Features
24
24
  Supported HTTP libraries
25
25
  ------------------------
26
26
 
27
- * Async::HTTP::Client
28
- * Curb (currently only Curb::Easy)
29
- * EM-HTTP-Request
30
- * Excon
31
- * HTTPClient
27
+ * [Async::HTTP::Client](https://github.com/socketry/async-http)
28
+ * [Curb](https://github.com/taf2/curb) (currently only Curb::Easy)
29
+ * [EM-HTTP-Request](https://github.com/igrigorik/em-http-request)
30
+ * [Excon](https://github.com/excon/excon)
31
+ * [HTTPClient](https://github.com/nahi/httpclient)
32
32
  * [HTTP Gem (also known as http.rb)](https://github.com/httprb/http)
33
- * Manticore
34
- * Net::HTTP and other libraries based on Net::HTTP, e.g.:
35
- * HTTParty
36
- * REST Client
37
- * RightHttpConnection
38
- * Patron
39
- * Typhoeus (currently only Typhoeus::Hydra)
33
+ * [httpx](https://honeyryderchuck.gitlab.io/httpx/wiki/Webmock-Adapter)
34
+ * [Manticore](https://github.com/cheald/manticore)
35
+ * [Net::HTTP](https://ruby-doc.org/stdlib-2.7.0/libdoc/net/http/rdoc/Net/HTTP.html) and other libraries based on Net::HTTP, e.g.:
36
+ * [HTTParty](https://github.com/jnunemaker/httparty)
37
+ * [REST Client](https://github.com/rest-client/rest-client)
38
+ * [Patron](https://github.com/toland/patron)
39
+ * [Typhoeus](https://github.com/typhoeus/typhoeus) (currently only Typhoeus::Hydra)
40
40
 
41
41
  Supported Ruby Interpreters
42
42
  ---------------------------
@@ -1157,6 +1157,10 @@ People who submitted patches and new features or suggested improvements. Many th
1157
1157
  * Matt Larraz
1158
1158
  * Tony Schneider
1159
1159
  * Niklas Hösl
1160
+ * Johanna Hartmann
1161
+ * Alex Vondrak
1162
+ * Will Storey
1163
+ * Eduardo Hernandez
1160
1164
 
1161
1165
  For a full list of contributors you can visit the
1162
1166
  [contributors](https://github.com/bblimke/webmock/contributors) page.
@@ -99,6 +99,11 @@ if defined?(EventMachine::HttpClient)
99
99
  end
100
100
  end
101
101
 
102
+ def connection_completed
103
+ @state = :response_header
104
+ send_request(request_signature.headers, request_signature.body)
105
+ end
106
+
102
107
  def send_request(head, body)
103
108
  WebMock::RequestRegistry.instance.requested_signatures.put(request_signature)
104
109
 
@@ -164,7 +169,7 @@ if defined?(EventMachine::HttpClient)
164
169
  end
165
170
 
166
171
  def build_request_signature
167
- headers, body = @req.headers, @req.body
172
+ headers, body = build_request, @req.body
168
173
 
169
174
  @conn.middleware.select {|m| m.respond_to?(:request) }.each do |m|
170
175
  headers, body = m.request(self, headers, body)
@@ -178,8 +183,6 @@ if defined?(EventMachine::HttpClient)
178
183
 
179
184
  body = form_encode_body(body) if body.is_a?(Hash)
180
185
 
181
- headers = @req.headers
182
-
183
186
  if headers['authorization'] && headers['authorization'].is_a?(Array)
184
187
  headers['Authorization'] = WebMock::Util::Headers.basic_auth_header(headers.delete('authorization'))
185
188
  end
@@ -11,7 +11,7 @@ module HTTP
11
11
  end
12
12
 
13
13
  class << self
14
- def from_webmock(webmock_response, request_signature = nil)
14
+ def from_webmock(request, webmock_response, request_signature = nil)
15
15
  status = Status.new(webmock_response.status.first)
16
16
  headers = webmock_response.headers || {}
17
17
  uri = normalize_uri(request_signature && request_signature.uri)
@@ -29,12 +29,23 @@ module HTTP
29
29
 
30
30
  return new(status, "1.1", headers, body, uri) if HTTP::VERSION < "1.0.0"
31
31
 
32
+ # 5.0.0 had a breaking change to require request instead of uri.
33
+ if HTTP::VERSION < '5.0.0'
34
+ return new({
35
+ status: status,
36
+ version: "1.1",
37
+ headers: headers,
38
+ body: body,
39
+ uri: uri
40
+ })
41
+ end
42
+
32
43
  new({
33
44
  status: status,
34
45
  version: "1.1",
35
46
  headers: headers,
36
47
  body: body,
37
- uri: uri
48
+ request: request,
38
49
  })
39
50
  end
40
51
 
@@ -38,7 +38,7 @@ module HTTP
38
38
  webmock_response.raise_error_if_any
39
39
 
40
40
  invoke_callbacks(webmock_response, real_request: false)
41
- ::HTTP::Response.from_webmock webmock_response, request_signature
41
+ ::HTTP::Response.from_webmock @request, webmock_response, request_signature
42
42
  end
43
43
 
44
44
  def raise_timeout_error
@@ -313,8 +313,6 @@ module WebMock
313
313
  module NetHTTPUtility
314
314
 
315
315
  def self.request_signature_from_request(net_http, request, body = nil)
316
- protocol = net_http.use_ssl? ? "https" : "http"
317
-
318
316
  path = request.path
319
317
 
320
318
  if path.respond_to?(:request_uri) #https://github.com/bblimke/webmock/issues/288
@@ -323,7 +321,7 @@ module WebMock
323
321
 
324
322
  path = WebMock::Util::URI.heuristic_parse(path).request_uri if path =~ /^http/
325
323
 
326
- uri = "#{protocol}://#{net_http.address}:#{net_http.port}#{path}"
324
+ uri = get_uri(net_http, path)
327
325
  method = request.method.downcase.to_sym
328
326
 
329
327
  headers = Hash[*request.to_hash.map {|k,v| [k, v]}.inject([]) {|r,x| r + x}]
@@ -343,6 +341,15 @@ module WebMock
343
341
  WebMock::RequestSignature.new(method, uri, body: request.body, headers: headers)
344
342
  end
345
343
 
344
+ def self.get_uri(net_http, path)
345
+ protocol = net_http.use_ssl? ? "https" : "http"
346
+
347
+ hostname = net_http.address
348
+ hostname = "[#{hostname}]" if /\A\[.*\]\z/ !~ hostname && /:/ =~ hostname
349
+
350
+ "#{protocol}://#{hostname}:#{net_http.port}#{path}"
351
+ end
352
+
346
353
  def self.validate_headers(headers)
347
354
  # For Ruby versions < 2.3.0, if you make a request with headers that are symbols
348
355
  # Net::HTTP raises a NoMethodError
@@ -1,3 +1,3 @@
1
1
  module WebMock
2
- VERSION = '3.12.0' unless defined?(::WebMock::VERSION)
2
+ VERSION = '3.14.0' unless defined?(::WebMock::VERSION)
3
3
  end
@@ -71,6 +71,35 @@ unless RUBY_PLATFORM =~ /java/
71
71
  end
72
72
  end
73
73
 
74
+ it "only calls request middleware once" do
75
+ stub_request(:get, "www.example.com")
76
+
77
+ middleware = Class.new do
78
+ def self.called!
79
+ @called = called + 1
80
+ end
81
+
82
+ def self.called
83
+ @called || 0
84
+ end
85
+
86
+ def request(client, head, body)
87
+ self.class.called!
88
+ [head, body]
89
+ end
90
+ end
91
+
92
+ EM.run do
93
+ conn = EventMachine::HttpRequest.new('http://www.example.com/')
94
+ conn.use middleware
95
+ http = conn.get
96
+ http.callback do
97
+ expect(middleware.called).to eq(1)
98
+ EM.stop
99
+ end
100
+ end
101
+ end
102
+
74
103
  let(:response_middleware) do
75
104
  Class.new do
76
105
  def response(resp)
@@ -119,6 +148,33 @@ unless RUBY_PLATFORM =~ /java/
119
148
  context 'making a real request', net_connect: true do
120
149
  before { WebMock.allow_net_connect! }
121
150
  include_examples "em-http-request middleware/after_request hook integration"
151
+
152
+ it "only calls request middleware once" do
153
+ middleware = Class.new do
154
+ def self.called!
155
+ @called = called + 1
156
+ end
157
+
158
+ def self.called
159
+ @called || 0
160
+ end
161
+
162
+ def request(client, head, body)
163
+ self.class.called!
164
+ [head, body]
165
+ end
166
+ end
167
+
168
+ EM.run do
169
+ conn = EventMachine::HttpRequest.new(webmock_server_url)
170
+ conn.use middleware
171
+ http = conn.get
172
+ http.callback do
173
+ expect(middleware.called).to eq(1)
174
+ EM.stop
175
+ end
176
+ end
177
+ end
122
178
  end
123
179
 
124
180
  context 'when the request is stubbed' do
@@ -340,4 +340,30 @@ describe "Net:HTTP" do
340
340
  http.request(req, '')
341
341
  end
342
342
  end
343
+
344
+ describe "hostname handling" do
345
+ it "should set brackets around the hostname if it is an IPv6 address" do
346
+ net_http = Net::HTTP.new('b2dc:5bdf:4f0d::3014:e0ca', 80)
347
+ path = '/example.jpg'
348
+ expect(WebMock::NetHTTPUtility.get_uri(net_http, path)).to eq('http://[b2dc:5bdf:4f0d::3014:e0ca]:80/example.jpg')
349
+ end
350
+
351
+ it "should not set brackets around the hostname if it is already wrapped by brackets" do
352
+ net_http = Net::HTTP.new('[b2dc:5bdf:4f0d::3014:e0ca]', 80)
353
+ path = '/example.jpg'
354
+ expect(WebMock::NetHTTPUtility.get_uri(net_http, path)).to eq('http://[b2dc:5bdf:4f0d::3014:e0ca]:80/example.jpg')
355
+ end
356
+
357
+ it "should not set brackets around the hostname if it is an IPv4 address" do
358
+ net_http = Net::HTTP.new('181.152.137.168', 80)
359
+ path = '/example.jpg'
360
+ expect(WebMock::NetHTTPUtility.get_uri(net_http, path)).to eq('http://181.152.137.168:80/example.jpg')
361
+ end
362
+
363
+ it "should not set brackets around the hostname if it is a domain" do
364
+ net_http = Net::HTTP.new('www.example.com', 80)
365
+ path = '/example.jpg'
366
+ expect(WebMock::NetHTTPUtility.get_uri(net_http, path)).to eq('http://www.example.com:80/example.jpg')
367
+ end
368
+ end
343
369
  end
@@ -28,8 +28,8 @@ module PatronSpecHelper
28
28
  end
29
29
  end
30
30
 
31
- status_line_pattern = %r(\AHTTP/(\d+\.\d+)\s+(\d\d\d)\s*([^\r\n]+)?)
32
- message = response.status_line.match(status_line_pattern)[3] || ""
31
+ status_line_pattern = %r(\AHTTP/(\d+(\.\d+)?)\s+(\d\d\d)\s*([^\r\n]+)?)
32
+ message = response.status_line.match(status_line_pattern)[4] || ""
33
33
 
34
34
  OpenStruct.new({
35
35
  body: response.body,
@@ -613,12 +613,12 @@ describe WebMock::RequestPattern do
613
613
  end
614
614
  end
615
615
 
616
- context "standard application/json" do
616
+ context "standard application/xml" do
617
617
  let(:content_type) { 'application/xml' }
618
618
  it_behaves_like "a xml body"
619
619
  end
620
620
 
621
- context "custom json content type" do
621
+ context "custom xml content type" do
622
622
  let(:content_type) { 'application/atom+xml' }
623
623
  it_behaves_like "a xml body"
624
624
  end
data/webmock.gemspec CHANGED
@@ -23,7 +23,7 @@ Gem::Specification.new do |s|
23
23
 
24
24
  s.required_ruby_version = '>= 2.0'
25
25
 
26
- s.add_dependency 'addressable', '>= 2.3.6'
26
+ s.add_dependency 'addressable', '>= 2.8.0'
27
27
  s.add_dependency 'crack', '>= 0.3.2'
28
28
  s.add_dependency 'hashdiff', ['>= 0.4.0', '< 2.0.0']
29
29
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: webmock
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.12.0
4
+ version: 3.14.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bartosz Blimke
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-02-26 00:00:00.000000000 Z
11
+ date: 2021-08-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: addressable
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: 2.3.6
19
+ version: 2.8.0
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: 2.3.6
26
+ version: 2.8.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: crack
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -280,7 +280,6 @@ files:
280
280
  - ".github/workflows/CI.yml"
281
281
  - ".gitignore"
282
282
  - ".rspec-tm"
283
- - ".travis.yml"
284
283
  - CHANGELOG.md
285
284
  - Gemfile
286
285
  - LICENSE
@@ -422,9 +421,9 @@ licenses:
422
421
  - MIT
423
422
  metadata:
424
423
  bug_tracker_uri: https://github.com/bblimke/webmock/issues
425
- changelog_uri: https://github.com/bblimke/webmock/blob/v3.12.0/CHANGELOG.md
426
- documentation_uri: https://www.rubydoc.info/gems/webmock/3.12.0
427
- source_code_uri: https://github.com/bblimke/webmock/tree/v3.12.0
424
+ changelog_uri: https://github.com/bblimke/webmock/blob/v3.14.0/CHANGELOG.md
425
+ documentation_uri: https://www.rubydoc.info/gems/webmock/3.14.0
426
+ source_code_uri: https://github.com/bblimke/webmock/tree/v3.14.0
428
427
  wiki_uri: https://github.com/bblimke/webmock/wiki
429
428
  post_install_message:
430
429
  rdoc_options: []
data/.travis.yml DELETED
@@ -1,24 +0,0 @@
1
- before_install:
2
- - gem update --system -N
3
- rvm:
4
- - 2.5.5
5
- - 2.6.3
6
- - 2.7.0
7
- - rbx-2
8
- - ruby-head
9
- matrix:
10
- include:
11
- - rvm: jruby-9.1.17.0
12
- jdk: openjdk8
13
- - rvm: jruby-9.2.11.1
14
- jdk: openjdk11
15
- - rvm: jruby-head
16
- jdk: openjdk11
17
- allow_failures:
18
- - rvm: jruby-head
19
- - rvm: ruby-head
20
- - rvm: rbx-2
21
- env:
22
- global:
23
- JRUBY_OPTS: "--debug"
24
-