webmock 3.12.0 → 3.12.1

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
  SHA256:
3
- metadata.gz: 6a63f193f9a6fb608fd8e50b8484cd06bf2ee29765cbe0347b74a6a8e82677be
4
- data.tar.gz: bf7b5341dc79029a57c793feb7a7fee2a411a5187f05b1240a3e890842b6300d
3
+ metadata.gz: 9da0e1f9d2507b4f2e84fc1b4fb4dbe513daba94771af7a255199c1f93ac7cbf
4
+ data.tar.gz: ddc87014539d9e40044c2039cd6a0f82d4da9e44035066481c7876e306322922
5
5
  SHA512:
6
- metadata.gz: fbde90987073665a627807880917906602ad10f661f2df95ae038e0e465839bcf98ef76bbc889d0368aa037518ffc0a85239e8cb66a6538600702b0ab72e9cfd
7
- data.tar.gz: b47709a8f994adee29b5d6808580af3980dd45b2dd5a539b678897da4779ee306da8d1137bdca324ad8d314e2d0e8f14cb04ce8ea27de4932002c6b2763f3ec1
6
+ metadata.gz: feb255076779f8f3311238a2f86d3ac4aeac85d904b9ce7972f80df011cffaac9e63322267c8a71cb5ed692b9cbc40fed75dacc16a1a4a377376d4abb89e89d6
7
+ data.tar.gz: e4e881fa8960506b5acec58312e2cd40d2fbc5f4f54487e8893713bba05459ca16b4ec0951c25aee2a239a885fb0a62637faf371b2eb46aca3e0d9ba0f5c1a94
data/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # Changelog
2
2
 
3
+ # 3.12.1
4
+
5
+ * Fixed handling of URIs with IPv6 addresses with square brackets when in Net::HTTP adapter.
6
+
7
+ Thanks to [Johanna Hartmann](https://github.com/JohannaHartmann)
8
+
3
9
  # 3.12.0
4
10
 
5
11
  * Added support for handling custom JSON and XML content types e.g. 'application/vnd.api+json'
data/README.md CHANGED
@@ -1157,6 +1157,7 @@ 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
1160
1161
 
1161
1162
  For a full list of contributors you can visit the
1162
1163
  [contributors](https://github.com/bblimke/webmock/contributors) page.
@@ -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.12.1' unless defined?(::WebMock::VERSION)
3
3
  end
@@ -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
@@ -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
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.12.1
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-03-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: addressable
@@ -422,9 +422,9 @@ licenses:
422
422
  - MIT
423
423
  metadata:
424
424
  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
425
+ changelog_uri: https://github.com/bblimke/webmock/blob/v3.12.1/CHANGELOG.md
426
+ documentation_uri: https://www.rubydoc.info/gems/webmock/3.12.1
427
+ source_code_uri: https://github.com/bblimke/webmock/tree/v3.12.1
428
428
  wiki_uri: https://github.com/bblimke/webmock/wiki
429
429
  post_install_message:
430
430
  rdoc_options: []