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.
Files changed (111) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +0 -1
  3. data/Gemfile +5 -0
  4. data/Gemfile.lock +31 -12
  5. data/lib/oso/api.rb +18 -2
  6. data/lib/oso/version.rb +1 -1
  7. data/vendor/gems/faraday-2.5.2/CHANGELOG.md +574 -0
  8. data/vendor/gems/faraday-2.5.2/LICENSE.md +20 -0
  9. data/vendor/gems/faraday-2.5.2/README.md +55 -0
  10. data/vendor/gems/faraday-2.5.2/Rakefile +7 -0
  11. data/vendor/gems/faraday-2.5.2/examples/client_spec.rb +119 -0
  12. data/vendor/gems/faraday-2.5.2/examples/client_test.rb +144 -0
  13. data/vendor/gems/faraday-2.5.2/lib/faraday/adapter/test.rb +298 -0
  14. data/vendor/gems/faraday-2.5.2/lib/faraday/adapter.rb +102 -0
  15. data/vendor/gems/faraday-2.5.2/lib/faraday/adapter_registry.rb +30 -0
  16. data/vendor/gems/faraday-2.5.2/lib/faraday/connection.rb +561 -0
  17. data/vendor/gems/faraday-2.5.2/lib/faraday/encoders/flat_params_encoder.rb +105 -0
  18. data/vendor/gems/faraday-2.5.2/lib/faraday/encoders/nested_params_encoder.rb +183 -0
  19. data/vendor/gems/faraday-2.5.2/lib/faraday/error.rb +147 -0
  20. data/vendor/gems/faraday-2.5.2/lib/faraday/logging/formatter.rb +106 -0
  21. data/vendor/gems/faraday-2.5.2/lib/faraday/methods.rb +6 -0
  22. data/vendor/gems/faraday-2.5.2/lib/faraday/middleware.rb +30 -0
  23. data/vendor/gems/faraday-2.5.2/lib/faraday/middleware_registry.rb +83 -0
  24. data/vendor/gems/faraday-2.5.2/lib/faraday/options/connection_options.rb +22 -0
  25. data/vendor/gems/faraday-2.5.2/lib/faraday/options/env.rb +199 -0
  26. data/vendor/gems/faraday-2.5.2/lib/faraday/options/proxy_options.rb +32 -0
  27. data/vendor/gems/faraday-2.5.2/lib/faraday/options/request_options.rb +22 -0
  28. data/vendor/gems/faraday-2.5.2/lib/faraday/options/ssl_options.rb +69 -0
  29. data/vendor/gems/faraday-2.5.2/lib/faraday/options.rb +218 -0
  30. data/vendor/gems/faraday-2.5.2/lib/faraday/parameters.rb +5 -0
  31. data/vendor/gems/faraday-2.5.2/lib/faraday/rack_builder.rb +252 -0
  32. data/vendor/gems/faraday-2.5.2/lib/faraday/request/authorization.rb +49 -0
  33. data/vendor/gems/faraday-2.5.2/lib/faraday/request/instrumentation.rb +56 -0
  34. data/vendor/gems/faraday-2.5.2/lib/faraday/request/json.rb +55 -0
  35. data/vendor/gems/faraday-2.5.2/lib/faraday/request/url_encoded.rb +60 -0
  36. data/vendor/gems/faraday-2.5.2/lib/faraday/request.rb +136 -0
  37. data/vendor/gems/faraday-2.5.2/lib/faraday/response/json.rb +54 -0
  38. data/vendor/gems/faraday-2.5.2/lib/faraday/response/logger.rb +33 -0
  39. data/vendor/gems/faraday-2.5.2/lib/faraday/response/raise_error.rb +64 -0
  40. data/vendor/gems/faraday-2.5.2/lib/faraday/response.rb +90 -0
  41. data/vendor/gems/faraday-2.5.2/lib/faraday/utils/headers.rb +139 -0
  42. data/vendor/gems/faraday-2.5.2/lib/faraday/utils/params_hash.rb +61 -0
  43. data/vendor/gems/faraday-2.5.2/lib/faraday/utils.rb +122 -0
  44. data/vendor/gems/faraday-2.5.2/lib/faraday/version.rb +5 -0
  45. data/vendor/gems/faraday-2.5.2/lib/faraday.rb +157 -0
  46. data/vendor/gems/faraday-2.5.2/spec/external_adapters/faraday_specs_setup.rb +14 -0
  47. data/vendor/gems/faraday-2.5.2/spec/faraday/adapter/test_spec.rb +413 -0
  48. data/vendor/gems/faraday-2.5.2/spec/faraday/adapter_registry_spec.rb +28 -0
  49. data/vendor/gems/faraday-2.5.2/spec/faraday/adapter_spec.rb +55 -0
  50. data/vendor/gems/faraday-2.5.2/spec/faraday/connection_spec.rb +793 -0
  51. data/vendor/gems/faraday-2.5.2/spec/faraday/error_spec.rb +60 -0
  52. data/vendor/gems/faraday-2.5.2/spec/faraday/middleware_registry_spec.rb +31 -0
  53. data/vendor/gems/faraday-2.5.2/spec/faraday/middleware_spec.rb +52 -0
  54. data/vendor/gems/faraday-2.5.2/spec/faraday/options/env_spec.rb +76 -0
  55. data/vendor/gems/faraday-2.5.2/spec/faraday/options/options_spec.rb +297 -0
  56. data/vendor/gems/faraday-2.5.2/spec/faraday/options/proxy_options_spec.rb +44 -0
  57. data/vendor/gems/faraday-2.5.2/spec/faraday/options/request_options_spec.rb +19 -0
  58. data/vendor/gems/faraday-2.5.2/spec/faraday/params_encoders/flat_spec.rb +42 -0
  59. data/vendor/gems/faraday-2.5.2/spec/faraday/params_encoders/nested_spec.rb +150 -0
  60. data/vendor/gems/faraday-2.5.2/spec/faraday/rack_builder_spec.rb +317 -0
  61. data/vendor/gems/faraday-2.5.2/spec/faraday/request/authorization_spec.rb +83 -0
  62. data/vendor/gems/faraday-2.5.2/spec/faraday/request/instrumentation_spec.rb +74 -0
  63. data/vendor/gems/faraday-2.5.2/spec/faraday/request/json_spec.rb +111 -0
  64. data/vendor/gems/faraday-2.5.2/spec/faraday/request/url_encoded_spec.rb +93 -0
  65. data/vendor/gems/faraday-2.5.2/spec/faraday/request_spec.rb +110 -0
  66. data/vendor/gems/faraday-2.5.2/spec/faraday/response/json_spec.rb +117 -0
  67. data/vendor/gems/faraday-2.5.2/spec/faraday/response/logger_spec.rb +220 -0
  68. data/vendor/gems/faraday-2.5.2/spec/faraday/response/raise_error_spec.rb +172 -0
  69. data/vendor/gems/faraday-2.5.2/spec/faraday/response_spec.rb +75 -0
  70. data/vendor/gems/faraday-2.5.2/spec/faraday/utils/headers_spec.rb +82 -0
  71. data/vendor/gems/faraday-2.5.2/spec/faraday/utils_spec.rb +118 -0
  72. data/vendor/gems/faraday-2.5.2/spec/faraday_spec.rb +37 -0
  73. data/vendor/gems/faraday-2.5.2/spec/spec_helper.rb +132 -0
  74. data/vendor/gems/faraday-2.5.2/spec/support/disabling_stub.rb +14 -0
  75. data/vendor/gems/faraday-2.5.2/spec/support/fake_safe_buffer.rb +15 -0
  76. data/vendor/gems/faraday-2.5.2/spec/support/helper_methods.rb +96 -0
  77. data/vendor/gems/faraday-2.5.2/spec/support/shared_examples/adapter.rb +105 -0
  78. data/vendor/gems/faraday-2.5.2/spec/support/shared_examples/params_encoder.rb +18 -0
  79. data/vendor/gems/faraday-2.5.2/spec/support/shared_examples/request_method.rb +263 -0
  80. data/vendor/gems/faraday-2.5.2/spec/support/streaming_response_checker.rb +35 -0
  81. data/vendor/gems/faraday-net_http-3.0.2/LICENSE.md +21 -0
  82. data/vendor/gems/faraday-net_http-3.0.2/README.md +57 -0
  83. data/vendor/gems/faraday-net_http-3.0.2/lib/faraday/adapter/net_http.rb +208 -0
  84. data/vendor/gems/faraday-net_http-3.0.2/lib/faraday/net_http/version.rb +7 -0
  85. data/vendor/gems/faraday-net_http-3.0.2/lib/faraday/net_http.rb +10 -0
  86. data/vendor/gems/faraday-net_http_persistent-2.3.0/LICENSE.md +21 -0
  87. data/vendor/gems/faraday-net_http_persistent-2.3.0/README.md +66 -0
  88. data/vendor/gems/faraday-net_http_persistent-2.3.0/lib/faraday/adapter/net_http_persistent.rb +234 -0
  89. data/vendor/gems/faraday-net_http_persistent-2.3.0/lib/faraday/net_http_persistent/version.rb +7 -0
  90. data/vendor/gems/faraday-net_http_persistent-2.3.0/lib/faraday/net_http_persistent.rb +18 -0
  91. data/vendor/gems/faraday-retry-2.0.0/CHANGELOG.md +24 -0
  92. data/vendor/gems/faraday-retry-2.0.0/LICENSE.md +21 -0
  93. data/vendor/gems/faraday-retry-2.0.0/README.md +169 -0
  94. data/vendor/gems/faraday-retry-2.0.0/lib/faraday/retriable_response.rb +8 -0
  95. data/vendor/gems/faraday-retry-2.0.0/lib/faraday/retry/middleware.rb +254 -0
  96. data/vendor/gems/faraday-retry-2.0.0/lib/faraday/retry/version.rb +7 -0
  97. data/vendor/gems/faraday-retry-2.0.0/lib/faraday/retry.rb +13 -0
  98. data/vendor/gems/net-http-persistent-4.0.5/.autotest +9 -0
  99. data/vendor/gems/net-http-persistent-4.0.5/.gemtest +0 -0
  100. data/vendor/gems/net-http-persistent-4.0.5/Gemfile +14 -0
  101. data/vendor/gems/net-http-persistent-4.0.5/History.txt +460 -0
  102. data/vendor/gems/net-http-persistent-4.0.5/Manifest.txt +13 -0
  103. data/vendor/gems/net-http-persistent-4.0.5/README.rdoc +82 -0
  104. data/vendor/gems/net-http-persistent-4.0.5/Rakefile +25 -0
  105. data/vendor/gems/net-http-persistent-4.0.5/lib/net/http/persistent/connection.rb +41 -0
  106. data/vendor/gems/net-http-persistent-4.0.5/lib/net/http/persistent/pool.rb +65 -0
  107. data/vendor/gems/net-http-persistent-4.0.5/lib/net/http/persistent/timed_stack_multi.rb +79 -0
  108. data/vendor/gems/net-http-persistent-4.0.5/lib/net/http/persistent.rb +1158 -0
  109. data/vendor/gems/net-http-persistent-4.0.5/test/test_net_http_persistent.rb +1512 -0
  110. data/vendor/gems/net-http-persistent-4.0.5/test/test_net_http_persistent_timed_stack_multi.rb +151 -0
  111. metadata +108 -4
@@ -0,0 +1,793 @@
1
+ # frozen_string_literal: true
2
+
3
+ class CustomEncoder
4
+ def encode(params)
5
+ params.map { |k, v| "#{k.upcase}-#{v.to_s.upcase}" }.join(',')
6
+ end
7
+
8
+ def decode(params)
9
+ params.split(',').to_h { |pair| pair.split('-') }
10
+ end
11
+ end
12
+
13
+ shared_examples 'initializer with url' do
14
+ context 'with simple url' do
15
+ let(:address) { 'http://httpbingo.org' }
16
+
17
+ it { expect(subject.host).to eq('httpbingo.org') }
18
+ it { expect(subject.port).to eq(80) }
19
+ it { expect(subject.scheme).to eq('http') }
20
+ it { expect(subject.path_prefix).to eq('/') }
21
+ it { expect(subject.params).to eq({}) }
22
+ end
23
+
24
+ context 'with complex url' do
25
+ let(:address) { 'http://httpbingo.org:815/fish?a=1' }
26
+
27
+ it { expect(subject.port).to eq(815) }
28
+ it { expect(subject.path_prefix).to eq('/fish') }
29
+ it { expect(subject.params).to eq('a' => '1') }
30
+ end
31
+
32
+ context 'with IPv6 address' do
33
+ let(:address) { 'http://[::1]:85/' }
34
+
35
+ it { expect(subject.host).to eq('[::1]') }
36
+ it { expect(subject.port).to eq(85) }
37
+ end
38
+ end
39
+
40
+ shared_examples 'default connection options' do
41
+ after { Faraday.default_connection_options = nil }
42
+
43
+ it 'works with implicit url' do
44
+ conn = Faraday.new 'http://httpbingo.org/foo'
45
+ expect(conn.options.timeout).to eq(10)
46
+ end
47
+
48
+ it 'works with option url' do
49
+ conn = Faraday.new url: 'http://httpbingo.org/foo'
50
+ expect(conn.options.timeout).to eq(10)
51
+ end
52
+
53
+ it 'works with instance connection options' do
54
+ conn = Faraday.new 'http://httpbingo.org/foo', request: { open_timeout: 1 }
55
+ expect(conn.options.timeout).to eq(10)
56
+ expect(conn.options.open_timeout).to eq(1)
57
+ end
58
+
59
+ it 'default connection options persist with an instance overriding' do
60
+ conn = Faraday.new 'http://nigiri.com/bar'
61
+ conn.options.timeout = 1
62
+ expect(Faraday.default_connection_options.request.timeout).to eq(10)
63
+
64
+ other = Faraday.new url: 'https://httpbingo.org/foo'
65
+ other.options.timeout = 1
66
+
67
+ expect(Faraday.default_connection_options.request.timeout).to eq(10)
68
+ end
69
+
70
+ it 'default connection uses default connection options' do
71
+ expect(Faraday.default_connection.options.timeout).to eq(10)
72
+ end
73
+ end
74
+
75
+ RSpec.describe Faraday::Connection do
76
+ let(:conn) { Faraday::Connection.new(url, options) }
77
+ let(:url) { nil }
78
+ let(:options) { nil }
79
+
80
+ describe '.new' do
81
+ subject { conn }
82
+
83
+ context 'with implicit url param' do
84
+ # Faraday::Connection.new('http://httpbingo.org')
85
+ let(:url) { address }
86
+
87
+ it_behaves_like 'initializer with url'
88
+ end
89
+
90
+ context 'with explicit url param' do
91
+ # Faraday::Connection.new(url: 'http://httpbingo.org')
92
+ let(:url) { { url: address } }
93
+
94
+ it_behaves_like 'initializer with url'
95
+ end
96
+
97
+ context 'with custom builder' do
98
+ let(:custom_builder) { Faraday::RackBuilder.new }
99
+ let(:options) { { builder: custom_builder } }
100
+
101
+ it { expect(subject.builder).to eq(custom_builder) }
102
+ end
103
+
104
+ context 'with custom params' do
105
+ let(:options) { { params: { a: 1 } } }
106
+
107
+ it { expect(subject.params).to eq('a' => 1) }
108
+ end
109
+
110
+ context 'with custom params and params in url' do
111
+ let(:url) { 'http://httpbingo.org/fish?a=1&b=2' }
112
+ let(:options) { { params: { a: 3 } } }
113
+ it { expect(subject.params).to eq('a' => 3, 'b' => '2') }
114
+ end
115
+
116
+ context 'with basic_auth in url' do
117
+ let(:url) { 'http://Aladdin:open%20sesame@httpbingo.org/fish' }
118
+
119
+ it { expect(subject.headers['Authorization']).to eq('Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==') }
120
+ end
121
+
122
+ context 'with custom headers' do
123
+ let(:options) { { headers: { user_agent: 'Faraday' } } }
124
+
125
+ it { expect(subject.headers['User-agent']).to eq('Faraday') }
126
+ end
127
+
128
+ context 'with ssl false' do
129
+ let(:options) { { ssl: { verify: false } } }
130
+
131
+ it { expect(subject.ssl.verify?).to be_falsey }
132
+ end
133
+
134
+ context 'with verify_hostname false' do
135
+ let(:options) { { ssl: { verify_hostname: false } } }
136
+
137
+ it { expect(subject.ssl.verify_hostname?).to be_falsey }
138
+ end
139
+
140
+ context 'with empty block' do
141
+ let(:conn) { Faraday::Connection.new {} }
142
+
143
+ it { expect(conn.builder.handlers.size).to eq(0) }
144
+ end
145
+
146
+ context 'with block' do
147
+ let(:conn) do
148
+ Faraday::Connection.new(params: { 'a' => '1' }) do |faraday|
149
+ faraday.adapter :test
150
+ faraday.url_prefix = 'http://httpbingo.org/omnom'
151
+ end
152
+ end
153
+
154
+ it { expect(conn.builder.handlers.size).to eq(0) }
155
+ it { expect(conn.path_prefix).to eq('/omnom') }
156
+ end
157
+ end
158
+
159
+ describe '#close' do
160
+ before { Faraday.default_adapter = :test }
161
+ after { Faraday.default_adapter = nil }
162
+
163
+ it 'can close underlying app' do
164
+ expect(conn.app).to receive(:close)
165
+ conn.close
166
+ end
167
+ end
168
+
169
+ describe '#build_exclusive_url' do
170
+ context 'with relative path' do
171
+ subject { conn.build_exclusive_url('sake.html') }
172
+
173
+ it 'uses connection host as default host' do
174
+ conn.host = 'httpbingo.org'
175
+ expect(subject.host).to eq('httpbingo.org')
176
+ expect(subject.scheme).to eq('http')
177
+ end
178
+
179
+ it do
180
+ conn.path_prefix = '/fish'
181
+ expect(subject.path).to eq('/fish/sake.html')
182
+ end
183
+
184
+ it do
185
+ conn.path_prefix = '/'
186
+ expect(subject.path).to eq('/sake.html')
187
+ end
188
+
189
+ it do
190
+ conn.path_prefix = 'fish'
191
+ expect(subject.path).to eq('/fish/sake.html')
192
+ end
193
+
194
+ it do
195
+ conn.path_prefix = '/fish/'
196
+ expect(subject.path).to eq('/fish/sake.html')
197
+ end
198
+ end
199
+
200
+ context 'with absolute path' do
201
+ subject { conn.build_exclusive_url('/sake.html') }
202
+
203
+ after { expect(subject.path).to eq('/sake.html') }
204
+
205
+ it { conn.path_prefix = '/fish' }
206
+ it { conn.path_prefix = '/' }
207
+ it { conn.path_prefix = 'fish' }
208
+ it { conn.path_prefix = '/fish/' }
209
+ end
210
+
211
+ context 'with complete url' do
212
+ subject { conn.build_exclusive_url('http://httpbingo.org/sake.html?a=1') }
213
+
214
+ it { expect(subject.scheme).to eq('http') }
215
+ it { expect(subject.host).to eq('httpbingo.org') }
216
+ it { expect(subject.port).to eq(80) }
217
+ it { expect(subject.path).to eq('/sake.html') }
218
+ it { expect(subject.query).to eq('a=1') }
219
+ end
220
+
221
+ it 'overrides connection port for absolute url' do
222
+ conn.port = 23
223
+ uri = conn.build_exclusive_url('http://httpbingo.org')
224
+ expect(uri.port).to eq(80)
225
+ end
226
+
227
+ it 'does not add ending slash given nil url' do
228
+ conn.url_prefix = 'http://httpbingo.org/nigiri'
229
+ uri = conn.build_exclusive_url
230
+ expect(uri.path).to eq('/nigiri')
231
+ end
232
+
233
+ it 'does not add ending slash given empty url' do
234
+ conn.url_prefix = 'http://httpbingo.org/nigiri'
235
+ uri = conn.build_exclusive_url('')
236
+ expect(uri.path).to eq('/nigiri')
237
+ end
238
+
239
+ it 'does not use connection params' do
240
+ conn.url_prefix = 'http://httpbingo.org/nigiri'
241
+ conn.params = { a: 1 }
242
+ expect(conn.build_exclusive_url.to_s).to eq('http://httpbingo.org/nigiri')
243
+ end
244
+
245
+ it 'allows to provide params argument' do
246
+ conn.url_prefix = 'http://httpbingo.org/nigiri'
247
+ conn.params = { a: 1 }
248
+ params = Faraday::Utils::ParamsHash.new
249
+ params[:a] = 2
250
+ uri = conn.build_exclusive_url(nil, params)
251
+ expect(uri.to_s).to eq('http://httpbingo.org/nigiri?a=2')
252
+ end
253
+
254
+ it 'handles uri instances' do
255
+ uri = conn.build_exclusive_url(URI('/sake.html'))
256
+ expect(uri.path).to eq('/sake.html')
257
+ end
258
+
259
+ it 'always returns new URI instance' do
260
+ conn.url_prefix = 'http://httpbingo.org'
261
+ uri1 = conn.build_exclusive_url(nil)
262
+ uri2 = conn.build_exclusive_url(nil)
263
+ expect(uri1).not_to equal(uri2)
264
+ end
265
+
266
+ context 'with url_prefixed connection' do
267
+ let(:url) { 'http://httpbingo.org/get/' }
268
+
269
+ it 'parses url and changes scheme' do
270
+ conn.scheme = 'https'
271
+ uri = conn.build_exclusive_url('sake.html')
272
+ expect(uri.to_s).to eq('https://httpbingo.org/get/sake.html')
273
+ end
274
+
275
+ it 'joins url to base with ending slash' do
276
+ uri = conn.build_exclusive_url('sake.html')
277
+ expect(uri.to_s).to eq('http://httpbingo.org/get/sake.html')
278
+ end
279
+
280
+ it 'used default base with ending slash' do
281
+ uri = conn.build_exclusive_url
282
+ expect(uri.to_s).to eq('http://httpbingo.org/get/')
283
+ end
284
+
285
+ it 'overrides base' do
286
+ uri = conn.build_exclusive_url('/sake/')
287
+ expect(uri.to_s).to eq('http://httpbingo.org/sake/')
288
+ end
289
+ end
290
+
291
+ context 'with colon in path' do
292
+ let(:url) { 'http://service.com' }
293
+
294
+ it 'joins url to base when used absolute path' do
295
+ conn = Faraday.new(url: url)
296
+ uri = conn.build_exclusive_url('/service:search?limit=400')
297
+ expect(uri.to_s).to eq('http://service.com/service:search?limit=400')
298
+ end
299
+
300
+ it 'joins url to base when used relative path' do
301
+ conn = Faraday.new(url: url)
302
+ uri = conn.build_exclusive_url('service:search?limit=400')
303
+ expect(uri.to_s).to eq('http://service.com/service%3Asearch?limit=400')
304
+ end
305
+
306
+ it 'joins url to base when used with path prefix' do
307
+ conn = Faraday.new(url: url)
308
+ conn.path_prefix = '/api'
309
+ uri = conn.build_exclusive_url('service:search?limit=400')
310
+ expect(uri.to_s).to eq('http://service.com/api/service%3Asearch?limit=400')
311
+ end
312
+ end
313
+ end
314
+
315
+ describe '#build_url' do
316
+ let(:url) { 'http://httpbingo.org/nigiri' }
317
+
318
+ it 'uses params' do
319
+ conn.params = { a: 1, b: 1 }
320
+ expect(conn.build_url.to_s).to eq('http://httpbingo.org/nigiri?a=1&b=1')
321
+ end
322
+
323
+ it 'merges params' do
324
+ conn.params = { a: 1, b: 1 }
325
+ url = conn.build_url(nil, b: 2, c: 3)
326
+ expect(url.to_s).to eq('http://httpbingo.org/nigiri?a=1&b=2&c=3')
327
+ end
328
+ end
329
+
330
+ describe '#build_request' do
331
+ let(:url) { 'https://ahttpbingo.org/sake.html' }
332
+ let(:request) { conn.build_request(:get) }
333
+
334
+ before do
335
+ conn.headers = { 'Authorization' => 'token abc123' }
336
+ request.headers.delete('Authorization')
337
+ end
338
+
339
+ it { expect(conn.headers.keys).to eq(['Authorization']) }
340
+ it { expect(conn.headers.include?('Authorization')).to be_truthy }
341
+ it { expect(request.headers.keys).to be_empty }
342
+ it { expect(request.headers.include?('Authorization')).to be_falsey }
343
+ end
344
+
345
+ describe '#to_env' do
346
+ subject { conn.build_request(:get).to_env(conn).url }
347
+
348
+ let(:url) { 'http://httpbingo.org/sake.html' }
349
+ let(:options) { { params: @params } }
350
+
351
+ it 'parses url params into query' do
352
+ @params = { 'a[b]' => '1 + 2' }
353
+ expect(subject.query).to eq('a%5Bb%5D=1+%2B+2')
354
+ end
355
+
356
+ it 'escapes per spec' do
357
+ @params = { 'a' => '1+2 foo~bar.-baz' }
358
+ expect(subject.query).to eq('a=1%2B2+foo~bar.-baz')
359
+ end
360
+
361
+ it 'bracketizes nested params in query' do
362
+ @params = { 'a' => { 'b' => 'c' } }
363
+ expect(subject.query).to eq('a%5Bb%5D=c')
364
+ end
365
+
366
+ it 'bracketizes repeated params in query' do
367
+ @params = { 'a' => [1, 2] }
368
+ expect(subject.query).to eq('a%5B%5D=1&a%5B%5D=2')
369
+ end
370
+
371
+ it 'without braketizing repeated params in query' do
372
+ @params = { 'a' => [1, 2] }
373
+ conn.options.params_encoder = Faraday::FlatParamsEncoder
374
+ expect(subject.query).to eq('a=1&a=2')
375
+ end
376
+ end
377
+
378
+ describe 'proxy support' do
379
+ it 'accepts string' do
380
+ with_env 'http_proxy' => 'http://env-proxy.com:80' do
381
+ conn.proxy = 'http://proxy.com'
382
+ expect(conn.proxy.host).to eq('proxy.com')
383
+ end
384
+ end
385
+
386
+ it 'accepts uri' do
387
+ with_env 'http_proxy' => 'http://env-proxy.com:80' do
388
+ conn.proxy = URI.parse('http://proxy.com')
389
+ expect(conn.proxy.host).to eq('proxy.com')
390
+ end
391
+ end
392
+
393
+ it 'accepts hash with string uri' do
394
+ with_env 'http_proxy' => 'http://env-proxy.com:80' do
395
+ conn.proxy = { uri: 'http://proxy.com', user: 'rick' }
396
+ expect(conn.proxy.host).to eq('proxy.com')
397
+ expect(conn.proxy.user).to eq('rick')
398
+ end
399
+ end
400
+
401
+ it 'accepts hash' do
402
+ with_env 'http_proxy' => 'http://env-proxy.com:80' do
403
+ conn.proxy = { uri: URI.parse('http://proxy.com'), user: 'rick' }
404
+ expect(conn.proxy.host).to eq('proxy.com')
405
+ expect(conn.proxy.user).to eq('rick')
406
+ end
407
+ end
408
+
409
+ it 'accepts http env' do
410
+ with_env 'http_proxy' => 'http://env-proxy.com:80' do
411
+ expect(conn.proxy.host).to eq('env-proxy.com')
412
+ end
413
+ end
414
+
415
+ it 'accepts http env with auth' do
416
+ with_env 'http_proxy' => 'http://a%40b:my%20pass@proxy.com:80' do
417
+ expect(conn.proxy.user).to eq('a@b')
418
+ expect(conn.proxy.password).to eq('my pass')
419
+ end
420
+ end
421
+
422
+ it 'accepts env without scheme' do
423
+ with_env 'http_proxy' => 'localhost:8888' do
424
+ uri = conn.proxy[:uri]
425
+ expect(uri.host).to eq('localhost')
426
+ expect(uri.port).to eq(8888)
427
+ end
428
+ end
429
+
430
+ it 'fetches no proxy from nil env' do
431
+ with_env 'http_proxy' => nil do
432
+ expect(conn.proxy).to be_nil
433
+ end
434
+ end
435
+
436
+ it 'fetches no proxy from blank env' do
437
+ with_env 'http_proxy' => '' do
438
+ expect(conn.proxy).to be_nil
439
+ end
440
+ end
441
+
442
+ it 'does not accept uppercase env' do
443
+ with_env 'HTTP_PROXY' => 'http://localhost:8888/' do
444
+ expect(conn.proxy).to be_nil
445
+ end
446
+ end
447
+
448
+ it 'allows when url in no proxy list' do
449
+ with_env 'http_proxy' => 'http://proxy.com', 'no_proxy' => 'example.com' do
450
+ conn = Faraday::Connection.new('http://example.com')
451
+ expect(conn.proxy).to be_nil
452
+ end
453
+ end
454
+
455
+ it 'allows when url in no proxy list with url_prefix' do
456
+ with_env 'http_proxy' => 'http://proxy.com', 'no_proxy' => 'example.com' do
457
+ conn = Faraday::Connection.new
458
+ conn.url_prefix = 'http://example.com'
459
+ expect(conn.proxy).to be_nil
460
+ end
461
+ end
462
+
463
+ it 'allows when prefixed url is not in no proxy list' do
464
+ with_env 'http_proxy' => 'http://proxy.com', 'no_proxy' => 'example.com' do
465
+ conn = Faraday::Connection.new('http://prefixedexample.com')
466
+ expect(conn.proxy.host).to eq('proxy.com')
467
+ end
468
+ end
469
+
470
+ it 'allows when subdomain url is in no proxy list' do
471
+ with_env 'http_proxy' => 'http://proxy.com', 'no_proxy' => 'example.com' do
472
+ conn = Faraday::Connection.new('http://subdomain.example.com')
473
+ expect(conn.proxy).to be_nil
474
+ end
475
+ end
476
+
477
+ it 'allows when url not in no proxy list' do
478
+ with_env 'http_proxy' => 'http://proxy.com', 'no_proxy' => 'example2.com' do
479
+ conn = Faraday::Connection.new('http://example.com')
480
+ expect(conn.proxy.host).to eq('proxy.com')
481
+ end
482
+ end
483
+
484
+ it 'allows when ip address is not in no proxy list but url is' do
485
+ with_env 'http_proxy' => 'http://proxy.com', 'no_proxy' => 'localhost' do
486
+ conn = Faraday::Connection.new('http://127.0.0.1')
487
+ expect(conn.proxy).to be_nil
488
+ end
489
+ end
490
+
491
+ it 'allows when url is not in no proxy list but ip address is' do
492
+ with_env 'http_proxy' => 'http://proxy.com', 'no_proxy' => '127.0.0.1' do
493
+ conn = Faraday::Connection.new('http://localhost')
494
+ expect(conn.proxy).to be_nil
495
+ end
496
+ end
497
+
498
+ it 'allows in multi element no proxy list' do
499
+ with_env 'http_proxy' => 'http://proxy.com', 'no_proxy' => 'example0.com,example.com,example1.com' do
500
+ expect(Faraday::Connection.new('http://example0.com').proxy).to be_nil
501
+ expect(Faraday::Connection.new('http://example.com').proxy).to be_nil
502
+ expect(Faraday::Connection.new('http://example1.com').proxy).to be_nil
503
+ expect(Faraday::Connection.new('http://example2.com').proxy.host).to eq('proxy.com')
504
+ end
505
+ end
506
+
507
+ it 'test proxy requires uri' do
508
+ expect { conn.proxy = { uri: :bad_uri, user: 'rick' } }.to raise_error(ArgumentError)
509
+ end
510
+
511
+ it 'uses env http_proxy' do
512
+ with_env 'http_proxy' => 'http://proxy.com' do
513
+ conn = Faraday.new
514
+ expect(conn.instance_variable_get(:@manual_proxy)).to be_falsey
515
+ expect(conn.proxy_for_request('http://google.co.uk').host).to eq('proxy.com')
516
+ end
517
+ end
518
+
519
+ it 'uses processes no_proxy before http_proxy' do
520
+ with_env 'http_proxy' => 'http://proxy.com', 'no_proxy' => 'google.co.uk' do
521
+ conn = Faraday.new
522
+ expect(conn.instance_variable_get(:@manual_proxy)).to be_falsey
523
+ expect(conn.proxy_for_request('http://google.co.uk')).to be_nil
524
+ end
525
+ end
526
+
527
+ it 'uses env https_proxy' do
528
+ with_env 'https_proxy' => 'https://proxy.com' do
529
+ conn = Faraday.new
530
+ expect(conn.instance_variable_get(:@manual_proxy)).to be_falsey
531
+ expect(conn.proxy_for_request('https://google.co.uk').host).to eq('proxy.com')
532
+ end
533
+ end
534
+
535
+ it 'uses processes no_proxy before https_proxy' do
536
+ with_env 'https_proxy' => 'https://proxy.com', 'no_proxy' => 'google.co.uk' do
537
+ conn = Faraday.new
538
+ expect(conn.instance_variable_get(:@manual_proxy)).to be_falsey
539
+ expect(conn.proxy_for_request('https://google.co.uk')).to be_nil
540
+ end
541
+ end
542
+
543
+ it 'gives priority to manually set proxy' do
544
+ with_env 'https_proxy' => 'https://proxy.com', 'no_proxy' => 'google.co.uk' do
545
+ conn = Faraday.new
546
+ conn.proxy = 'http://proxy2.com'
547
+
548
+ expect(conn.instance_variable_get(:@manual_proxy)).to be_truthy
549
+ expect(conn.proxy_for_request('https://google.co.uk').host).to eq('proxy2.com')
550
+ end
551
+ end
552
+
553
+ it 'ignores env proxy if set that way' do
554
+ with_env_proxy_disabled do
555
+ with_env 'http_proxy' => 'http://duncan.proxy.com:80' do
556
+ expect(conn.proxy).to be_nil
557
+ end
558
+ end
559
+ end
560
+
561
+ context 'performing a request' do
562
+ let(:url) { 'http://example.com' }
563
+ let(:conn) do
564
+ Faraday.new do |f|
565
+ f.adapter :test do |stubs|
566
+ stubs.get(url) do
567
+ [200, {}, 'ok']
568
+ end
569
+ end
570
+ end
571
+ end
572
+
573
+ it 'dynamically checks proxy' do
574
+ with_env 'http_proxy' => 'http://proxy.com:80' do
575
+ expect(conn.proxy.uri.host).to eq('proxy.com')
576
+
577
+ conn.get(url) do |req|
578
+ expect(req.options.proxy.uri.host).to eq('proxy.com')
579
+ end
580
+ end
581
+
582
+ conn.get(url)
583
+ expect(conn.instance_variable_get(:@temp_proxy)).to be_nil
584
+ end
585
+
586
+ it 'dynamically check no proxy' do
587
+ with_env 'http_proxy' => 'http://proxy.com', 'no_proxy' => 'example.com' do
588
+ expect(conn.proxy.uri.host).to eq('proxy.com')
589
+
590
+ conn.get('http://example.com') do |req|
591
+ expect(req.options.proxy).to be_nil
592
+ end
593
+ end
594
+ end
595
+ end
596
+ end
597
+
598
+ describe '#dup' do
599
+ subject { conn.dup }
600
+
601
+ let(:url) { 'http://httpbingo.org/foo' }
602
+ let(:options) do
603
+ {
604
+ ssl: { verify: :none },
605
+ headers: { 'content-type' => 'text/plain' },
606
+ params: { 'a' => '1' },
607
+ request: { timeout: 5 }
608
+ }
609
+ end
610
+
611
+ it { expect(subject.build_exclusive_url).to eq(conn.build_exclusive_url) }
612
+ it { expect(subject.headers['content-type']).to eq('text/plain') }
613
+ it { expect(subject.params['a']).to eq('1') }
614
+
615
+ context 'after manual changes' do
616
+ before do
617
+ subject.headers['content-length'] = 12
618
+ subject.params['b'] = '2'
619
+ subject.options[:open_timeout] = 10
620
+ end
621
+
622
+ it { expect(subject.builder.handlers.size).to eq(1) }
623
+ it { expect(conn.builder.handlers.size).to eq(1) }
624
+ it { expect(conn.headers.key?('content-length')).to be_falsey }
625
+ it { expect(conn.params.key?('b')).to be_falsey }
626
+ it { expect(subject.options[:timeout]).to eq(5) }
627
+ it { expect(conn.options[:open_timeout]).to be_nil }
628
+ end
629
+ end
630
+
631
+ describe '#respond_to?' do
632
+ it { expect(Faraday.respond_to?(:get)).to be_truthy }
633
+ it { expect(Faraday.respond_to?(:post)).to be_truthy }
634
+ end
635
+
636
+ describe 'default_connection_options' do
637
+ context 'assigning a default value' do
638
+ before do
639
+ Faraday.default_connection_options = nil
640
+ Faraday.default_connection_options.request.timeout = 10
641
+ end
642
+
643
+ it_behaves_like 'default connection options'
644
+ end
645
+
646
+ context 'assigning a hash' do
647
+ before { Faraday.default_connection_options = { request: { timeout: 10 } } }
648
+
649
+ it_behaves_like 'default connection options'
650
+ end
651
+
652
+ context 'preserving a user_agent assigned via default_conncetion_options' do
653
+ around do |example|
654
+ old = Faraday.default_connection_options
655
+ Faraday.default_connection_options = { headers: { user_agent: 'My Agent 1.2' } }
656
+ example.run
657
+ Faraday.default_connection_options = old
658
+ end
659
+
660
+ context 'when url is a Hash' do
661
+ let(:conn) { Faraday.new(url: 'http://example.co', headers: { 'CustomHeader' => 'CustomValue' }) }
662
+
663
+ it { expect(conn.headers).to eq('CustomHeader' => 'CustomValue', 'User-Agent' => 'My Agent 1.2') }
664
+ end
665
+
666
+ context 'when url is a String' do
667
+ let(:conn) { Faraday.new('http://example.co', headers: { 'CustomHeader' => 'CustomValue' }) }
668
+
669
+ it { expect(conn.headers).to eq('CustomHeader' => 'CustomValue', 'User-Agent' => 'My Agent 1.2') }
670
+ end
671
+ end
672
+ end
673
+
674
+ describe 'request params' do
675
+ context 'with simple url' do
676
+ let(:url) { 'http://example.com' }
677
+ let(:stubs) { Faraday::Adapter::Test::Stubs.new }
678
+
679
+ before do
680
+ conn.adapter(:test, stubs)
681
+ stubs.get('http://example.com?a=a&p=3') do
682
+ [200, {}, 'ok']
683
+ end
684
+ end
685
+
686
+ after { stubs.verify_stubbed_calls }
687
+
688
+ it 'test_overrides_request_params' do
689
+ conn.get('?p=2&a=a', p: 3)
690
+ end
691
+
692
+ it 'test_overrides_request_params_block' do
693
+ conn.get('?p=1&a=a', p: 2) do |req|
694
+ req.params[:p] = 3
695
+ end
696
+ end
697
+
698
+ it 'test_overrides_request_params_block_url' do
699
+ conn.get(nil, p: 2) do |req|
700
+ req.url('?p=1&a=a', 'p' => 3)
701
+ end
702
+ end
703
+ end
704
+
705
+ context 'with url and extra params' do
706
+ let(:url) { 'http://example.com?a=1&b=2' }
707
+ let(:options) { { params: { c: 3 } } }
708
+ let(:stubs) { Faraday::Adapter::Test::Stubs.new }
709
+
710
+ before do
711
+ conn.adapter(:test, stubs)
712
+ end
713
+
714
+ it 'merges connection and request params' do
715
+ expected = 'http://example.com?a=1&b=2&c=3&limit=5&page=1'
716
+ stubs.get(expected) { [200, {}, 'ok'] }
717
+ conn.get('?page=1', limit: 5)
718
+ stubs.verify_stubbed_calls
719
+ end
720
+
721
+ it 'allows to override all params' do
722
+ expected = 'http://example.com?b=b'
723
+ stubs.get(expected) { [200, {}, 'ok'] }
724
+ conn.get('?p=1&a=a', p: 2) do |req|
725
+ expect(req.params[:a]).to eq('a')
726
+ expect(req.params['c']).to eq(3)
727
+ expect(req.params['p']).to eq(2)
728
+ req.params = { b: 'b' }
729
+ expect(req.params['b']).to eq('b')
730
+ end
731
+ stubs.verify_stubbed_calls
732
+ end
733
+
734
+ it 'allows to set params_encoder for single request' do
735
+ encoder = CustomEncoder.new
736
+ expected = 'http://example.com/?A-1,B-2,C-3,FEELING-BLUE'
737
+ stubs.get(expected) { [200, {}, 'ok'] }
738
+
739
+ conn.get('/', a: 1, b: 2, c: 3, feeling: 'blue') do |req|
740
+ req.options.params_encoder = encoder
741
+ end
742
+ stubs.verify_stubbed_calls
743
+ end
744
+ end
745
+
746
+ context 'with default params encoder' do
747
+ let(:stubs) { Faraday::Adapter::Test::Stubs.new }
748
+
749
+ before do
750
+ conn.adapter(:test, stubs)
751
+ stubs.get('http://example.com?color%5B%5D=blue&color%5B%5D=red') do
752
+ [200, {}, 'ok']
753
+ end
754
+ end
755
+
756
+ after { stubs.verify_stubbed_calls }
757
+
758
+ it 'supports array params in url' do
759
+ conn.get('http://example.com?color[]=blue&color[]=red')
760
+ end
761
+
762
+ it 'supports array params in params' do
763
+ conn.get('http://example.com', color: %w[blue red])
764
+ end
765
+ end
766
+
767
+ context 'with flat params encoder' do
768
+ let(:options) { { request: { params_encoder: Faraday::FlatParamsEncoder } } }
769
+ let(:stubs) { Faraday::Adapter::Test::Stubs.new }
770
+
771
+ before do
772
+ conn.adapter(:test, stubs)
773
+ stubs.get('http://example.com?color=blue&color=red') do
774
+ [200, {}, 'ok']
775
+ end
776
+ end
777
+
778
+ after { stubs.verify_stubbed_calls }
779
+
780
+ it 'supports array params in params' do
781
+ conn.get('http://example.com', color: %w[blue red])
782
+ end
783
+
784
+ context 'with array param in url' do
785
+ let(:url) { 'http://example.com?color[]=blue&color[]=red' }
786
+
787
+ it do
788
+ conn.get('/')
789
+ end
790
+ end
791
+ end
792
+ end
793
+ end