webmock 3.14.0 → 3.17.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/CI.yml +1 -0
- data/CHANGELOG.md +64 -2
- data/README.md +11 -2
- data/lib/webmock/http_lib_adapters/async_http_client_adapter.rb +6 -1
- data/lib/webmock/http_lib_adapters/curb_adapter.rb +2 -2
- data/lib/webmock/http_lib_adapters/http_rb/client.rb +1 -3
- data/lib/webmock/http_lib_adapters/http_rb/response.rb +4 -1
- data/lib/webmock/http_lib_adapters/http_rb/streamer.rb +4 -2
- data/lib/webmock/http_lib_adapters/http_rb/webmock.rb +6 -2
- data/lib/webmock/http_lib_adapters/net_http.rb +22 -49
- data/lib/webmock/request_pattern.rb +23 -7
- data/lib/webmock/request_signature.rb +2 -2
- data/lib/webmock/request_stub.rb +15 -0
- data/lib/webmock/version.rb +1 -1
- data/lib/webmock/webmock.rb +10 -0
- data/minitest/webmock_spec.rb +1 -1
- data/spec/acceptance/async_http_client/async_http_client_spec.rb +5 -5
- data/spec/acceptance/curb/curb_spec.rb +11 -0
- data/spec/acceptance/em_http_request/em_http_request_spec.rb +1 -1
- data/spec/acceptance/em_http_request/em_http_request_spec_helper.rb +1 -1
- data/spec/acceptance/excon/excon_spec.rb +2 -2
- data/spec/acceptance/net_http/net_http_shared.rb +46 -9
- data/spec/acceptance/net_http/net_http_spec.rb +49 -23
- data/spec/acceptance/net_http/real_net_http_spec.rb +1 -1
- data/spec/acceptance/patron/patron_spec.rb +19 -21
- data/spec/acceptance/shared/allowing_and_disabling_net_connect.rb +14 -14
- data/spec/acceptance/shared/callbacks.rb +2 -2
- data/spec/acceptance/shared/complex_cross_concern_behaviors.rb +1 -1
- data/spec/unit/request_pattern_spec.rb +12 -0
- data/spec/unit/request_signature_spec.rb +21 -1
- data/spec/unit/request_stub_spec.rb +35 -0
- data/spec/unit/response_spec.rb +1 -1
- data/spec/unit/webmock_spec.rb +54 -0
- data/webmock.gemspec +4 -4
- metadata +29 -29
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e4cbe1f0f2f191bea7fda094073e265aeff44e1669d1222da5cb724e5124eb55
|
4
|
+
data.tar.gz: e631266b6f082b93800e815a9dc0aa071a60a89c1f803bf3eee739e6b97820a2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4911f51bd82520812df827796996ab8cf9975f1bee625a158f4644f8c121bbf34172266cd3097ef0609750d51d0c987ea7a645df077f936924f2ea0915f1c0a1
|
7
|
+
data.tar.gz: bc053c6d94f668d75c1e97629dd9ba38f018ffb2355f5cd97e1f5e54015f6adf02c6f9cac2abf6b5c13d7d4fcd69d1bae77b45cffa2b2b8488fa4d0a1c53e1b3
|
data/.github/workflows/CI.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,67 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
# 3.17.1
|
4
|
+
|
5
|
+
* Fixed Syntax Error
|
6
|
+
|
7
|
+
Thanks to [Mark Spangler](https://github.com/mspangler)
|
8
|
+
|
9
|
+
# 3.17.0
|
10
|
+
|
11
|
+
* Minimum required Ruby version is 2.3
|
12
|
+
|
13
|
+
Thanks to [Go Sueyoshi](https://github.com/sue445)
|
14
|
+
|
15
|
+
* When using Net::HTTP, stubbed socket StubSocket#close and StubSocket#closed? behave more like the real sockets.
|
16
|
+
|
17
|
+
Thanks to [Ray Zane](https://github.com/rzane)
|
18
|
+
|
19
|
+
* Added `peeraddr`, `ssl_version` and `cipher` methods to stubbed sockets used by Net::HTTP.
|
20
|
+
|
21
|
+
Thanks to [Ray Zane](https://github.com/rzane)
|
22
|
+
|
23
|
+
* Added support for matching top-level array in JSON request body.
|
24
|
+
|
25
|
+
E.g.
|
26
|
+
|
27
|
+
````
|
28
|
+
stub_request(:post, 'www.example.com').with(body: [{a: 1}])
|
29
|
+
````
|
30
|
+
|
31
|
+
Thanks to [Cedric Sohrauer](https://github.com/cedrics)
|
32
|
+
|
33
|
+
# 3.16.0
|
34
|
+
|
35
|
+
* Fix leaky file descriptors and reuse socket for persistent connections.
|
36
|
+
|
37
|
+
Thanks to [Ray Zane](https://github.com/rzane)
|
38
|
+
|
39
|
+
* Allow specifying for what URIs or hosts, Net::HTTP should connect on start.
|
40
|
+
|
41
|
+
Thanks to [Ray Zane](https://github.com/rzane)
|
42
|
+
|
43
|
+
# 3.15.0
|
44
|
+
|
45
|
+
* fixed async-http adapter on Windows
|
46
|
+
|
47
|
+
Thanks to [Pavel Rosický](https://github.com/ahorek)
|
48
|
+
|
49
|
+
* Support for http.rb >= 5.0.2
|
50
|
+
|
51
|
+
Thanks to [ojab](https://github.com/ojab)
|
52
|
+
|
53
|
+
* Curb adapter supports headers with `:` character in the header value
|
54
|
+
|
55
|
+
Thanks to [Giorgio Gambino](https://github.com/mrbuzz)
|
56
|
+
|
57
|
+
* Support for matching body of JSON or application/x-www-form-urlencoded requests with content type header including charset.
|
58
|
+
|
59
|
+
Thanks to [Timmitry](https://github.com/Timmitry)
|
60
|
+
|
61
|
+
* Prevent double-wrapping http.rb features on non-stubbed requests
|
62
|
+
|
63
|
+
Thanks to [Michael Fairley](https://github.com/michaelfairley)
|
64
|
+
|
3
65
|
# 3.14.0
|
4
66
|
|
5
67
|
* Bump Addressable from 2.3.6 to 2.8.0
|
@@ -605,9 +667,9 @@
|
|
605
667
|
* `WebMock.disable_net_connect` accepts `:allow` option with an object that responds to `#call`, receiving a `URI` object and returning a boolean:
|
606
668
|
|
607
669
|
|
608
|
-
|
670
|
+
denylist = ['google.com', 'facebook.com', 'apple.com']
|
609
671
|
allowed_sites = lambda{|uri|
|
610
|
-
|
672
|
+
denylist.none?{|site| uri.host.include?(site) }
|
611
673
|
}
|
612
674
|
WebMock.disable_net_connect!(:allow => allowed_sites)
|
613
675
|
|
data/README.md
CHANGED
@@ -550,9 +550,9 @@ RestClient.get('sample.org', '/bar') # ===> Failure
|
|
550
550
|
With an object that responds to `#call`, receiving a `URI` object and returning a boolean:
|
551
551
|
|
552
552
|
```ruby
|
553
|
-
|
553
|
+
denylist = ['google.com', 'facebook.com', 'apple.com']
|
554
554
|
allowed_sites = lambda{|uri|
|
555
|
-
|
555
|
+
denylist.none?{|site| uri.host.include?(site) }
|
556
556
|
}
|
557
557
|
WebMock.disable_net_connect!(allow: allowed_sites)
|
558
558
|
|
@@ -1161,6 +1161,15 @@ People who submitted patches and new features or suggested improvements. Many th
|
|
1161
1161
|
* Alex Vondrak
|
1162
1162
|
* Will Storey
|
1163
1163
|
* Eduardo Hernandez
|
1164
|
+
* ojab
|
1165
|
+
* Giorgio Gambino
|
1166
|
+
* Timmitry
|
1167
|
+
* Michael Fairley
|
1168
|
+
* Ray Zane
|
1169
|
+
* Go Sueyoshi
|
1170
|
+
* Cedric Sohrauer
|
1171
|
+
* Akira Matsuda
|
1172
|
+
* Mark Spangler
|
1164
1173
|
|
1165
1174
|
For a full list of contributors you can visit the
|
1166
1175
|
[contributors](https://github.com/bblimke/webmock/contributors) page.
|
@@ -151,7 +151,12 @@ if defined?(Async::HTTP)
|
|
151
151
|
private
|
152
152
|
|
153
153
|
def create_connected_sockets
|
154
|
-
|
154
|
+
pair = begin
|
155
|
+
Async::IO::Socket.pair(Socket::AF_UNIX, Socket::SOCK_STREAM)
|
156
|
+
rescue Errno::EAFNOSUPPORT
|
157
|
+
Async::IO::Socket.pair(Socket::AF_INET, Socket::SOCK_STREAM)
|
158
|
+
end
|
159
|
+
pair.tap do |sockets|
|
155
160
|
sockets.each do |socket|
|
156
161
|
socket.instance_variable_set :@alpn_protocol, nil
|
157
162
|
socket.instance_eval do
|
@@ -5,7 +5,7 @@ rescue LoadError
|
|
5
5
|
end
|
6
6
|
|
7
7
|
if defined?(Curl)
|
8
|
-
WebMock::VersionChecker.new('Curb', Curl::CURB_VERSION, '0.7.16', '0.
|
8
|
+
WebMock::VersionChecker.new('Curb', Curl::CURB_VERSION, '0.7.16', '1.0.1', ['0.8.7']).check_version!
|
9
9
|
|
10
10
|
module WebMock
|
11
11
|
module HttpLibAdapters
|
@@ -128,7 +128,7 @@ if defined?(Curl)
|
|
128
128
|
def headers_as_hash(headers)
|
129
129
|
if headers.is_a?(Array)
|
130
130
|
headers.inject({}) {|hash, header|
|
131
|
-
name, value = header.split(":").map(&:strip)
|
131
|
+
name, value = header.split(":", 2).map(&:strip)
|
132
132
|
hash[name] = value
|
133
133
|
hash
|
134
134
|
}
|
@@ -5,9 +5,7 @@ module HTTP
|
|
5
5
|
def perform(request, options)
|
6
6
|
return __perform__(request, options) unless webmock_enabled?
|
7
7
|
|
8
|
-
|
9
|
-
options.features.each { |_name, feature| response = feature.wrap_response(response) }
|
10
|
-
response
|
8
|
+
WebMockPerform.new(request, options) { __perform__(request, options) }.exec
|
11
9
|
end
|
12
10
|
|
13
11
|
def webmock_enabled?
|
@@ -24,7 +24,10 @@ module HTTP
|
|
24
24
|
elsif HTTP::VERSION < "3.0.0"
|
25
25
|
Body.new(Streamer.new(webmock_response.body), webmock_response.body.encoding)
|
26
26
|
else
|
27
|
-
Body.new(
|
27
|
+
Body.new(
|
28
|
+
Streamer.new(webmock_response.body, encoding: webmock_response.body.encoding),
|
29
|
+
encoding: webmock_response.body.encoding
|
30
|
+
)
|
28
31
|
end
|
29
32
|
|
30
33
|
return new(status, "1.1", headers, body, uri) if HTTP::VERSION < "1.0.0"
|
@@ -1,8 +1,9 @@
|
|
1
1
|
module HTTP
|
2
2
|
class Response
|
3
3
|
class Streamer
|
4
|
-
def initialize(str)
|
4
|
+
def initialize(str, encoding: Encoding::BINARY)
|
5
5
|
@io = StringIO.new str
|
6
|
+
@encoding = encoding
|
6
7
|
end
|
7
8
|
|
8
9
|
def readpartial(size = nil, outbuf = nil)
|
@@ -14,7 +15,8 @@ module HTTP
|
|
14
15
|
end
|
15
16
|
end
|
16
17
|
|
17
|
-
@io.read size, outbuf
|
18
|
+
chunk = @io.read size, outbuf
|
19
|
+
chunk.force_encoding(@encoding) if chunk
|
18
20
|
end
|
19
21
|
|
20
22
|
def close
|
@@ -1,7 +1,8 @@
|
|
1
1
|
module HTTP
|
2
2
|
class WebMockPerform
|
3
|
-
def initialize(request, &perform)
|
3
|
+
def initialize(request, options, &perform)
|
4
4
|
@request = request
|
5
|
+
@options = options
|
5
6
|
@perform = perform
|
6
7
|
@request_signature = nil
|
7
8
|
end
|
@@ -38,7 +39,10 @@ module HTTP
|
|
38
39
|
webmock_response.raise_error_if_any
|
39
40
|
|
40
41
|
invoke_callbacks(webmock_response, real_request: false)
|
41
|
-
::HTTP::Response.from_webmock @request, webmock_response, request_signature
|
42
|
+
response = ::HTTP::Response.from_webmock @request, webmock_response, request_signature
|
43
|
+
|
44
|
+
@options.features.each { |_name, feature| response = feature.wrap_response(response) }
|
45
|
+
response
|
42
46
|
end
|
43
47
|
|
44
48
|
def raise_timeout_error
|
@@ -98,13 +98,8 @@ module WebMock
|
|
98
98
|
after_request.call(response)
|
99
99
|
}
|
100
100
|
if started?
|
101
|
-
|
102
|
-
|
103
|
-
else
|
104
|
-
start_with_connect_without_finish {
|
105
|
-
super_with_after_request.call
|
106
|
-
}
|
107
|
-
end
|
101
|
+
ensure_actual_connection
|
102
|
+
super_with_after_request.call
|
108
103
|
else
|
109
104
|
start_with_connect {
|
110
105
|
super_with_after_request.call
|
@@ -119,32 +114,33 @@ module WebMock
|
|
119
114
|
raise IOError, 'HTTP session already opened' if @started
|
120
115
|
if block_given?
|
121
116
|
begin
|
117
|
+
@socket = Net::HTTP.socket_type.new
|
122
118
|
@started = true
|
123
119
|
return yield(self)
|
124
120
|
ensure
|
125
121
|
do_finish
|
126
122
|
end
|
127
123
|
end
|
124
|
+
@socket = Net::HTTP.socket_type.new
|
128
125
|
@started = true
|
129
126
|
self
|
130
127
|
end
|
131
128
|
|
132
129
|
|
133
|
-
def
|
134
|
-
if
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
end
|
130
|
+
def ensure_actual_connection
|
131
|
+
if @socket.is_a?(StubSocket)
|
132
|
+
@socket&.close
|
133
|
+
@socket = nil
|
134
|
+
do_start
|
139
135
|
end
|
140
|
-
do_start
|
141
|
-
self
|
142
136
|
end
|
143
137
|
|
144
138
|
alias_method :start_with_connect, :start
|
145
139
|
|
146
140
|
def start(&block)
|
147
|
-
|
141
|
+
uri = Addressable::URI.parse(WebMock::NetHTTPUtility.get_uri(self))
|
142
|
+
|
143
|
+
if WebMock.net_http_connect_on_start?(uri)
|
148
144
|
super(&block)
|
149
145
|
else
|
150
146
|
start_without_connect(&block)
|
@@ -169,7 +165,7 @@ module WebMock
|
|
169
165
|
response.extend Net::WebMockHTTPResponse
|
170
166
|
|
171
167
|
if webmock_response.should_timeout
|
172
|
-
raise
|
168
|
+
raise Net::OpenTimeout, "execution expired"
|
173
169
|
end
|
174
170
|
|
175
171
|
webmock_response.raise_error_if_any
|
@@ -179,16 +175,6 @@ module WebMock
|
|
179
175
|
response
|
180
176
|
end
|
181
177
|
|
182
|
-
def timeout_exception
|
183
|
-
if defined?(Net::OpenTimeout)
|
184
|
-
# Ruby 2.x
|
185
|
-
Net::OpenTimeout
|
186
|
-
else
|
187
|
-
# Fallback, if things change
|
188
|
-
Timeout::Error
|
189
|
-
end
|
190
|
-
end
|
191
|
-
|
192
178
|
def build_webmock_response(net_http_response)
|
193
179
|
webmock_response = WebMock::Response.new
|
194
180
|
webmock_response.status = [
|
@@ -240,13 +226,16 @@ class StubSocket #:nodoc:
|
|
240
226
|
attr_accessor :read_timeout, :continue_timeout, :write_timeout
|
241
227
|
|
242
228
|
def initialize(*args)
|
229
|
+
@closed = false
|
243
230
|
end
|
244
231
|
|
245
232
|
def closed?
|
246
|
-
@closed
|
233
|
+
@closed
|
247
234
|
end
|
248
235
|
|
249
236
|
def close
|
237
|
+
@closed = true
|
238
|
+
nil
|
250
239
|
end
|
251
240
|
|
252
241
|
def readuntil(*args)
|
@@ -258,6 +247,10 @@ class StubSocket #:nodoc:
|
|
258
247
|
|
259
248
|
class StubIO
|
260
249
|
def setsockopt(*args); end
|
250
|
+
def peer_cert; end
|
251
|
+
def peeraddr; ["AF_INET", 443, "127.0.0.1", "127.0.0.1"] end
|
252
|
+
def ssl_version; "TLSv1.3" end
|
253
|
+
def cipher; ["TLS_AES_128_GCM_SHA256", "TLSv1.3", 128, 128] end
|
261
254
|
end
|
262
255
|
end
|
263
256
|
|
@@ -325,7 +318,6 @@ module WebMock
|
|
325
318
|
method = request.method.downcase.to_sym
|
326
319
|
|
327
320
|
headers = Hash[*request.to_hash.map {|k,v| [k, v]}.inject([]) {|r,x| r + x}]
|
328
|
-
validate_headers(headers)
|
329
321
|
|
330
322
|
if request.body_stream
|
331
323
|
body = request.body_stream.read
|
@@ -341,7 +333,7 @@ module WebMock
|
|
341
333
|
WebMock::RequestSignature.new(method, uri, body: request.body, headers: headers)
|
342
334
|
end
|
343
335
|
|
344
|
-
def self.get_uri(net_http, path)
|
336
|
+
def self.get_uri(net_http, path = nil)
|
345
337
|
protocol = net_http.use_ssl? ? "https" : "http"
|
346
338
|
|
347
339
|
hostname = net_http.address
|
@@ -350,25 +342,6 @@ module WebMock
|
|
350
342
|
"#{protocol}://#{hostname}:#{net_http.port}#{path}"
|
351
343
|
end
|
352
344
|
|
353
|
-
def self.validate_headers(headers)
|
354
|
-
# For Ruby versions < 2.3.0, if you make a request with headers that are symbols
|
355
|
-
# Net::HTTP raises a NoMethodError
|
356
|
-
#
|
357
|
-
# WebMock normalizes headers when creating a RequestSignature,
|
358
|
-
# and will update all headers from symbols to strings.
|
359
|
-
#
|
360
|
-
# This could create a false positive in a test suite with WebMock.
|
361
|
-
#
|
362
|
-
# So before this point, WebMock raises an ArgumentError if any of the headers are symbols
|
363
|
-
# instead of the cryptic NoMethodError "undefined method `split' ...` from Net::HTTP
|
364
|
-
if Gem::Version.new(RUBY_VERSION.dup) < Gem::Version.new('2.3.0')
|
365
|
-
header_as_symbol = headers.keys.find {|header| header.is_a? Symbol}
|
366
|
-
if header_as_symbol
|
367
|
-
raise ArgumentError.new("Net:HTTP does not accept headers as symbols")
|
368
|
-
end
|
369
|
-
end
|
370
|
-
end
|
371
|
-
|
372
345
|
def self.check_right_http_connection
|
373
346
|
@was_right_http_connection_loaded = defined?(RightHttpConnection)
|
374
347
|
end
|
@@ -281,6 +281,8 @@ module WebMock
|
|
281
281
|
if (@pattern).is_a?(Hash)
|
282
282
|
return true if @pattern.empty?
|
283
283
|
matching_body_hashes?(body_as_hash(body, content_type), @pattern, content_type)
|
284
|
+
elsif (@pattern).is_a?(Array)
|
285
|
+
matching_body_array?(body_as_hash(body, content_type), @pattern, content_type)
|
284
286
|
elsif (@pattern).is_a?(WebMock::Matchers::HashIncludingMatcher)
|
285
287
|
@pattern == body_as_hash(body, content_type)
|
286
288
|
else
|
@@ -344,19 +346,33 @@ module WebMock
|
|
344
346
|
def matching_body_hashes?(query_parameters, pattern, content_type)
|
345
347
|
return false unless query_parameters.is_a?(Hash)
|
346
348
|
return false unless query_parameters.keys.sort == pattern.keys.sort
|
347
|
-
|
349
|
+
|
350
|
+
query_parameters.all? do |key, actual|
|
348
351
|
expected = pattern[key]
|
352
|
+
matching_values(actual, expected, content_type)
|
353
|
+
end
|
354
|
+
end
|
349
355
|
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
+
def matching_body_array?(query_parameters, pattern, content_type)
|
357
|
+
return false unless query_parameters.is_a?(Array)
|
358
|
+
return false unless query_parameters.length == pattern.length
|
359
|
+
|
360
|
+
query_parameters.each_with_index do |actual, index|
|
361
|
+
expected = pattern[index]
|
362
|
+
return false unless matching_values(actual, expected, content_type)
|
356
363
|
end
|
364
|
+
|
357
365
|
true
|
358
366
|
end
|
359
367
|
|
368
|
+
def matching_values(actual, expected, content_type)
|
369
|
+
return matching_body_hashes?(actual, expected, content_type) if actual.is_a?(Hash) && expected.is_a?(Hash)
|
370
|
+
return matching_body_array?(actual, expected, content_type) if actual.is_a?(Array) && expected.is_a?(Array)
|
371
|
+
|
372
|
+
expected = WebMock::Util::ValuesStringifier.stringify_values(expected) if url_encoded_body?(content_type)
|
373
|
+
expected === actual
|
374
|
+
end
|
375
|
+
|
360
376
|
def empty_string?(string)
|
361
377
|
string.nil? || string == ""
|
362
378
|
end
|
@@ -35,11 +35,11 @@ module WebMock
|
|
35
35
|
alias == eql?
|
36
36
|
|
37
37
|
def url_encoded?
|
38
|
-
!!(headers
|
38
|
+
!!(headers&.fetch('Content-Type', nil)&.start_with?('application/x-www-form-urlencoded'))
|
39
39
|
end
|
40
40
|
|
41
41
|
def json_headers?
|
42
|
-
!!(headers
|
42
|
+
!!(headers&.fetch('Content-Type', nil)&.start_with?('application/json'))
|
43
43
|
end
|
44
44
|
|
45
45
|
private
|
data/lib/webmock/request_stub.rb
CHANGED
@@ -24,6 +24,21 @@ module WebMock
|
|
24
24
|
end
|
25
25
|
alias_method :and_return, :to_return
|
26
26
|
|
27
|
+
def to_return_json(*response_hashes)
|
28
|
+
raise ArgumentError, '#to_return_json does not support passing a block' if block_given?
|
29
|
+
|
30
|
+
json_response_hashes = [*response_hashes].flatten.map do |resp_h|
|
31
|
+
headers, body = resp_h.values_at(:headers, :body)
|
32
|
+
resp_h.merge(
|
33
|
+
headers: {content_type: 'application/json'}.merge(headers.to_h),
|
34
|
+
body: body.is_a?(Hash) ? body.to_json : body
|
35
|
+
)
|
36
|
+
end
|
37
|
+
|
38
|
+
to_return(json_response_hashes)
|
39
|
+
end
|
40
|
+
alias_method :and_return_json, :to_return_json
|
41
|
+
|
27
42
|
def to_rack(app, options={})
|
28
43
|
@responses_sequences << ResponsesSequence.new([RackResponse.new(app)])
|
29
44
|
end
|
data/lib/webmock/version.rb
CHANGED
data/lib/webmock/webmock.rb
CHANGED
@@ -70,6 +70,16 @@ module WebMock
|
|
70
70
|
Config.instance.allow && net_connect_explicit_allowed?(Config.instance.allow, uri) )
|
71
71
|
end
|
72
72
|
|
73
|
+
def self.net_http_connect_on_start?(uri)
|
74
|
+
allowed = Config.instance.net_http_connect_on_start || false
|
75
|
+
|
76
|
+
if [true, false].include?(allowed)
|
77
|
+
allowed
|
78
|
+
else
|
79
|
+
net_connect_explicit_allowed?(allowed, uri)
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
73
83
|
def self.net_connect_explicit_allowed?(allowed, uri=nil)
|
74
84
|
case allowed
|
75
85
|
when Array
|
data/minitest/webmock_spec.rb
CHANGED
@@ -20,7 +20,7 @@ require File.expand_path(File.dirname(__FILE__) + '/test_helper')
|
|
20
20
|
end
|
21
21
|
|
22
22
|
it "should raise error on non stubbed request" do
|
23
|
-
|
23
|
+
expect { http_request(:get, "http://www.example.net/") }.must_raise(WebMock::NetConnectNotAllowedError)
|
24
24
|
end
|
25
25
|
|
26
26
|
it "should verify that expected request occured" do
|
@@ -248,7 +248,7 @@ unless RUBY_PLATFORM =~ /java/
|
|
248
248
|
end
|
249
249
|
|
250
250
|
context 'multiple requests' do
|
251
|
-
let(:endpoint) { Async::HTTP::Endpoint.parse('http://www.example.com') }
|
251
|
+
let!(:endpoint) { Async::HTTP::Endpoint.parse('http://www.example.com') }
|
252
252
|
let(:requests_count) { 3 }
|
253
253
|
|
254
254
|
shared_examples :common do
|
@@ -300,13 +300,13 @@ unless RUBY_PLATFORM =~ /java/
|
|
300
300
|
end
|
301
301
|
|
302
302
|
context 'HTTP1 protocol' do
|
303
|
-
let(:protocol) { Async::HTTP::Protocol::HTTP1 }
|
303
|
+
let!(:protocol) { Async::HTTP::Protocol::HTTP1 }
|
304
304
|
|
305
305
|
include_examples :common
|
306
306
|
end
|
307
307
|
|
308
308
|
context 'HTTP2 protocol' do
|
309
|
-
let(:protocol) { Async::HTTP::Protocol::HTTP2 }
|
309
|
+
let!(:protocol) { Async::HTTP::Protocol::HTTP2 }
|
310
310
|
|
311
311
|
include_examples :common
|
312
312
|
end
|
@@ -331,13 +331,13 @@ unless RUBY_PLATFORM =~ /java/
|
|
331
331
|
end
|
332
332
|
|
333
333
|
context 'HTTP1 protocol' do
|
334
|
-
let(:protocol) { Async::HTTP::Protocol::HTTP1 }
|
334
|
+
let!(:protocol) { Async::HTTP::Protocol::HTTP1 }
|
335
335
|
|
336
336
|
include_examples :common
|
337
337
|
end
|
338
338
|
|
339
339
|
context 'HTTP2 protocol' do
|
340
|
-
let(:protocol) { Async::HTTP::Protocol::HTTP2 }
|
340
|
+
let!(:protocol) { Async::HTTP::Protocol::HTTP2 }
|
341
341
|
|
342
342
|
include_examples :common
|
343
343
|
end
|
@@ -383,6 +383,17 @@ unless RUBY_PLATFORM =~ /java/
|
|
383
383
|
expect(c.body).to eq("abc")
|
384
384
|
end
|
385
385
|
|
386
|
+
it "supports headers containing the ':' character" do
|
387
|
+
stub_request(:get, "www.example.com").with(headers: {'Referer'=>'http://www.example.com'}).to_return(body: "abc")
|
388
|
+
|
389
|
+
c = Curl::Easy.new
|
390
|
+
c.url = "http://www.example.com"
|
391
|
+
c.headers = ["Referer: http://www.example.com"]
|
392
|
+
c.http(:GET)
|
393
|
+
expect(c.body).to eq("abc")
|
394
|
+
expect(c.headers).to eq(["Referer: http://www.example.com"])
|
395
|
+
end
|
396
|
+
|
386
397
|
describe 'match request body' do
|
387
398
|
it 'for post' do
|
388
399
|
stub_request(:post, "www.example.com").with(body: 'foo=nhe').to_return(body: "abc")
|
@@ -22,7 +22,7 @@ unless RUBY_PLATFORM =~ /java/
|
|
22
22
|
|
23
23
|
def make_request
|
24
24
|
EM.run do
|
25
|
-
request = EM::HttpRequest.new(http_url).get(redirects: 1)
|
25
|
+
request = EM::HttpRequest.new(http_url, ssl: {verify_peer: true}).get(redirects: 1)
|
26
26
|
request.callback { EM.stop }
|
27
27
|
end
|
28
28
|
end
|
@@ -16,7 +16,7 @@ module EMHttpRequestSpecHelper
|
|
16
16
|
error_set = false
|
17
17
|
uri = Addressable::URI.heuristic_parse(uri)
|
18
18
|
EventMachine.run {
|
19
|
-
request = EventMachine::HttpRequest.new("#{uri.normalize.to_s}")
|
19
|
+
request = EventMachine::HttpRequest.new("#{uri.normalize.to_s}", ssl: {verify_peer: true})
|
20
20
|
http = request.send(method, {
|
21
21
|
timeout: 30,
|
22
22
|
body: options[:body],
|
@@ -20,7 +20,7 @@ describe "Excon" do
|
|
20
20
|
it "should support excon response_block for real requests", net_connect: true do
|
21
21
|
a = []
|
22
22
|
WebMock.allow_net_connect!
|
23
|
-
r = Excon.new('
|
23
|
+
r = Excon.new('https://httpstat.us/200', headers: { "Accept" => "*" }).
|
24
24
|
get(response_block: lambda {|e, remaining, total| a << e}, chunk_size: 1)
|
25
25
|
expect(a).to eq(["2", "0", "0", " ", "O", "K"])
|
26
26
|
expect(r.body).to eq("")
|
@@ -41,7 +41,7 @@ describe "Excon" do
|
|
41
41
|
WebMock.after_request { |_, res|
|
42
42
|
response = res
|
43
43
|
}
|
44
|
-
r = Excon.new('
|
44
|
+
r = Excon.new('https://httpstat.us/200', headers: { "Accept" => "*" }).
|
45
45
|
get(response_block: lambda {|e, remaining, total| a << e}, chunk_size: 1)
|
46
46
|
expect(response.body).to eq("200 OK")
|
47
47
|
expect(a).to eq(["2", "0", "0", " ", "O", "K"])
|