oso-cloud 1.9.0 → 1.9.1.pre.vendored.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 +4 -4
- data/.gitignore +0 -1
- data/Gemfile +5 -0
- data/Gemfile.lock +31 -12
- data/lib/oso/api.rb +18 -2
- data/lib/oso/version.rb +1 -1
- data/vendor/gems/faraday-2.5.2/CHANGELOG.md +574 -0
- data/vendor/gems/faraday-2.5.2/LICENSE.md +20 -0
- data/vendor/gems/faraday-2.5.2/README.md +55 -0
- data/vendor/gems/faraday-2.5.2/Rakefile +7 -0
- data/vendor/gems/faraday-2.5.2/examples/client_spec.rb +119 -0
- data/vendor/gems/faraday-2.5.2/examples/client_test.rb +144 -0
- data/vendor/gems/faraday-2.5.2/lib/faraday/adapter/test.rb +298 -0
- data/vendor/gems/faraday-2.5.2/lib/faraday/adapter.rb +102 -0
- data/vendor/gems/faraday-2.5.2/lib/faraday/adapter_registry.rb +30 -0
- data/vendor/gems/faraday-2.5.2/lib/faraday/connection.rb +561 -0
- data/vendor/gems/faraday-2.5.2/lib/faraday/encoders/flat_params_encoder.rb +105 -0
- data/vendor/gems/faraday-2.5.2/lib/faraday/encoders/nested_params_encoder.rb +183 -0
- data/vendor/gems/faraday-2.5.2/lib/faraday/error.rb +147 -0
- data/vendor/gems/faraday-2.5.2/lib/faraday/logging/formatter.rb +106 -0
- data/vendor/gems/faraday-2.5.2/lib/faraday/methods.rb +6 -0
- data/vendor/gems/faraday-2.5.2/lib/faraday/middleware.rb +30 -0
- data/vendor/gems/faraday-2.5.2/lib/faraday/middleware_registry.rb +83 -0
- data/vendor/gems/faraday-2.5.2/lib/faraday/options/connection_options.rb +22 -0
- data/vendor/gems/faraday-2.5.2/lib/faraday/options/env.rb +199 -0
- data/vendor/gems/faraday-2.5.2/lib/faraday/options/proxy_options.rb +32 -0
- data/vendor/gems/faraday-2.5.2/lib/faraday/options/request_options.rb +22 -0
- data/vendor/gems/faraday-2.5.2/lib/faraday/options/ssl_options.rb +69 -0
- data/vendor/gems/faraday-2.5.2/lib/faraday/options.rb +218 -0
- data/vendor/gems/faraday-2.5.2/lib/faraday/parameters.rb +5 -0
- data/vendor/gems/faraday-2.5.2/lib/faraday/rack_builder.rb +252 -0
- data/vendor/gems/faraday-2.5.2/lib/faraday/request/authorization.rb +49 -0
- data/vendor/gems/faraday-2.5.2/lib/faraday/request/instrumentation.rb +56 -0
- data/vendor/gems/faraday-2.5.2/lib/faraday/request/json.rb +55 -0
- data/vendor/gems/faraday-2.5.2/lib/faraday/request/url_encoded.rb +60 -0
- data/vendor/gems/faraday-2.5.2/lib/faraday/request.rb +136 -0
- data/vendor/gems/faraday-2.5.2/lib/faraday/response/json.rb +54 -0
- data/vendor/gems/faraday-2.5.2/lib/faraday/response/logger.rb +33 -0
- data/vendor/gems/faraday-2.5.2/lib/faraday/response/raise_error.rb +64 -0
- data/vendor/gems/faraday-2.5.2/lib/faraday/response.rb +90 -0
- data/vendor/gems/faraday-2.5.2/lib/faraday/utils/headers.rb +139 -0
- data/vendor/gems/faraday-2.5.2/lib/faraday/utils/params_hash.rb +61 -0
- data/vendor/gems/faraday-2.5.2/lib/faraday/utils.rb +122 -0
- data/vendor/gems/faraday-2.5.2/lib/faraday/version.rb +5 -0
- data/vendor/gems/faraday-2.5.2/lib/faraday.rb +157 -0
- data/vendor/gems/faraday-2.5.2/spec/external_adapters/faraday_specs_setup.rb +14 -0
- data/vendor/gems/faraday-2.5.2/spec/faraday/adapter/test_spec.rb +413 -0
- data/vendor/gems/faraday-2.5.2/spec/faraday/adapter_registry_spec.rb +28 -0
- data/vendor/gems/faraday-2.5.2/spec/faraday/adapter_spec.rb +55 -0
- data/vendor/gems/faraday-2.5.2/spec/faraday/connection_spec.rb +793 -0
- data/vendor/gems/faraday-2.5.2/spec/faraday/error_spec.rb +60 -0
- data/vendor/gems/faraday-2.5.2/spec/faraday/middleware_registry_spec.rb +31 -0
- data/vendor/gems/faraday-2.5.2/spec/faraday/middleware_spec.rb +52 -0
- data/vendor/gems/faraday-2.5.2/spec/faraday/options/env_spec.rb +76 -0
- data/vendor/gems/faraday-2.5.2/spec/faraday/options/options_spec.rb +297 -0
- data/vendor/gems/faraday-2.5.2/spec/faraday/options/proxy_options_spec.rb +44 -0
- data/vendor/gems/faraday-2.5.2/spec/faraday/options/request_options_spec.rb +19 -0
- data/vendor/gems/faraday-2.5.2/spec/faraday/params_encoders/flat_spec.rb +42 -0
- data/vendor/gems/faraday-2.5.2/spec/faraday/params_encoders/nested_spec.rb +150 -0
- data/vendor/gems/faraday-2.5.2/spec/faraday/rack_builder_spec.rb +317 -0
- data/vendor/gems/faraday-2.5.2/spec/faraday/request/authorization_spec.rb +83 -0
- data/vendor/gems/faraday-2.5.2/spec/faraday/request/instrumentation_spec.rb +74 -0
- data/vendor/gems/faraday-2.5.2/spec/faraday/request/json_spec.rb +111 -0
- data/vendor/gems/faraday-2.5.2/spec/faraday/request/url_encoded_spec.rb +93 -0
- data/vendor/gems/faraday-2.5.2/spec/faraday/request_spec.rb +110 -0
- data/vendor/gems/faraday-2.5.2/spec/faraday/response/json_spec.rb +117 -0
- data/vendor/gems/faraday-2.5.2/spec/faraday/response/logger_spec.rb +220 -0
- data/vendor/gems/faraday-2.5.2/spec/faraday/response/raise_error_spec.rb +172 -0
- data/vendor/gems/faraday-2.5.2/spec/faraday/response_spec.rb +75 -0
- data/vendor/gems/faraday-2.5.2/spec/faraday/utils/headers_spec.rb +82 -0
- data/vendor/gems/faraday-2.5.2/spec/faraday/utils_spec.rb +118 -0
- data/vendor/gems/faraday-2.5.2/spec/faraday_spec.rb +37 -0
- data/vendor/gems/faraday-2.5.2/spec/spec_helper.rb +132 -0
- data/vendor/gems/faraday-2.5.2/spec/support/disabling_stub.rb +14 -0
- data/vendor/gems/faraday-2.5.2/spec/support/fake_safe_buffer.rb +15 -0
- data/vendor/gems/faraday-2.5.2/spec/support/helper_methods.rb +96 -0
- data/vendor/gems/faraday-2.5.2/spec/support/shared_examples/adapter.rb +105 -0
- data/vendor/gems/faraday-2.5.2/spec/support/shared_examples/params_encoder.rb +18 -0
- data/vendor/gems/faraday-2.5.2/spec/support/shared_examples/request_method.rb +263 -0
- data/vendor/gems/faraday-2.5.2/spec/support/streaming_response_checker.rb +35 -0
- data/vendor/gems/faraday-net_http-3.0.2/LICENSE.md +21 -0
- data/vendor/gems/faraday-net_http-3.0.2/README.md +57 -0
- data/vendor/gems/faraday-net_http-3.0.2/lib/faraday/adapter/net_http.rb +208 -0
- data/vendor/gems/faraday-net_http-3.0.2/lib/faraday/net_http/version.rb +7 -0
- data/vendor/gems/faraday-net_http-3.0.2/lib/faraday/net_http.rb +10 -0
- data/vendor/gems/faraday-net_http_persistent-2.3.0/LICENSE.md +21 -0
- data/vendor/gems/faraday-net_http_persistent-2.3.0/README.md +66 -0
- data/vendor/gems/faraday-net_http_persistent-2.3.0/lib/faraday/adapter/net_http_persistent.rb +234 -0
- data/vendor/gems/faraday-net_http_persistent-2.3.0/lib/faraday/net_http_persistent/version.rb +7 -0
- data/vendor/gems/faraday-net_http_persistent-2.3.0/lib/faraday/net_http_persistent.rb +18 -0
- data/vendor/gems/faraday-retry-2.0.0/CHANGELOG.md +24 -0
- data/vendor/gems/faraday-retry-2.0.0/LICENSE.md +21 -0
- data/vendor/gems/faraday-retry-2.0.0/README.md +169 -0
- data/vendor/gems/faraday-retry-2.0.0/lib/faraday/retriable_response.rb +8 -0
- data/vendor/gems/faraday-retry-2.0.0/lib/faraday/retry/middleware.rb +254 -0
- data/vendor/gems/faraday-retry-2.0.0/lib/faraday/retry/version.rb +7 -0
- data/vendor/gems/faraday-retry-2.0.0/lib/faraday/retry.rb +13 -0
- data/vendor/gems/net-http-persistent-4.0.5/.autotest +9 -0
- data/vendor/gems/net-http-persistent-4.0.5/.gemtest +0 -0
- data/vendor/gems/net-http-persistent-4.0.5/Gemfile +14 -0
- data/vendor/gems/net-http-persistent-4.0.5/History.txt +460 -0
- data/vendor/gems/net-http-persistent-4.0.5/Manifest.txt +13 -0
- data/vendor/gems/net-http-persistent-4.0.5/README.rdoc +82 -0
- data/vendor/gems/net-http-persistent-4.0.5/Rakefile +25 -0
- data/vendor/gems/net-http-persistent-4.0.5/lib/net/http/persistent/connection.rb +41 -0
- data/vendor/gems/net-http-persistent-4.0.5/lib/net/http/persistent/pool.rb +65 -0
- data/vendor/gems/net-http-persistent-4.0.5/lib/net/http/persistent/timed_stack_multi.rb +79 -0
- data/vendor/gems/net-http-persistent-4.0.5/lib/net/http/persistent.rb +1158 -0
- data/vendor/gems/net-http-persistent-4.0.5/test/test_net_http_persistent.rb +1512 -0
- data/vendor/gems/net-http-persistent-4.0.5/test/test_net_http_persistent_timed_stack_multi.rb +151 -0
- metadata +108 -4
@@ -0,0 +1,1512 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'minitest/autorun'
|
3
|
+
require 'net/http/persistent'
|
4
|
+
require 'stringio'
|
5
|
+
|
6
|
+
HAVE_OPENSSL = defined?(OpenSSL::SSL)
|
7
|
+
|
8
|
+
module Net::HTTP::Persistent::TestConnect
|
9
|
+
def self.included mod
|
10
|
+
mod.send :alias_method, :orig_connect, :connect
|
11
|
+
|
12
|
+
def mod.use_connect which
|
13
|
+
self.send :remove_method, :connect
|
14
|
+
self.send :alias_method, :connect, which
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def host_down_connect
|
19
|
+
raise Errno::EHOSTDOWN
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_connect
|
23
|
+
unless use_ssl? then
|
24
|
+
io = Object.new
|
25
|
+
def io.setsockopt(*a) @setsockopts ||= []; @setsockopts << a end
|
26
|
+
|
27
|
+
@socket = Net::BufferedIO.new io
|
28
|
+
|
29
|
+
return
|
30
|
+
end
|
31
|
+
|
32
|
+
io = open '/dev/null'
|
33
|
+
def io.setsockopt(*a) @setsockopts ||= []; @setsockopts << a end
|
34
|
+
|
35
|
+
@ssl_context ||= OpenSSL::SSL::SSLContext.new
|
36
|
+
|
37
|
+
@ssl_context.verify_mode = OpenSSL::SSL::VERIFY_PEER unless
|
38
|
+
@ssl_context.verify_mode
|
39
|
+
|
40
|
+
s = OpenSSL::SSL::SSLSocket.new io, @ssl_context
|
41
|
+
|
42
|
+
@socket = Net::BufferedIO.new s
|
43
|
+
end
|
44
|
+
|
45
|
+
def refused_connect
|
46
|
+
raise Errno::ECONNREFUSED
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
class Net::HTTP
|
51
|
+
include Net::HTTP::Persistent::TestConnect
|
52
|
+
end
|
53
|
+
|
54
|
+
class TestNetHttpPersistent < Minitest::Test
|
55
|
+
|
56
|
+
def setup
|
57
|
+
@http = Net::HTTP::Persistent.new
|
58
|
+
|
59
|
+
@uri = URI 'http://example.com/path'
|
60
|
+
@uri_v6 = URI 'http://[2001:db8::1]/path'
|
61
|
+
|
62
|
+
ENV.delete 'http_proxy'
|
63
|
+
ENV.delete 'HTTP_PROXY'
|
64
|
+
ENV.delete 'http_proxy_user'
|
65
|
+
ENV.delete 'HTTP_PROXY_USER'
|
66
|
+
ENV.delete 'http_proxy_pass'
|
67
|
+
ENV.delete 'HTTP_PROXY_PASS'
|
68
|
+
ENV.delete 'no_proxy'
|
69
|
+
ENV.delete 'NO_PROXY'
|
70
|
+
|
71
|
+
Net::HTTP.use_connect :test_connect
|
72
|
+
end
|
73
|
+
|
74
|
+
def teardown
|
75
|
+
Net::HTTP.use_connect :orig_connect
|
76
|
+
end
|
77
|
+
|
78
|
+
class BasicConnection
|
79
|
+
attr_accessor :started, :finished, :address, :port, :use_ssl,
|
80
|
+
:read_timeout, :open_timeout, :keep_alive_timeout
|
81
|
+
attr_accessor :ciphers, :ssl_timeout, :ssl_version, :min_version,
|
82
|
+
:max_version, :verify_depth, :verify_mode, :cert_store,
|
83
|
+
:ca_file, :ca_path, :cert, :key
|
84
|
+
attr_reader :req, :debug_output
|
85
|
+
def initialize
|
86
|
+
@started, @finished = 0, 0
|
87
|
+
@address, @port = 'example.com', 80
|
88
|
+
@use_ssl = false
|
89
|
+
end
|
90
|
+
def finish
|
91
|
+
@finished += 1
|
92
|
+
@socket = nil
|
93
|
+
end
|
94
|
+
def finished?
|
95
|
+
@finished >= 1
|
96
|
+
end
|
97
|
+
def pipeline requests, &block
|
98
|
+
requests.map { |r| r.path }
|
99
|
+
end
|
100
|
+
def reset?
|
101
|
+
@started == @finished + 1
|
102
|
+
end
|
103
|
+
def set_debug_output io
|
104
|
+
@debug_output = io
|
105
|
+
end
|
106
|
+
def start
|
107
|
+
@started += 1
|
108
|
+
io = Object.new
|
109
|
+
def io.setsockopt(*a) @setsockopts ||= []; @setsockopts << a end
|
110
|
+
@socket = Net::BufferedIO.new io
|
111
|
+
end
|
112
|
+
def started?
|
113
|
+
@started >= 1
|
114
|
+
end
|
115
|
+
def proxy_address
|
116
|
+
end
|
117
|
+
def proxy_port
|
118
|
+
end
|
119
|
+
def proxy?
|
120
|
+
false
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
def basic_connection
|
125
|
+
raise "#{@uri} is not HTTP" unless @uri.scheme.downcase == 'http'
|
126
|
+
|
127
|
+
net_http_args = [@uri.hostname, @uri.port, nil, nil, nil, nil]
|
128
|
+
|
129
|
+
connection = Net::HTTP::Persistent::Connection.allocate
|
130
|
+
connection.ssl_generation = @http.ssl_generation
|
131
|
+
connection.http = BasicConnection.new
|
132
|
+
connection.reset
|
133
|
+
|
134
|
+
@http.pool.available.push connection, connection_args: net_http_args
|
135
|
+
|
136
|
+
connection
|
137
|
+
end
|
138
|
+
|
139
|
+
def connection uri = @uri
|
140
|
+
@uri = uri
|
141
|
+
|
142
|
+
connection = basic_connection
|
143
|
+
connection.last_use = Time.now
|
144
|
+
|
145
|
+
def (connection.http).request(req)
|
146
|
+
@req = req
|
147
|
+
r = Net::HTTPResponse.allocate
|
148
|
+
r.instance_variable_set :@header, {}
|
149
|
+
def r.http_version() '1.1' end
|
150
|
+
def r.read_body() :read_body end
|
151
|
+
yield r if block_given?
|
152
|
+
r
|
153
|
+
end
|
154
|
+
|
155
|
+
connection
|
156
|
+
end
|
157
|
+
|
158
|
+
def ssl_connection
|
159
|
+
raise "#{@uri} is not HTTPS" unless @uri.scheme.downcase == 'https'
|
160
|
+
|
161
|
+
net_http_args = [@uri.hostname, @uri.port, nil, nil, nil, nil]
|
162
|
+
|
163
|
+
connection = Net::HTTP::Persistent::Connection.allocate
|
164
|
+
connection.ssl_generation = @http.ssl_generation
|
165
|
+
connection.http = BasicConnection.new
|
166
|
+
connection.reset
|
167
|
+
|
168
|
+
@http.pool.available.push connection, connection_args: net_http_args
|
169
|
+
|
170
|
+
connection
|
171
|
+
end
|
172
|
+
|
173
|
+
def test_initialize
|
174
|
+
assert_nil @http.proxy_uri
|
175
|
+
|
176
|
+
assert_empty @http.no_proxy
|
177
|
+
|
178
|
+
skip 'OpenSSL is missing' unless HAVE_OPENSSL
|
179
|
+
|
180
|
+
ssl_session_exists = OpenSSL::SSL.const_defined? :Session
|
181
|
+
|
182
|
+
assert_equal ssl_session_exists, @http.reuse_ssl_sessions
|
183
|
+
end
|
184
|
+
|
185
|
+
def test_initialize_name
|
186
|
+
http = Net::HTTP::Persistent.new name: 'name'
|
187
|
+
assert_equal 'name', http.name
|
188
|
+
end
|
189
|
+
|
190
|
+
def test_initialize_no_ssl_session
|
191
|
+
skip 'OpenSSL is missing' unless HAVE_OPENSSL
|
192
|
+
|
193
|
+
skip "OpenSSL::SSL::Session does not exist on #{RUBY_PLATFORM}" unless
|
194
|
+
OpenSSL::SSL.const_defined? :Session
|
195
|
+
|
196
|
+
ssl_session = OpenSSL::SSL::Session
|
197
|
+
|
198
|
+
OpenSSL::SSL.send :remove_const, :Session
|
199
|
+
|
200
|
+
http = Net::HTTP::Persistent.new
|
201
|
+
|
202
|
+
refute http.reuse_ssl_sessions
|
203
|
+
ensure
|
204
|
+
OpenSSL::SSL.const_set :Session, ssl_session if ssl_session
|
205
|
+
end
|
206
|
+
|
207
|
+
def test_initialize_proxy
|
208
|
+
proxy_uri = URI.parse 'http://proxy.example'
|
209
|
+
|
210
|
+
http = Net::HTTP::Persistent.new proxy: proxy_uri
|
211
|
+
|
212
|
+
assert_equal proxy_uri, http.proxy_uri
|
213
|
+
end
|
214
|
+
|
215
|
+
def test_ca_file_equals
|
216
|
+
@http.ca_file = :ca_file
|
217
|
+
|
218
|
+
assert_equal :ca_file, @http.ca_file
|
219
|
+
assert_equal 1, @http.ssl_generation
|
220
|
+
end
|
221
|
+
|
222
|
+
def test_ca_path_equals
|
223
|
+
@http.ca_path = :ca_path
|
224
|
+
|
225
|
+
assert_equal :ca_path, @http.ca_path
|
226
|
+
assert_equal 1, @http.ssl_generation
|
227
|
+
end
|
228
|
+
|
229
|
+
def test_cert_store_equals
|
230
|
+
@http.cert_store = :cert_store
|
231
|
+
|
232
|
+
assert_equal :cert_store, @http.cert_store
|
233
|
+
assert_equal 1, @http.ssl_generation
|
234
|
+
end
|
235
|
+
|
236
|
+
def test_certificate_equals
|
237
|
+
@http.certificate = :cert
|
238
|
+
|
239
|
+
assert_equal :cert, @http.certificate
|
240
|
+
assert_equal 1, @http.ssl_generation
|
241
|
+
end
|
242
|
+
|
243
|
+
def test_ciphers_equals
|
244
|
+
@http.ciphers = :ciphers
|
245
|
+
|
246
|
+
assert_equal :ciphers, @http.ciphers
|
247
|
+
assert_equal 1, @http.ssl_generation
|
248
|
+
end
|
249
|
+
|
250
|
+
def test_extra_chain_cert_equals
|
251
|
+
skip 'extra_chain_cert is not supported by Net::HTTP' unless Net::HTTP.method_defined?(:extra_chain_cert)
|
252
|
+
@http.extra_chain_cert = :extra_chain_cert
|
253
|
+
|
254
|
+
assert_equal :extra_chain_cert, @http.extra_chain_cert
|
255
|
+
assert_equal 1, @http.ssl_generation
|
256
|
+
end
|
257
|
+
|
258
|
+
def test_connection_for
|
259
|
+
@http.open_timeout = 123
|
260
|
+
@http.read_timeout = 321
|
261
|
+
@http.idle_timeout = 42
|
262
|
+
@http.max_retries = 5
|
263
|
+
|
264
|
+
used = @http.connection_for @uri do |c|
|
265
|
+
assert_kind_of Net::HTTP, c.http
|
266
|
+
|
267
|
+
assert c.http.started?
|
268
|
+
refute c.http.proxy?
|
269
|
+
|
270
|
+
assert_equal 123, c.http.open_timeout
|
271
|
+
assert_equal 321, c.http.read_timeout
|
272
|
+
assert_equal 42, c.http.keep_alive_timeout
|
273
|
+
assert_equal 5, c.http.max_retries if c.http.respond_to?(:max_retries)
|
274
|
+
|
275
|
+
c
|
276
|
+
end
|
277
|
+
|
278
|
+
stored = @http.pool.checkout ['example.com', 80, nil, nil, nil, nil]
|
279
|
+
|
280
|
+
assert_same used, stored
|
281
|
+
end
|
282
|
+
|
283
|
+
def test_connection_for_cached
|
284
|
+
cached = basic_connection
|
285
|
+
cached.http.start
|
286
|
+
|
287
|
+
@http.read_timeout = 5
|
288
|
+
|
289
|
+
@http.connection_for @uri do |c|
|
290
|
+
assert c.http.started?
|
291
|
+
|
292
|
+
assert_equal 5, c.http.read_timeout
|
293
|
+
|
294
|
+
assert_same cached, c
|
295
|
+
end
|
296
|
+
end
|
297
|
+
|
298
|
+
def test_connection_for_closed
|
299
|
+
cached = basic_connection
|
300
|
+
cached.http.start
|
301
|
+
if Socket.const_defined? :TCP_NODELAY then
|
302
|
+
io = Object.new
|
303
|
+
def io.setsockopt(*a) raise IOError, 'closed stream' end
|
304
|
+
cached.instance_variable_set :@socket, Net::BufferedIO.new(io)
|
305
|
+
end
|
306
|
+
|
307
|
+
@http.connection_for @uri do |c|
|
308
|
+
assert c.http.started?
|
309
|
+
|
310
|
+
socket = c.http.instance_variable_get :@socket
|
311
|
+
|
312
|
+
refute_includes socket.io.instance_variables, :@setsockopt
|
313
|
+
refute_includes socket.io.instance_variables, '@setsockopt'
|
314
|
+
end
|
315
|
+
end
|
316
|
+
|
317
|
+
def test_connection_for_debug_output
|
318
|
+
io = StringIO.new
|
319
|
+
@http.debug_output = io
|
320
|
+
|
321
|
+
@http.connection_for @uri do |c|
|
322
|
+
assert c.http.started?
|
323
|
+
assert_equal io, c.http.instance_variable_get(:@debug_output)
|
324
|
+
end
|
325
|
+
end
|
326
|
+
|
327
|
+
def test_connection_for_cached_expire_always
|
328
|
+
cached = basic_connection
|
329
|
+
cached.http.start
|
330
|
+
cached.requests = 10
|
331
|
+
cached.last_use = Time.now # last used right now
|
332
|
+
|
333
|
+
@http.idle_timeout = 0
|
334
|
+
|
335
|
+
@http.connection_for @uri do |c|
|
336
|
+
assert c.http.started?
|
337
|
+
|
338
|
+
assert_same cached, c
|
339
|
+
|
340
|
+
assert_equal 0, c.requests, 'connection reset due to timeout'
|
341
|
+
end
|
342
|
+
end
|
343
|
+
|
344
|
+
def test_connection_for_cached_expire_never
|
345
|
+
cached = basic_connection
|
346
|
+
cached.http.start
|
347
|
+
cached.requests = 10
|
348
|
+
cached.last_use = Time.now # last used right now
|
349
|
+
|
350
|
+
@http.idle_timeout = nil
|
351
|
+
|
352
|
+
@http.connection_for @uri do |c|
|
353
|
+
assert c.http.started?
|
354
|
+
|
355
|
+
assert_same cached, c
|
356
|
+
|
357
|
+
assert_equal 10, c.requests, 'connection reset despite no timeout'
|
358
|
+
end
|
359
|
+
end
|
360
|
+
|
361
|
+
def test_connection_for_cached_expired
|
362
|
+
cached = basic_connection
|
363
|
+
cached.http.start
|
364
|
+
cached.requests = 10
|
365
|
+
cached.last_use = Time.now - 3600
|
366
|
+
|
367
|
+
@http.connection_for @uri do |c|
|
368
|
+
assert c.http.started?
|
369
|
+
|
370
|
+
assert_same cached, c
|
371
|
+
assert_equal 0, cached.requests, 'connection not reset due to timeout'
|
372
|
+
end
|
373
|
+
end
|
374
|
+
|
375
|
+
def test_connection_for_finished_ssl
|
376
|
+
skip 'Broken on Windows' if Gem.win_platform?
|
377
|
+
skip 'OpenSSL is missing' unless HAVE_OPENSSL
|
378
|
+
|
379
|
+
uri = URI.parse 'https://example.com/path'
|
380
|
+
|
381
|
+
@http.connection_for uri do |c|
|
382
|
+
assert c.http.started?
|
383
|
+
assert c.http.use_ssl?
|
384
|
+
|
385
|
+
@http.finish c
|
386
|
+
|
387
|
+
refute c.http.started?
|
388
|
+
end
|
389
|
+
|
390
|
+
@http.connection_for uri do |c2|
|
391
|
+
assert c2.http.started?
|
392
|
+
end
|
393
|
+
end
|
394
|
+
|
395
|
+
def test_connection_for_ipv6
|
396
|
+
@http.connection_for @uri_v6 do |c|
|
397
|
+
assert_equal '2001:db8::1', c.http.address
|
398
|
+
end
|
399
|
+
end
|
400
|
+
|
401
|
+
def test_connection_for_host_down
|
402
|
+
c = basic_connection
|
403
|
+
def (c.http).start; raise Errno::EHOSTDOWN end
|
404
|
+
def (c.http).started?; false end
|
405
|
+
|
406
|
+
e = assert_raises Net::HTTP::Persistent::Error do
|
407
|
+
@http.connection_for @uri do end
|
408
|
+
end
|
409
|
+
|
410
|
+
assert_equal 'host down: example.com:80', e.message
|
411
|
+
end
|
412
|
+
|
413
|
+
def test_connection_for_http_class_with_fakeweb
|
414
|
+
Object.send :const_set, :FakeWeb, nil
|
415
|
+
|
416
|
+
@http.connection_for @uri do |c|
|
417
|
+
assert_instance_of Net::HTTP, c.http
|
418
|
+
end
|
419
|
+
ensure
|
420
|
+
if Object.const_defined?(:FakeWeb) then
|
421
|
+
Object.send :remove_const, :FakeWeb
|
422
|
+
end
|
423
|
+
end
|
424
|
+
|
425
|
+
def test_connection_for_http_class_with_webmock
|
426
|
+
Object.send :const_set, :WebMock, nil
|
427
|
+
@http.connection_for @uri do |c|
|
428
|
+
assert_instance_of Net::HTTP, c.http
|
429
|
+
end
|
430
|
+
ensure
|
431
|
+
if Object.const_defined?(:WebMock) then
|
432
|
+
Object.send :remove_const, :WebMock
|
433
|
+
end
|
434
|
+
end
|
435
|
+
|
436
|
+
def test_connection_for_http_class_with_artifice
|
437
|
+
Object.send :const_set, :Artifice, nil
|
438
|
+
@http.connection_for @uri do |c|
|
439
|
+
assert_instance_of Net::HTTP, c.http
|
440
|
+
end
|
441
|
+
ensure
|
442
|
+
if Object.const_defined?(:Artifice) then
|
443
|
+
Object.send :remove_const, :Artifice
|
444
|
+
end
|
445
|
+
end
|
446
|
+
|
447
|
+
def test_connection_for_name
|
448
|
+
http = Net::HTTP::Persistent.new name: 'name'
|
449
|
+
uri = URI.parse 'http://example/'
|
450
|
+
|
451
|
+
http.connection_for uri do |c|
|
452
|
+
assert c.http.started?
|
453
|
+
end
|
454
|
+
end
|
455
|
+
|
456
|
+
def test_connection_for_proxy
|
457
|
+
uri = URI.parse 'http://proxy.example'
|
458
|
+
uri.user = 'johndoe'
|
459
|
+
uri.password = 'muffins'
|
460
|
+
|
461
|
+
http = Net::HTTP::Persistent.new proxy: uri
|
462
|
+
|
463
|
+
used = http.connection_for @uri do |c|
|
464
|
+
assert c.http.started?
|
465
|
+
assert c.http.proxy?
|
466
|
+
|
467
|
+
c
|
468
|
+
end
|
469
|
+
|
470
|
+
stored = http.pool.checkout ['example.com', 80,
|
471
|
+
'proxy.example', 80,
|
472
|
+
'johndoe', 'muffins']
|
473
|
+
|
474
|
+
assert_same used, stored
|
475
|
+
end
|
476
|
+
|
477
|
+
def test_connection_for_proxy_unescaped
|
478
|
+
uri = URI.parse 'http://proxy.example'
|
479
|
+
uri.user = 'john%40doe'
|
480
|
+
uri.password = 'muf%3Afins'
|
481
|
+
uri.freeze
|
482
|
+
|
483
|
+
http = Net::HTTP::Persistent.new proxy: uri
|
484
|
+
|
485
|
+
http.connection_for @uri do end
|
486
|
+
|
487
|
+
stored = http.pool.checkout ['example.com', 80,
|
488
|
+
'proxy.example', 80,
|
489
|
+
'john@doe', 'muf:fins']
|
490
|
+
|
491
|
+
assert stored
|
492
|
+
end
|
493
|
+
|
494
|
+
def test_connection_for_proxy_host_down
|
495
|
+
Net::HTTP.use_connect :host_down_connect
|
496
|
+
|
497
|
+
uri = URI.parse 'http://proxy.example'
|
498
|
+
uri.user = 'johndoe'
|
499
|
+
uri.password = 'muffins'
|
500
|
+
|
501
|
+
http = Net::HTTP::Persistent.new proxy: uri
|
502
|
+
|
503
|
+
e = assert_raises Net::HTTP::Persistent::Error do
|
504
|
+
http.connection_for @uri do end
|
505
|
+
end
|
506
|
+
|
507
|
+
assert_equal 'host down: proxy.example:80', e.message
|
508
|
+
end
|
509
|
+
|
510
|
+
def test_connection_for_proxy_refused
|
511
|
+
Net::HTTP.use_connect :refused_connect
|
512
|
+
|
513
|
+
uri = URI.parse 'http://proxy.example'
|
514
|
+
uri.user = 'johndoe'
|
515
|
+
uri.password = 'muffins'
|
516
|
+
|
517
|
+
http = Net::HTTP::Persistent.new proxy: uri
|
518
|
+
|
519
|
+
e = assert_raises Net::HTTP::Persistent::Error do
|
520
|
+
http.connection_for @uri do end
|
521
|
+
end
|
522
|
+
|
523
|
+
assert_equal 'connection refused: proxy.example:80', e.message
|
524
|
+
end
|
525
|
+
|
526
|
+
def test_connection_for_no_proxy
|
527
|
+
uri = URI.parse 'http://proxy.example'
|
528
|
+
uri.user = 'johndoe'
|
529
|
+
uri.password = 'muffins'
|
530
|
+
uri.query = 'no_proxy=example.com'
|
531
|
+
|
532
|
+
http = Net::HTTP::Persistent.new proxy: uri
|
533
|
+
|
534
|
+
http.connection_for @uri do |c|
|
535
|
+
assert c.http.started?
|
536
|
+
refute c.http.proxy?
|
537
|
+
end
|
538
|
+
|
539
|
+
stored = http.pool.checkout ['example.com', 80]
|
540
|
+
|
541
|
+
assert stored
|
542
|
+
end
|
543
|
+
|
544
|
+
def test_connection_for_no_proxy_from_env
|
545
|
+
ENV['http_proxy'] = 'proxy.example'
|
546
|
+
ENV['no_proxy'] = 'localhost, example.com,'
|
547
|
+
ENV['proxy_user'] = 'johndoe'
|
548
|
+
ENV['proxy_password'] = 'muffins'
|
549
|
+
|
550
|
+
http = Net::HTTP::Persistent.new proxy: :ENV
|
551
|
+
|
552
|
+
http.connection_for @uri do |c|
|
553
|
+
assert c.http.started?
|
554
|
+
refute c.http.proxy?
|
555
|
+
refute c.http.proxy_from_env?
|
556
|
+
end
|
557
|
+
end
|
558
|
+
|
559
|
+
def test_connection_for_refused
|
560
|
+
Net::HTTP.use_connect :refused_connect
|
561
|
+
|
562
|
+
e = assert_raises Net::HTTP::Persistent::Error do
|
563
|
+
@http.connection_for @uri do end
|
564
|
+
end
|
565
|
+
|
566
|
+
assert_equal 'connection refused: example.com:80', e.message
|
567
|
+
end
|
568
|
+
|
569
|
+
def test_connection_for_ssl
|
570
|
+
skip 'Broken on Windows' if Gem.win_platform?
|
571
|
+
skip 'OpenSSL is missing' unless HAVE_OPENSSL
|
572
|
+
|
573
|
+
uri = URI.parse 'https://example.com/path'
|
574
|
+
|
575
|
+
@http.connection_for uri do |c|
|
576
|
+
assert c.http.started?
|
577
|
+
assert c.http.use_ssl?
|
578
|
+
end
|
579
|
+
end
|
580
|
+
|
581
|
+
def test_connection_for_ssl_cached
|
582
|
+
skip 'OpenSSL is missing' unless HAVE_OPENSSL
|
583
|
+
|
584
|
+
@uri = URI.parse 'https://example.com/path'
|
585
|
+
|
586
|
+
cached = ssl_connection
|
587
|
+
|
588
|
+
@http.connection_for @uri do |c|
|
589
|
+
assert_same cached, c
|
590
|
+
end
|
591
|
+
end
|
592
|
+
|
593
|
+
def test_connection_for_ssl_cached_reconnect
|
594
|
+
skip 'OpenSSL is missing' unless HAVE_OPENSSL
|
595
|
+
|
596
|
+
@uri = URI.parse 'https://example.com/path'
|
597
|
+
|
598
|
+
cached = ssl_connection
|
599
|
+
|
600
|
+
ssl_generation = @http.ssl_generation
|
601
|
+
|
602
|
+
@http.reconnect_ssl
|
603
|
+
|
604
|
+
@http.connection_for @uri do |c|
|
605
|
+
assert_same cached, c
|
606
|
+
refute_equal ssl_generation, c.ssl_generation
|
607
|
+
end
|
608
|
+
end
|
609
|
+
|
610
|
+
def test_connection_for_ssl_case
|
611
|
+
skip 'Broken on Windows' if Gem.win_platform?
|
612
|
+
skip 'OpenSSL is missing' unless HAVE_OPENSSL
|
613
|
+
|
614
|
+
uri = URI.parse 'HTTPS://example.com/path'
|
615
|
+
@http.connection_for uri do |c|
|
616
|
+
assert c.http.started?
|
617
|
+
assert c.http.use_ssl?
|
618
|
+
end
|
619
|
+
end
|
620
|
+
|
621
|
+
def test_connection_for_timeout
|
622
|
+
cached = basic_connection
|
623
|
+
cached.http.start
|
624
|
+
cached.requests = 10
|
625
|
+
cached.last_use = Time.now - 6
|
626
|
+
|
627
|
+
@http.connection_for @uri do |c|
|
628
|
+
assert c.http.started?
|
629
|
+
assert_equal 0, c.requests
|
630
|
+
|
631
|
+
assert_same cached, c
|
632
|
+
end
|
633
|
+
end
|
634
|
+
|
635
|
+
def test_escape
|
636
|
+
assert_nil @http.escape nil
|
637
|
+
|
638
|
+
assert_equal '+%3F', @http.escape(' ?')
|
639
|
+
end
|
640
|
+
|
641
|
+
def test_unescape
|
642
|
+
assert_nil @http.unescape nil
|
643
|
+
|
644
|
+
assert_equal ' ?', @http.unescape('+%3F')
|
645
|
+
end
|
646
|
+
|
647
|
+
def test_expired_eh
|
648
|
+
skip 'Broken on Windows' if Gem.win_platform?
|
649
|
+
c = basic_connection
|
650
|
+
c.requests = 0
|
651
|
+
c.last_use = Time.now - 11
|
652
|
+
|
653
|
+
@http.idle_timeout = 0
|
654
|
+
assert @http.expired? c
|
655
|
+
|
656
|
+
@http.idle_timeout = 10
|
657
|
+
assert @http.expired? c
|
658
|
+
|
659
|
+
@http.idle_timeout = 11
|
660
|
+
assert @http.expired? c
|
661
|
+
|
662
|
+
@http.idle_timeout = 12
|
663
|
+
refute @http.expired? c
|
664
|
+
|
665
|
+
@http.idle_timeout = nil
|
666
|
+
refute @http.expired? c
|
667
|
+
end
|
668
|
+
|
669
|
+
def test_expired_due_to_max_requests
|
670
|
+
c = basic_connection
|
671
|
+
c.requests = 0
|
672
|
+
c.last_use = Time.now
|
673
|
+
|
674
|
+
refute @http.expired? c
|
675
|
+
|
676
|
+
c.requests = 10
|
677
|
+
refute @http.expired? c
|
678
|
+
|
679
|
+
@http.max_requests = 10
|
680
|
+
assert @http.expired? c
|
681
|
+
|
682
|
+
c.requests = 9
|
683
|
+
refute @http.expired? c
|
684
|
+
end
|
685
|
+
|
686
|
+
def test_finish
|
687
|
+
c = basic_connection
|
688
|
+
c.requests = 5
|
689
|
+
c.http.instance_variable_set(:@last_communicated, Process.clock_gettime(Process::CLOCK_MONOTONIC))
|
690
|
+
|
691
|
+
@http.finish c
|
692
|
+
|
693
|
+
refute c.http.started?
|
694
|
+
assert c.http.finished?
|
695
|
+
|
696
|
+
assert_equal 0, c.requests
|
697
|
+
assert_equal Net::HTTP::Persistent::EPOCH, c.last_use
|
698
|
+
assert_nil c.http.instance_variable_get(:@last_communicated)
|
699
|
+
end
|
700
|
+
|
701
|
+
def test_finish_io_error
|
702
|
+
c = basic_connection
|
703
|
+
def (c.http).finish; @finished += 1; raise IOError end
|
704
|
+
c.requests = 5
|
705
|
+
|
706
|
+
@http.finish c
|
707
|
+
|
708
|
+
refute c.http.started?
|
709
|
+
assert c.http.finished?
|
710
|
+
end
|
711
|
+
|
712
|
+
def test_finish_ssl_no_session_reuse
|
713
|
+
http = Net::HTTP.new 'localhost', 443, ssl: true
|
714
|
+
http.instance_variable_set :@ssl_session, :something
|
715
|
+
|
716
|
+
c = Net::HTTP::Persistent::Connection.allocate
|
717
|
+
c.instance_variable_set :@http, http
|
718
|
+
|
719
|
+
@http.reuse_ssl_sessions = false
|
720
|
+
|
721
|
+
@http.finish c
|
722
|
+
|
723
|
+
assert_nil c.http.instance_variable_get :@ssl_session
|
724
|
+
end
|
725
|
+
|
726
|
+
def test_http_version
|
727
|
+
assert_nil @http.http_version @uri
|
728
|
+
|
729
|
+
connection
|
730
|
+
|
731
|
+
@http.request @uri
|
732
|
+
|
733
|
+
assert_equal '1.1', @http.http_version(@uri)
|
734
|
+
end
|
735
|
+
|
736
|
+
def test_http_version_IPv6
|
737
|
+
assert_nil @http.http_version @uri_v6
|
738
|
+
|
739
|
+
connection @uri_v6
|
740
|
+
|
741
|
+
@http.request @uri_v6
|
742
|
+
|
743
|
+
assert_equal '1.1', @http.http_version(@uri_v6)
|
744
|
+
end
|
745
|
+
|
746
|
+
def test_max_retries_equals
|
747
|
+
@http.max_retries = 5
|
748
|
+
|
749
|
+
assert_equal 5, @http.max_retries
|
750
|
+
assert_equal 1, @http.generation
|
751
|
+
end
|
752
|
+
|
753
|
+
def test_normalize_uri
|
754
|
+
assert_equal 'http://example', @http.normalize_uri('example')
|
755
|
+
assert_equal 'http://example', @http.normalize_uri('http://example')
|
756
|
+
assert_equal 'https://example', @http.normalize_uri('https://example')
|
757
|
+
end
|
758
|
+
|
759
|
+
def test_override_haeders
|
760
|
+
assert_empty @http.override_headers
|
761
|
+
|
762
|
+
@http.override_headers['User-Agent'] = 'MyCustomAgent'
|
763
|
+
|
764
|
+
expected = { 'User-Agent' => 'MyCustomAgent' }
|
765
|
+
|
766
|
+
assert_equal expected, @http.override_headers
|
767
|
+
end
|
768
|
+
|
769
|
+
def test_pipeline
|
770
|
+
skip 'net-http-pipeline not installed' unless defined?(Net::HTTP::Pipeline)
|
771
|
+
|
772
|
+
cached = basic_connection
|
773
|
+
cached.http.start
|
774
|
+
|
775
|
+
requests = [
|
776
|
+
Net::HTTP::Get.new((@uri + '1').request_uri),
|
777
|
+
Net::HTTP::Get.new((@uri + '2').request_uri),
|
778
|
+
]
|
779
|
+
|
780
|
+
responses = @http.pipeline @uri, requests
|
781
|
+
|
782
|
+
assert_equal 2, responses.length
|
783
|
+
assert_equal '/1', responses.first
|
784
|
+
assert_equal '/2', responses.last
|
785
|
+
end
|
786
|
+
|
787
|
+
def test_private_key_equals
|
788
|
+
@http.private_key = :private_key
|
789
|
+
|
790
|
+
assert_equal :private_key, @http.private_key
|
791
|
+
assert_equal 1, @http.ssl_generation
|
792
|
+
end
|
793
|
+
|
794
|
+
def test_proxy_equals_env
|
795
|
+
ENV['http_proxy'] = 'proxy.example'
|
796
|
+
|
797
|
+
@http.proxy = :ENV
|
798
|
+
|
799
|
+
assert_equal URI.parse('http://proxy.example'), @http.proxy_uri
|
800
|
+
|
801
|
+
assert_equal 1, @http.generation, 'generation'
|
802
|
+
assert_equal 1, @http.ssl_generation, 'ssl_generation'
|
803
|
+
end
|
804
|
+
|
805
|
+
def test_proxy_equals_nil
|
806
|
+
@http.proxy = nil
|
807
|
+
|
808
|
+
assert_nil @http.proxy_uri
|
809
|
+
|
810
|
+
assert_equal 1, @http.generation, 'generation'
|
811
|
+
assert_equal 1, @http.ssl_generation, 'ssl_generation'
|
812
|
+
end
|
813
|
+
|
814
|
+
def test_proxy_equals_uri
|
815
|
+
proxy_uri = URI.parse 'http://proxy.example'
|
816
|
+
|
817
|
+
@http.proxy = proxy_uri
|
818
|
+
|
819
|
+
assert_equal proxy_uri, @http.proxy_uri
|
820
|
+
end
|
821
|
+
|
822
|
+
def test_proxy_equals_uri_IPv6
|
823
|
+
proxy_uri = @uri_v6
|
824
|
+
|
825
|
+
@http.proxy = proxy_uri
|
826
|
+
|
827
|
+
assert_equal proxy_uri, @http.proxy_uri
|
828
|
+
end
|
829
|
+
|
830
|
+
def test_proxy_from_env
|
831
|
+
ENV['http_proxy'] = 'proxy.example'
|
832
|
+
ENV['http_proxy_user'] = 'johndoe'
|
833
|
+
ENV['http_proxy_pass'] = 'muffins'
|
834
|
+
ENV['NO_PROXY'] = 'localhost,example.com'
|
835
|
+
|
836
|
+
uri = @http.proxy_from_env
|
837
|
+
|
838
|
+
expected = URI.parse 'http://proxy.example'
|
839
|
+
expected.user = 'johndoe'
|
840
|
+
expected.password = 'muffins'
|
841
|
+
expected.query = 'no_proxy=localhost%2Cexample.com'
|
842
|
+
|
843
|
+
assert_equal expected, uri
|
844
|
+
end
|
845
|
+
|
846
|
+
def test_proxy_from_env_lower
|
847
|
+
ENV['http_proxy'] = 'proxy.example'
|
848
|
+
ENV['http_proxy_user'] = 'johndoe'
|
849
|
+
ENV['http_proxy_pass'] = 'muffins'
|
850
|
+
ENV['no_proxy'] = 'localhost,example.com'
|
851
|
+
|
852
|
+
uri = @http.proxy_from_env
|
853
|
+
|
854
|
+
expected = URI.parse 'http://proxy.example'
|
855
|
+
expected.user = 'johndoe'
|
856
|
+
expected.password = 'muffins'
|
857
|
+
expected.query = 'no_proxy=localhost%2Cexample.com'
|
858
|
+
|
859
|
+
assert_equal expected, uri
|
860
|
+
end
|
861
|
+
|
862
|
+
def test_proxy_from_env_nil
|
863
|
+
uri = @http.proxy_from_env
|
864
|
+
|
865
|
+
assert_nil uri
|
866
|
+
|
867
|
+
ENV['http_proxy'] = ''
|
868
|
+
|
869
|
+
uri = @http.proxy_from_env
|
870
|
+
|
871
|
+
assert_nil uri
|
872
|
+
end
|
873
|
+
|
874
|
+
def test_proxy_from_env_no_proxy_star
|
875
|
+
uri = @http.proxy_from_env
|
876
|
+
|
877
|
+
assert_nil uri
|
878
|
+
|
879
|
+
ENV['http_proxy'] = 'proxy.example'
|
880
|
+
ENV['no_proxy'] = '*'
|
881
|
+
|
882
|
+
uri = @http.proxy_from_env
|
883
|
+
|
884
|
+
assert_nil uri
|
885
|
+
end
|
886
|
+
|
887
|
+
def test_proxy_bypass
|
888
|
+
ENV['http_proxy'] = 'proxy.example'
|
889
|
+
ENV['no_proxy'] = 'localhost,example.com:80'
|
890
|
+
|
891
|
+
@http.proxy = :ENV
|
892
|
+
|
893
|
+
assert @http.proxy_bypass? 'localhost', 80
|
894
|
+
assert @http.proxy_bypass? 'localhost', 443
|
895
|
+
assert @http.proxy_bypass? 'LOCALHOST', 80
|
896
|
+
assert @http.proxy_bypass? 'example.com', 80
|
897
|
+
refute @http.proxy_bypass? 'example.com', 443
|
898
|
+
assert @http.proxy_bypass? 'www.example.com', 80
|
899
|
+
refute @http.proxy_bypass? 'www.example.com', 443
|
900
|
+
assert @http.proxy_bypass? 'endingexample.com', 80
|
901
|
+
refute @http.proxy_bypass? 'example.org', 80
|
902
|
+
end
|
903
|
+
|
904
|
+
def test_proxy_bypass_space
|
905
|
+
ENV['http_proxy'] = 'proxy.example'
|
906
|
+
ENV['no_proxy'] = 'localhost, example.com'
|
907
|
+
|
908
|
+
@http.proxy = :ENV
|
909
|
+
|
910
|
+
assert @http.proxy_bypass? 'example.com', 80
|
911
|
+
refute @http.proxy_bypass? 'example.org', 80
|
912
|
+
end
|
913
|
+
|
914
|
+
def test_proxy_bypass_trailing
|
915
|
+
ENV['http_proxy'] = 'proxy.example'
|
916
|
+
ENV['no_proxy'] = 'localhost,example.com,'
|
917
|
+
|
918
|
+
@http.proxy = :ENV
|
919
|
+
|
920
|
+
assert @http.proxy_bypass? 'example.com', 80
|
921
|
+
refute @http.proxy_bypass? 'example.org', 80
|
922
|
+
end
|
923
|
+
|
924
|
+
def test_proxy_bypass_double_comma
|
925
|
+
ENV['http_proxy'] = 'proxy.example'
|
926
|
+
ENV['no_proxy'] = 'localhost,,example.com'
|
927
|
+
|
928
|
+
@http.proxy = :ENV
|
929
|
+
|
930
|
+
assert @http.proxy_bypass? 'example.com', 80
|
931
|
+
refute @http.proxy_bypass? 'example.org', 80
|
932
|
+
end
|
933
|
+
|
934
|
+
def test_reconnect
|
935
|
+
result = @http.reconnect
|
936
|
+
|
937
|
+
assert_equal 1, result
|
938
|
+
end
|
939
|
+
|
940
|
+
def test_reconnect_ssl
|
941
|
+
skip 'OpenSSL is missing' unless HAVE_OPENSSL
|
942
|
+
|
943
|
+
@uri = URI 'https://example.com'
|
944
|
+
now = Time.now
|
945
|
+
|
946
|
+
ssl_http = ssl_connection
|
947
|
+
|
948
|
+
def (ssl_http.http).finish
|
949
|
+
@started = 0
|
950
|
+
end
|
951
|
+
|
952
|
+
used1 = @http.connection_for @uri do |c|
|
953
|
+
c.requests = 1
|
954
|
+
c.last_use = now
|
955
|
+
c
|
956
|
+
end
|
957
|
+
|
958
|
+
assert_equal OpenSSL::SSL::VERIFY_PEER, used1.http.verify_mode
|
959
|
+
|
960
|
+
@http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
961
|
+
@http.reconnect_ssl
|
962
|
+
|
963
|
+
used2 = @http.connection_for @uri do |c|
|
964
|
+
c
|
965
|
+
end
|
966
|
+
|
967
|
+
assert_same used1, used2
|
968
|
+
|
969
|
+
assert_equal OpenSSL::SSL::VERIFY_NONE, used2.http.verify_mode,
|
970
|
+
'verify mode must change'
|
971
|
+
assert_equal 0, used2.requests
|
972
|
+
assert_equal Net::HTTP::Persistent::EPOCH, used2.last_use
|
973
|
+
end
|
974
|
+
|
975
|
+
def test_requestx
|
976
|
+
@http.override_headers['user-agent'] = 'test ua'
|
977
|
+
@http.headers['accept'] = 'text/*'
|
978
|
+
c = connection
|
979
|
+
|
980
|
+
res = @http.request @uri
|
981
|
+
req = c.http.req
|
982
|
+
|
983
|
+
assert_kind_of Net::HTTPResponse, res
|
984
|
+
|
985
|
+
assert_kind_of Net::HTTP::Get, req
|
986
|
+
assert_equal '/path', req.path
|
987
|
+
|
988
|
+
assert_equal 'test ua', req['user-agent']
|
989
|
+
assert_match %r%text/\*%, req['accept']
|
990
|
+
|
991
|
+
assert_equal 'keep-alive', req['connection']
|
992
|
+
assert_equal '30', req['keep-alive']
|
993
|
+
|
994
|
+
# There's some roounding issue on jruby preventing this from passing
|
995
|
+
unless RUBY_PLATFORM == "java"
|
996
|
+
assert_in_delta Time.now, c.last_use
|
997
|
+
end
|
998
|
+
|
999
|
+
assert_equal 1, c.requests
|
1000
|
+
end
|
1001
|
+
|
1002
|
+
def test_request_block
|
1003
|
+
@http.headers['user-agent'] = 'test ua'
|
1004
|
+
c = connection
|
1005
|
+
body = nil
|
1006
|
+
|
1007
|
+
res = @http.request @uri do |r|
|
1008
|
+
body = r.read_body
|
1009
|
+
end
|
1010
|
+
|
1011
|
+
req = c.http.req
|
1012
|
+
|
1013
|
+
assert_kind_of Net::HTTPResponse, res
|
1014
|
+
refute_nil body
|
1015
|
+
|
1016
|
+
assert_kind_of Net::HTTP::Get, req
|
1017
|
+
assert_equal '/path', req.path
|
1018
|
+
assert_equal 'keep-alive', req['connection']
|
1019
|
+
assert_equal '30', req['keep-alive']
|
1020
|
+
assert_match %r%test ua%, req['user-agent']
|
1021
|
+
|
1022
|
+
assert_equal 1, c.requests
|
1023
|
+
end
|
1024
|
+
|
1025
|
+
def test_request_close_1_0
|
1026
|
+
c = connection
|
1027
|
+
|
1028
|
+
class << c.http
|
1029
|
+
remove_method :request
|
1030
|
+
end
|
1031
|
+
|
1032
|
+
def (c.http).request req
|
1033
|
+
@req = req
|
1034
|
+
r = Net::HTTPResponse.allocate
|
1035
|
+
r.instance_variable_set :@header, {}
|
1036
|
+
def r.http_version() '1.0' end
|
1037
|
+
def r.read_body() :read_body end
|
1038
|
+
yield r if block_given?
|
1039
|
+
r
|
1040
|
+
end
|
1041
|
+
|
1042
|
+
request = Net::HTTP::Get.new @uri.request_uri
|
1043
|
+
|
1044
|
+
res = @http.request @uri, request
|
1045
|
+
req = c.http.req
|
1046
|
+
|
1047
|
+
assert_kind_of Net::HTTPResponse, res
|
1048
|
+
|
1049
|
+
assert_kind_of Net::HTTP::Get, req
|
1050
|
+
assert_equal '/path', req.path
|
1051
|
+
assert_equal 'keep-alive', req['connection']
|
1052
|
+
assert_equal '30', req['keep-alive']
|
1053
|
+
|
1054
|
+
assert c.http.finished?
|
1055
|
+
end
|
1056
|
+
|
1057
|
+
def test_request_connection_close_request
|
1058
|
+
c = connection
|
1059
|
+
|
1060
|
+
request = Net::HTTP::Get.new @uri.request_uri
|
1061
|
+
request['connection'] = 'close'
|
1062
|
+
|
1063
|
+
res = @http.request @uri, request
|
1064
|
+
req = c.http.req
|
1065
|
+
|
1066
|
+
assert_kind_of Net::HTTPResponse, res
|
1067
|
+
|
1068
|
+
assert_kind_of Net::HTTP::Get, req
|
1069
|
+
assert_equal '/path', req.path
|
1070
|
+
assert_equal 'close', req['connection']
|
1071
|
+
assert_nil req['keep-alive']
|
1072
|
+
|
1073
|
+
assert c.http.finished?
|
1074
|
+
end
|
1075
|
+
|
1076
|
+
def test_request_connection_close_response
|
1077
|
+
c = connection
|
1078
|
+
|
1079
|
+
class << c.http
|
1080
|
+
remove_method :request
|
1081
|
+
end
|
1082
|
+
|
1083
|
+
def (c.http).request req
|
1084
|
+
@req = req
|
1085
|
+
r = Net::HTTPResponse.allocate
|
1086
|
+
r.instance_variable_set :@header, {}
|
1087
|
+
r['connection'] = 'close'
|
1088
|
+
def r.http_version() '1.1' end
|
1089
|
+
def r.read_body() :read_body end
|
1090
|
+
yield r if block_given?
|
1091
|
+
r
|
1092
|
+
end
|
1093
|
+
|
1094
|
+
request = Net::HTTP::Get.new @uri.request_uri
|
1095
|
+
|
1096
|
+
res = @http.request @uri, request
|
1097
|
+
req = c.http.req
|
1098
|
+
|
1099
|
+
assert_kind_of Net::HTTPResponse, res
|
1100
|
+
|
1101
|
+
assert_kind_of Net::HTTP::Get, req
|
1102
|
+
assert_equal '/path', req.path
|
1103
|
+
assert_equal 'keep-alive', req['connection']
|
1104
|
+
assert_equal '30', req['keep-alive']
|
1105
|
+
|
1106
|
+
assert c.http.finished?
|
1107
|
+
end
|
1108
|
+
|
1109
|
+
def test_request_exception
|
1110
|
+
c = basic_connection
|
1111
|
+
def (c.http).request(*a)
|
1112
|
+
raise Exception, "very bad things happened"
|
1113
|
+
end
|
1114
|
+
|
1115
|
+
assert_raises Exception do
|
1116
|
+
@http.request @uri
|
1117
|
+
end
|
1118
|
+
|
1119
|
+
assert_equal 0, c.requests
|
1120
|
+
assert c.http.finished?
|
1121
|
+
end
|
1122
|
+
|
1123
|
+
def test_request_invalid
|
1124
|
+
c = basic_connection
|
1125
|
+
def (c.http).request(*a) raise Errno::EINVAL, "write" end
|
1126
|
+
|
1127
|
+
e = assert_raises Errno::EINVAL do
|
1128
|
+
@http.request @uri
|
1129
|
+
end
|
1130
|
+
|
1131
|
+
assert_equal 0, c.requests
|
1132
|
+
assert_match %r%Invalid argument - write%, e.message
|
1133
|
+
end
|
1134
|
+
|
1135
|
+
def test_request_post
|
1136
|
+
c = connection
|
1137
|
+
|
1138
|
+
post = Net::HTTP::Post.new @uri.path
|
1139
|
+
|
1140
|
+
@http.request @uri, post
|
1141
|
+
req = c.http.req
|
1142
|
+
|
1143
|
+
assert_same post, req
|
1144
|
+
end
|
1145
|
+
|
1146
|
+
def test_request_setup
|
1147
|
+
@http.override_headers['user-agent'] = 'test ua'
|
1148
|
+
@http.headers['accept'] = 'text/*'
|
1149
|
+
|
1150
|
+
input = Net::HTTP::Post.new '/path'
|
1151
|
+
|
1152
|
+
req = @http.request_setup input
|
1153
|
+
|
1154
|
+
assert_same input, req
|
1155
|
+
assert_equal '/path', req.path
|
1156
|
+
|
1157
|
+
assert_equal 'test ua', req['user-agent']
|
1158
|
+
assert_match %r%text/\*%, req['accept']
|
1159
|
+
|
1160
|
+
assert_equal 'keep-alive', req['connection']
|
1161
|
+
assert_equal '30', req['keep-alive']
|
1162
|
+
end
|
1163
|
+
|
1164
|
+
def test_request_string
|
1165
|
+
@http.override_headers['user-agent'] = 'test ua'
|
1166
|
+
@http.headers['accept'] = 'text/*'
|
1167
|
+
c = connection
|
1168
|
+
|
1169
|
+
res = @http.request @uri.to_s
|
1170
|
+
req = c.http.req
|
1171
|
+
|
1172
|
+
assert_kind_of Net::HTTPResponse, res
|
1173
|
+
|
1174
|
+
assert_kind_of Net::HTTP::Get, req
|
1175
|
+
assert_equal '/path', req.path
|
1176
|
+
|
1177
|
+
assert_equal 1, c.requests
|
1178
|
+
end
|
1179
|
+
|
1180
|
+
def test_request_setup_uri
|
1181
|
+
uri = @uri + '?a=b'
|
1182
|
+
|
1183
|
+
req = @http.request_setup uri
|
1184
|
+
|
1185
|
+
assert_kind_of Net::HTTP::Get, req
|
1186
|
+
assert_equal '/path?a=b', req.path
|
1187
|
+
end
|
1188
|
+
|
1189
|
+
def test_reset
|
1190
|
+
c = basic_connection
|
1191
|
+
c.http.start
|
1192
|
+
c.last_use = Time.now
|
1193
|
+
c.requests = 5
|
1194
|
+
|
1195
|
+
@http.reset c
|
1196
|
+
|
1197
|
+
assert c.http.started?
|
1198
|
+
assert c.http.finished?
|
1199
|
+
assert c.http.reset?
|
1200
|
+
assert_equal 0, c.requests
|
1201
|
+
assert_equal Net::HTTP::Persistent::EPOCH, c.last_use
|
1202
|
+
end
|
1203
|
+
|
1204
|
+
def test_reset_host_down
|
1205
|
+
c = basic_connection
|
1206
|
+
c.last_use = Time.now
|
1207
|
+
def (c.http).start; raise Errno::EHOSTDOWN end
|
1208
|
+
c.requests = 5
|
1209
|
+
|
1210
|
+
e = assert_raises Net::HTTP::Persistent::Error do
|
1211
|
+
@http.reset c
|
1212
|
+
end
|
1213
|
+
|
1214
|
+
assert_match %r%host down%, e.message
|
1215
|
+
assert_match __FILE__, e.backtrace.first
|
1216
|
+
end
|
1217
|
+
|
1218
|
+
def test_reset_io_error
|
1219
|
+
c = basic_connection
|
1220
|
+
c.last_use = Time.now
|
1221
|
+
c.requests = 5
|
1222
|
+
|
1223
|
+
@http.reset c
|
1224
|
+
|
1225
|
+
assert c.http.started?
|
1226
|
+
assert c.http.finished?
|
1227
|
+
end
|
1228
|
+
|
1229
|
+
def test_reset_refused
|
1230
|
+
c = basic_connection
|
1231
|
+
c.last_use = Time.now
|
1232
|
+
def (c.http).start; raise Errno::ECONNREFUSED end
|
1233
|
+
c.requests = 5
|
1234
|
+
|
1235
|
+
e = assert_raises Net::HTTP::Persistent::Error do
|
1236
|
+
@http.reset c
|
1237
|
+
end
|
1238
|
+
|
1239
|
+
assert_match %r%connection refused%, e.message
|
1240
|
+
assert_match __FILE__, e.backtrace.first
|
1241
|
+
end
|
1242
|
+
|
1243
|
+
def test_shutdown
|
1244
|
+
c = connection
|
1245
|
+
|
1246
|
+
orig = @http
|
1247
|
+
@http = Net::HTTP::Persistent.new name: 'name'
|
1248
|
+
c2 = connection
|
1249
|
+
|
1250
|
+
orig.shutdown
|
1251
|
+
|
1252
|
+
@http = orig
|
1253
|
+
|
1254
|
+
assert c.http.finished?, 'last-generation connection must be finished'
|
1255
|
+
refute c2.http.finished?, 'present generation connection must not be finished'
|
1256
|
+
end
|
1257
|
+
|
1258
|
+
def test_ssl
|
1259
|
+
skip 'OpenSSL is missing' unless HAVE_OPENSSL
|
1260
|
+
|
1261
|
+
@http.verify_callback = :callback
|
1262
|
+
c = Net::HTTP.new 'localhost', 80
|
1263
|
+
|
1264
|
+
@http.ssl c
|
1265
|
+
|
1266
|
+
assert c.use_ssl?
|
1267
|
+
assert_equal OpenSSL::SSL::VERIFY_PEER, c.verify_mode
|
1268
|
+
assert_kind_of OpenSSL::X509::Store, c.cert_store
|
1269
|
+
assert_nil c.verify_callback
|
1270
|
+
assert_nil c.verify_hostname if c.respond_to?(:verify_hostname)
|
1271
|
+
end
|
1272
|
+
|
1273
|
+
def test_ssl_ca_file
|
1274
|
+
skip 'OpenSSL is missing' unless HAVE_OPENSSL
|
1275
|
+
|
1276
|
+
@http.ca_file = 'ca_file'
|
1277
|
+
@http.verify_callback = :callback
|
1278
|
+
c = Net::HTTP.new 'localhost', 80
|
1279
|
+
|
1280
|
+
@http.ssl c
|
1281
|
+
|
1282
|
+
assert c.use_ssl?
|
1283
|
+
assert_equal OpenSSL::SSL::VERIFY_PEER, c.verify_mode
|
1284
|
+
assert_equal :callback, c.verify_callback
|
1285
|
+
end
|
1286
|
+
|
1287
|
+
def test_ssl_ca_path
|
1288
|
+
skip 'OpenSSL is missing' unless HAVE_OPENSSL
|
1289
|
+
|
1290
|
+
@http.ca_path = 'ca_path'
|
1291
|
+
@http.verify_callback = :callback
|
1292
|
+
c = Net::HTTP.new 'localhost', 80
|
1293
|
+
|
1294
|
+
@http.ssl c
|
1295
|
+
|
1296
|
+
assert c.use_ssl?
|
1297
|
+
assert_equal OpenSSL::SSL::VERIFY_PEER, c.verify_mode
|
1298
|
+
assert_equal :callback, c.verify_callback
|
1299
|
+
end
|
1300
|
+
|
1301
|
+
def test_ssl_cert_store
|
1302
|
+
skip 'OpenSSL is missing' unless HAVE_OPENSSL
|
1303
|
+
|
1304
|
+
store = OpenSSL::X509::Store.new
|
1305
|
+
@http.cert_store = store
|
1306
|
+
|
1307
|
+
c = Net::HTTP.new 'localhost', 80
|
1308
|
+
|
1309
|
+
@http.ssl c
|
1310
|
+
|
1311
|
+
assert c.use_ssl?
|
1312
|
+
assert_equal store, c.cert_store
|
1313
|
+
end
|
1314
|
+
|
1315
|
+
def test_ssl_cert_store_default
|
1316
|
+
skip 'OpenSSL is missing' unless HAVE_OPENSSL
|
1317
|
+
|
1318
|
+
@http.verify_mode = OpenSSL::SSL::VERIFY_PEER
|
1319
|
+
|
1320
|
+
c = Net::HTTP.new 'localhost', 80
|
1321
|
+
|
1322
|
+
@http.ssl c
|
1323
|
+
|
1324
|
+
assert c.use_ssl?
|
1325
|
+
assert c.cert_store
|
1326
|
+
end
|
1327
|
+
|
1328
|
+
def test_ssl_certificate
|
1329
|
+
skip 'OpenSSL is missing' unless HAVE_OPENSSL
|
1330
|
+
|
1331
|
+
@http.certificate = :cert
|
1332
|
+
@http.private_key = :key
|
1333
|
+
c = Net::HTTP.new 'localhost', 80
|
1334
|
+
|
1335
|
+
@http.ssl c
|
1336
|
+
|
1337
|
+
assert c.use_ssl?
|
1338
|
+
assert_equal :cert, c.cert
|
1339
|
+
assert_equal :key, c.key
|
1340
|
+
end
|
1341
|
+
|
1342
|
+
def test_ssl_verify_mode
|
1343
|
+
skip 'OpenSSL is missing' unless HAVE_OPENSSL
|
1344
|
+
|
1345
|
+
@http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
1346
|
+
c = Net::HTTP.new 'localhost', 80
|
1347
|
+
|
1348
|
+
@http.ssl c
|
1349
|
+
|
1350
|
+
assert c.use_ssl?
|
1351
|
+
assert_equal OpenSSL::SSL::VERIFY_NONE, c.verify_mode
|
1352
|
+
end
|
1353
|
+
|
1354
|
+
def test_ssl_enable_verify_hostname
|
1355
|
+
skip 'OpenSSL is missing' unless HAVE_OPENSSL
|
1356
|
+
|
1357
|
+
@http.verify_hostname = true
|
1358
|
+
c = Net::HTTP.new 'localhost', 80
|
1359
|
+
|
1360
|
+
skip 'net/http doesn\'t provide verify_hostname= method' unless
|
1361
|
+
c.respond_to?(:verify_hostname=)
|
1362
|
+
|
1363
|
+
@http.ssl c
|
1364
|
+
|
1365
|
+
assert c.use_ssl?
|
1366
|
+
assert c.verify_hostname
|
1367
|
+
end
|
1368
|
+
|
1369
|
+
def test_ssl_disable_verify_hostname
|
1370
|
+
skip 'OpenSSL is missing' unless HAVE_OPENSSL
|
1371
|
+
|
1372
|
+
@http.verify_hostname = false
|
1373
|
+
c = Net::HTTP.new 'localhost', 80
|
1374
|
+
|
1375
|
+
skip 'net/http doesn\'t provide verify_hostname= method' unless
|
1376
|
+
c.respond_to?(:verify_hostname=)
|
1377
|
+
|
1378
|
+
@http.ssl c
|
1379
|
+
|
1380
|
+
assert c.use_ssl?
|
1381
|
+
assert c.verify_hostname == false
|
1382
|
+
end
|
1383
|
+
|
1384
|
+
def test_ssl_extra_chain_cert
|
1385
|
+
skip 'OpenSSL is missing' unless HAVE_OPENSSL
|
1386
|
+
skip 'extra_chain_cert is not supported by Net::HTTP' unless Net::HTTP.method_defined?(:extra_chain_cert)
|
1387
|
+
|
1388
|
+
@http.extra_chain_cert = :extra_chain_cert
|
1389
|
+
c = Net::HTTP.new 'localhost', 80
|
1390
|
+
|
1391
|
+
@http.ssl c
|
1392
|
+
|
1393
|
+
assert c.use_ssl?
|
1394
|
+
assert_equal :extra_chain_cert, c.extra_chain_cert
|
1395
|
+
end
|
1396
|
+
|
1397
|
+
def test_ssl_warning
|
1398
|
+
skip 'OpenSSL is missing' unless HAVE_OPENSSL
|
1399
|
+
|
1400
|
+
begin
|
1401
|
+
orig_verify_peer = OpenSSL::SSL::VERIFY_PEER
|
1402
|
+
OpenSSL::SSL.send :remove_const, :VERIFY_PEER
|
1403
|
+
OpenSSL::SSL.send :const_set, :VERIFY_PEER, OpenSSL::SSL::VERIFY_NONE
|
1404
|
+
|
1405
|
+
c = Net::HTTP.new 'localhost', 80
|
1406
|
+
|
1407
|
+
out, err = capture_io do
|
1408
|
+
@http.ssl c
|
1409
|
+
end
|
1410
|
+
|
1411
|
+
assert_empty out
|
1412
|
+
|
1413
|
+
assert_match %r%localhost:80%, err
|
1414
|
+
assert_match %r%I_KNOW_THAT_OPENSSL%, err
|
1415
|
+
|
1416
|
+
Object.send :const_set, :I_KNOW_THAT_OPENSSL_VERIFY_PEER_EQUALS_VERIFY_NONE_IS_WRONG, nil
|
1417
|
+
|
1418
|
+
assert_silent do
|
1419
|
+
@http.ssl c
|
1420
|
+
end
|
1421
|
+
ensure
|
1422
|
+
OpenSSL::SSL.send :remove_const, :VERIFY_PEER
|
1423
|
+
OpenSSL::SSL.send :const_set, :VERIFY_PEER, orig_verify_peer
|
1424
|
+
if Object.const_defined?(:I_KNOW_THAT_OPENSSL_VERIFY_PEER_EQUALS_VERIFY_NONE_IS_WRONG) then
|
1425
|
+
Object.send :remove_const, :I_KNOW_THAT_OPENSSL_VERIFY_PEER_EQUALS_VERIFY_NONE_IS_WRONG
|
1426
|
+
end
|
1427
|
+
end
|
1428
|
+
end
|
1429
|
+
|
1430
|
+
def test_ssl_timeout_equals
|
1431
|
+
@http.ssl_timeout = :ssl_timeout
|
1432
|
+
|
1433
|
+
assert_equal :ssl_timeout, @http.ssl_timeout
|
1434
|
+
assert_equal 1, @http.ssl_generation
|
1435
|
+
end
|
1436
|
+
|
1437
|
+
def test_ssl_version_equals
|
1438
|
+
@http.ssl_version = :ssl_version
|
1439
|
+
|
1440
|
+
assert_equal :ssl_version, @http.ssl_version
|
1441
|
+
assert_equal 1, @http.ssl_generation
|
1442
|
+
end
|
1443
|
+
|
1444
|
+
def test_min_version_equals
|
1445
|
+
@http.min_version = :min_version
|
1446
|
+
|
1447
|
+
assert_equal :min_version, @http.min_version
|
1448
|
+
assert_equal 1, @http.ssl_generation
|
1449
|
+
end
|
1450
|
+
|
1451
|
+
def test_max_version_equals
|
1452
|
+
@http.max_version = :max_version
|
1453
|
+
|
1454
|
+
assert_equal :max_version, @http.max_version
|
1455
|
+
assert_equal 1, @http.ssl_generation
|
1456
|
+
end
|
1457
|
+
|
1458
|
+
def test_start
|
1459
|
+
c = basic_connection
|
1460
|
+
c = c.http
|
1461
|
+
|
1462
|
+
@http.socket_options << [Socket::SOL_SOCKET, Socket::SO_KEEPALIVE, 1]
|
1463
|
+
@http.debug_output = $stderr
|
1464
|
+
@http.open_timeout = 6
|
1465
|
+
|
1466
|
+
@http.start c
|
1467
|
+
|
1468
|
+
assert_equal $stderr, c.debug_output
|
1469
|
+
assert_equal 6, c.open_timeout
|
1470
|
+
|
1471
|
+
socket = c.instance_variable_get :@socket
|
1472
|
+
|
1473
|
+
expected = []
|
1474
|
+
expected << [Socket::IPPROTO_TCP, Socket::TCP_NODELAY, 1] if
|
1475
|
+
Socket.const_defined? :TCP_NODELAY
|
1476
|
+
expected << [Socket::SOL_SOCKET, Socket::SO_KEEPALIVE, 1]
|
1477
|
+
|
1478
|
+
assert_equal expected, socket.io.instance_variable_get(:@setsockopts)
|
1479
|
+
end
|
1480
|
+
|
1481
|
+
def test_verify_callback_equals
|
1482
|
+
@http.verify_callback = :verify_callback
|
1483
|
+
|
1484
|
+
assert_equal :verify_callback, @http.verify_callback
|
1485
|
+
assert_equal 1, @http.ssl_generation
|
1486
|
+
end
|
1487
|
+
|
1488
|
+
def test_verify_depth_equals
|
1489
|
+
@http.verify_depth = :verify_depth
|
1490
|
+
|
1491
|
+
assert_equal :verify_depth, @http.verify_depth
|
1492
|
+
assert_equal 1, @http.ssl_generation
|
1493
|
+
end
|
1494
|
+
|
1495
|
+
def test_verify_mode_equals
|
1496
|
+
@http.verify_mode = :verify_mode
|
1497
|
+
|
1498
|
+
assert_equal :verify_mode, @http.verify_mode
|
1499
|
+
assert_equal 1, @http.ssl_generation
|
1500
|
+
end
|
1501
|
+
|
1502
|
+
def test_connection_pool_after_fork
|
1503
|
+
# ConnectionPool 2.4+ calls `checkin(force: true)` after fork
|
1504
|
+
@http.pool.checkin(force: true)
|
1505
|
+
|
1506
|
+
@http.pool.checkout ['example.com', 80, nil, nil, nil, nil]
|
1507
|
+
@http.pool.checkin(force: true)
|
1508
|
+
@http.pool.reload do |connection|
|
1509
|
+
connection.close
|
1510
|
+
end
|
1511
|
+
end
|
1512
|
+
end
|