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,150 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'rack/utils'
|
4
|
+
|
5
|
+
RSpec.describe Faraday::NestedParamsEncoder do
|
6
|
+
it_behaves_like 'a params encoder'
|
7
|
+
|
8
|
+
it 'decodes arrays' do
|
9
|
+
query = 'a[1]=one&a[2]=two&a[3]=three'
|
10
|
+
expected = { 'a' => %w[one two three] }
|
11
|
+
expect(subject.decode(query)).to eq(expected)
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'decodes hashes' do
|
15
|
+
query = 'a[b1]=one&a[b2]=two&a[b][c]=foo'
|
16
|
+
expected = { 'a' => { 'b1' => 'one', 'b2' => 'two', 'b' => { 'c' => 'foo' } } }
|
17
|
+
expect(subject.decode(query)).to eq(expected)
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'decodes nested arrays rack compat' do
|
21
|
+
query = 'a[][one]=1&a[][two]=2&a[][one]=3&a[][two]=4'
|
22
|
+
expected = Rack::Utils.parse_nested_query(query)
|
23
|
+
expect(subject.decode(query)).to eq(expected)
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'decodes nested array mixed types' do
|
27
|
+
query = 'a[][one]=1&a[]=2&a[]=&a[]'
|
28
|
+
expected = Rack::Utils.parse_nested_query(query)
|
29
|
+
expect(subject.decode(query)).to eq(expected)
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'decodes nested ignores invalid array' do
|
33
|
+
query = '[][a]=1&b=2'
|
34
|
+
expected = { 'a' => '1', 'b' => '2' }
|
35
|
+
expect(subject.decode(query)).to eq(expected)
|
36
|
+
end
|
37
|
+
|
38
|
+
it 'decodes nested ignores repeated array notation' do
|
39
|
+
query = 'a[][][]=1'
|
40
|
+
expected = { 'a' => ['1'] }
|
41
|
+
expect(subject.decode(query)).to eq(expected)
|
42
|
+
end
|
43
|
+
|
44
|
+
it 'decodes nested ignores malformed keys' do
|
45
|
+
query = '=1&[]=2'
|
46
|
+
expected = {}
|
47
|
+
expect(subject.decode(query)).to eq(expected)
|
48
|
+
end
|
49
|
+
|
50
|
+
it 'decodes nested subkeys dont have to be in brackets' do
|
51
|
+
query = 'a[b]c[d]e=1'
|
52
|
+
expected = { 'a' => { 'b' => { 'c' => { 'd' => { 'e' => '1' } } } } }
|
53
|
+
expect(subject.decode(query)).to eq(expected)
|
54
|
+
end
|
55
|
+
|
56
|
+
it 'decodes nested final value overrides any type' do
|
57
|
+
query = 'a[b][c]=1&a[b]=2'
|
58
|
+
expected = { 'a' => { 'b' => '2' } }
|
59
|
+
expect(subject.decode(query)).to eq(expected)
|
60
|
+
end
|
61
|
+
|
62
|
+
it 'encodes rack compat' do
|
63
|
+
params = { a: [{ one: '1', two: '2' }, '3', ''] }
|
64
|
+
result = Faraday::Utils.unescape(Faraday::NestedParamsEncoder.encode(params)).split('&')
|
65
|
+
expected = Rack::Utils.build_nested_query(params).split('&')
|
66
|
+
expect(result).to match_array(expected)
|
67
|
+
end
|
68
|
+
|
69
|
+
it 'encodes empty string array value' do
|
70
|
+
expected = 'baz=&foo%5Bbar%5D='
|
71
|
+
result = Faraday::NestedParamsEncoder.encode(foo: { bar: '' }, baz: '')
|
72
|
+
expect(result).to eq(expected)
|
73
|
+
end
|
74
|
+
|
75
|
+
it 'encodes nil array value' do
|
76
|
+
expected = 'baz&foo%5Bbar%5D'
|
77
|
+
result = Faraday::NestedParamsEncoder.encode(foo: { bar: nil }, baz: nil)
|
78
|
+
expect(result).to eq(expected)
|
79
|
+
end
|
80
|
+
|
81
|
+
it 'encodes empty array value' do
|
82
|
+
expected = 'baz%5B%5D&foo%5Bbar%5D%5B%5D'
|
83
|
+
result = Faraday::NestedParamsEncoder.encode(foo: { bar: [] }, baz: [])
|
84
|
+
expect(result).to eq(expected)
|
85
|
+
end
|
86
|
+
|
87
|
+
it 'encodes boolean values' do
|
88
|
+
params = { a: true, b: false }
|
89
|
+
expect(subject.encode(params)).to eq('a=true&b=false')
|
90
|
+
end
|
91
|
+
|
92
|
+
it 'encodes boolean values in array' do
|
93
|
+
params = { a: [true, false] }
|
94
|
+
expect(subject.encode(params)).to eq('a%5B%5D=true&a%5B%5D=false')
|
95
|
+
end
|
96
|
+
|
97
|
+
it 'encodes unsorted when asked' do
|
98
|
+
params = { b: false, a: true }
|
99
|
+
expect(subject.encode(params)).to eq('a=true&b=false')
|
100
|
+
Faraday::NestedParamsEncoder.sort_params = false
|
101
|
+
expect(subject.encode(params)).to eq('b=false&a=true')
|
102
|
+
Faraday::NestedParamsEncoder.sort_params = true
|
103
|
+
end
|
104
|
+
|
105
|
+
it 'encodes arrays indices when asked' do
|
106
|
+
params = { a: [0, 1, 2] }
|
107
|
+
expect(subject.encode(params)).to eq('a%5B%5D=0&a%5B%5D=1&a%5B%5D=2')
|
108
|
+
Faraday::NestedParamsEncoder.array_indices = true
|
109
|
+
expect(subject.encode(params)).to eq('a%5B0%5D=0&a%5B1%5D=1&a%5B2%5D=2')
|
110
|
+
Faraday::NestedParamsEncoder.array_indices = false
|
111
|
+
end
|
112
|
+
|
113
|
+
shared_examples 'a wrong decoding' do
|
114
|
+
it do
|
115
|
+
expect { subject.decode(query) }.to raise_error(TypeError) do |e|
|
116
|
+
expect(e.message).to eq(error_message)
|
117
|
+
end
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
context 'when expecting hash but getting string' do
|
122
|
+
let(:query) { 'a=1&a[b]=2' }
|
123
|
+
let(:error_message) { "expected Hash (got String) for param `a'" }
|
124
|
+
it_behaves_like 'a wrong decoding'
|
125
|
+
end
|
126
|
+
|
127
|
+
context 'when expecting hash but getting array' do
|
128
|
+
let(:query) { 'a[]=1&a[b]=2' }
|
129
|
+
let(:error_message) { "expected Hash (got Array) for param `a'" }
|
130
|
+
it_behaves_like 'a wrong decoding'
|
131
|
+
end
|
132
|
+
|
133
|
+
context 'when expecting nested hash but getting non nested' do
|
134
|
+
let(:query) { 'a[b]=1&a[b][c]=2' }
|
135
|
+
let(:error_message) { "expected Hash (got String) for param `b'" }
|
136
|
+
it_behaves_like 'a wrong decoding'
|
137
|
+
end
|
138
|
+
|
139
|
+
context 'when expecting array but getting hash' do
|
140
|
+
let(:query) { 'a[b]=1&a[]=2' }
|
141
|
+
let(:error_message) { "expected Array (got Hash) for param `a'" }
|
142
|
+
it_behaves_like 'a wrong decoding'
|
143
|
+
end
|
144
|
+
|
145
|
+
context 'when expecting array but getting string' do
|
146
|
+
let(:query) { 'a=1&a[]=2' }
|
147
|
+
let(:error_message) { "expected Array (got String) for param `a'" }
|
148
|
+
it_behaves_like 'a wrong decoding'
|
149
|
+
end
|
150
|
+
end
|
@@ -0,0 +1,317 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
RSpec.describe Faraday::RackBuilder do
|
4
|
+
# mock handler classes
|
5
|
+
(Handler = Struct.new(:app)).class_eval do
|
6
|
+
def call(env)
|
7
|
+
env[:request_headers]['X-Middleware'] ||= ''
|
8
|
+
env[:request_headers]['X-Middleware'] += ":#{self.class.name.split('::').last}"
|
9
|
+
app.call(env)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
class Apple < Handler
|
14
|
+
end
|
15
|
+
|
16
|
+
class Orange < Handler
|
17
|
+
end
|
18
|
+
|
19
|
+
class Banana < Handler
|
20
|
+
end
|
21
|
+
|
22
|
+
subject { conn.builder }
|
23
|
+
before { Faraday.default_adapter = :test }
|
24
|
+
after { Faraday.default_adapter = nil }
|
25
|
+
|
26
|
+
context 'with default stack' do
|
27
|
+
let(:conn) { Faraday::Connection.new }
|
28
|
+
|
29
|
+
it { expect(subject[0]).to eq(Faraday::Request.lookup_middleware(:url_encoded)) }
|
30
|
+
it { expect(subject.adapter).to eq(Faraday::Adapter.lookup_middleware(Faraday.default_adapter)) }
|
31
|
+
end
|
32
|
+
|
33
|
+
context 'with custom empty block' do
|
34
|
+
let(:conn) { Faraday::Connection.new {} }
|
35
|
+
|
36
|
+
it { expect(subject[0]).to be_nil }
|
37
|
+
it { expect(subject.adapter).to eq(Faraday::Adapter.lookup_middleware(Faraday.default_adapter)) }
|
38
|
+
end
|
39
|
+
|
40
|
+
context 'with custom adapter only' do
|
41
|
+
let(:conn) do
|
42
|
+
Faraday::Connection.new do |builder|
|
43
|
+
builder.adapter :test do |stub|
|
44
|
+
stub.get('/') { |_| [200, {}, ''] }
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
it { expect(subject[0]).to be_nil }
|
50
|
+
it { expect(subject.adapter).to eq(Faraday::Adapter.lookup_middleware(:test)) }
|
51
|
+
end
|
52
|
+
|
53
|
+
context 'with custom handler and adapter' do
|
54
|
+
let(:conn) do
|
55
|
+
Faraday::Connection.new do |builder|
|
56
|
+
builder.use Apple
|
57
|
+
builder.adapter :test do |stub|
|
58
|
+
stub.get('/') { |_| [200, {}, ''] }
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
it 'locks the stack after making a request' do
|
64
|
+
expect(subject.locked?).to be_falsey
|
65
|
+
conn.get('/')
|
66
|
+
expect(subject.locked?).to be_truthy
|
67
|
+
expect { subject.use(Orange) }.to raise_error(Faraday::RackBuilder::StackLocked)
|
68
|
+
end
|
69
|
+
|
70
|
+
it 'dup stack is unlocked' do
|
71
|
+
expect(subject.locked?).to be_falsey
|
72
|
+
subject.lock!
|
73
|
+
expect(subject.locked?).to be_truthy
|
74
|
+
dup = subject.dup
|
75
|
+
expect(dup).to eq(subject)
|
76
|
+
expect(dup.locked?).to be_falsey
|
77
|
+
end
|
78
|
+
|
79
|
+
it 'allows to compare handlers' do
|
80
|
+
expect(subject.handlers.first).to eq(Faraday::RackBuilder::Handler.new(Apple))
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
context 'when having a single handler' do
|
85
|
+
let(:conn) { Faraday::Connection.new {} }
|
86
|
+
|
87
|
+
before { subject.use(Apple) }
|
88
|
+
|
89
|
+
it { expect(subject.handlers).to eq([Apple]) }
|
90
|
+
|
91
|
+
it 'allows use' do
|
92
|
+
subject.use(Orange)
|
93
|
+
expect(subject.handlers).to eq([Apple, Orange])
|
94
|
+
end
|
95
|
+
|
96
|
+
it 'allows insert_before' do
|
97
|
+
subject.insert_before(Apple, Orange)
|
98
|
+
expect(subject.handlers).to eq([Orange, Apple])
|
99
|
+
end
|
100
|
+
|
101
|
+
it 'allows insert_after' do
|
102
|
+
subject.insert_after(Apple, Orange)
|
103
|
+
expect(subject.handlers).to eq([Apple, Orange])
|
104
|
+
end
|
105
|
+
|
106
|
+
it 'raises an error trying to use an unregistered symbol' do
|
107
|
+
expect { subject.use(:apple) }.to raise_error(Faraday::Error) do |err|
|
108
|
+
expect(err.message).to eq(':apple is not registered on Faraday::Middleware')
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
context 'when having two handlers' do
|
114
|
+
let(:conn) { Faraday::Connection.new {} }
|
115
|
+
|
116
|
+
before do
|
117
|
+
subject.use(Apple)
|
118
|
+
subject.use(Orange)
|
119
|
+
end
|
120
|
+
|
121
|
+
it 'allows insert_before' do
|
122
|
+
subject.insert_before(Orange, Banana)
|
123
|
+
expect(subject.handlers).to eq([Apple, Banana, Orange])
|
124
|
+
end
|
125
|
+
|
126
|
+
it 'allows insert_after' do
|
127
|
+
subject.insert_after(Apple, Banana)
|
128
|
+
expect(subject.handlers).to eq([Apple, Banana, Orange])
|
129
|
+
end
|
130
|
+
|
131
|
+
it 'allows to swap handlers' do
|
132
|
+
subject.swap(Apple, Banana)
|
133
|
+
expect(subject.handlers).to eq([Banana, Orange])
|
134
|
+
end
|
135
|
+
|
136
|
+
it 'allows to delete a handler' do
|
137
|
+
subject.delete(Apple)
|
138
|
+
expect(subject.handlers).to eq([Orange])
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
context 'when adapter is added with named options' do
|
143
|
+
after { Faraday.default_adapter_options = {} }
|
144
|
+
let(:conn) { Faraday::Connection.new {} }
|
145
|
+
|
146
|
+
let(:cat_adapter) do
|
147
|
+
Class.new(Faraday::Adapter) do
|
148
|
+
attr_accessor :name
|
149
|
+
|
150
|
+
def initialize(app, name:)
|
151
|
+
super(app)
|
152
|
+
@name = name
|
153
|
+
end
|
154
|
+
end
|
155
|
+
end
|
156
|
+
|
157
|
+
let(:cat) { subject.adapter.build }
|
158
|
+
|
159
|
+
it 'adds a handler to construct adapter with named options' do
|
160
|
+
Faraday.default_adapter = cat_adapter
|
161
|
+
Faraday.default_adapter_options = { name: 'Chloe' }
|
162
|
+
expect { cat }.to_not output(
|
163
|
+
/warning: Using the last argument as keyword parameters is deprecated/
|
164
|
+
).to_stderr
|
165
|
+
expect(cat.name).to eq 'Chloe'
|
166
|
+
end
|
167
|
+
end
|
168
|
+
|
169
|
+
context 'when middleware is added with named arguments' do
|
170
|
+
let(:conn) { Faraday::Connection.new {} }
|
171
|
+
|
172
|
+
let(:dog_middleware) do
|
173
|
+
Class.new(Faraday::Middleware) do
|
174
|
+
attr_accessor :name
|
175
|
+
|
176
|
+
def initialize(app, name:)
|
177
|
+
super(app)
|
178
|
+
@name = name
|
179
|
+
end
|
180
|
+
end
|
181
|
+
end
|
182
|
+
let(:dog) do
|
183
|
+
subject.handlers.find { |handler| handler == dog_middleware }.build
|
184
|
+
end
|
185
|
+
|
186
|
+
it 'adds a handler to construct middleware with options passed to use' do
|
187
|
+
subject.use dog_middleware, name: 'Rex'
|
188
|
+
expect { dog }.to_not output(
|
189
|
+
/warning: Using the last argument as keyword parameters is deprecated/
|
190
|
+
).to_stderr
|
191
|
+
expect(dog.name).to eq('Rex')
|
192
|
+
end
|
193
|
+
end
|
194
|
+
|
195
|
+
context 'when a middleware is added with named arguments' do
|
196
|
+
let(:conn) { Faraday::Connection.new {} }
|
197
|
+
|
198
|
+
let(:cat_request) do
|
199
|
+
Class.new(Faraday::Middleware) do
|
200
|
+
attr_accessor :name
|
201
|
+
|
202
|
+
def initialize(app, name:)
|
203
|
+
super(app)
|
204
|
+
@name = name
|
205
|
+
end
|
206
|
+
end
|
207
|
+
end
|
208
|
+
let(:cat) do
|
209
|
+
subject.handlers.find { |handler| handler == cat_request }.build
|
210
|
+
end
|
211
|
+
|
212
|
+
it 'adds a handler to construct request adapter with options passed to request' do
|
213
|
+
Faraday::Request.register_middleware cat_request: cat_request
|
214
|
+
subject.request :cat_request, name: 'Felix'
|
215
|
+
expect { cat }.to_not output(
|
216
|
+
/warning: Using the last argument as keyword parameters is deprecated/
|
217
|
+
).to_stderr
|
218
|
+
expect(cat.name).to eq('Felix')
|
219
|
+
end
|
220
|
+
end
|
221
|
+
|
222
|
+
context 'when a middleware is added with named arguments' do
|
223
|
+
let(:conn) { Faraday::Connection.new {} }
|
224
|
+
|
225
|
+
let(:fish_response) do
|
226
|
+
Class.new(Faraday::Middleware) do
|
227
|
+
attr_accessor :name
|
228
|
+
|
229
|
+
def initialize(app, name:)
|
230
|
+
super(app)
|
231
|
+
@name = name
|
232
|
+
end
|
233
|
+
end
|
234
|
+
end
|
235
|
+
let(:fish) do
|
236
|
+
subject.handlers.find { |handler| handler == fish_response }.build
|
237
|
+
end
|
238
|
+
|
239
|
+
it 'adds a handler to construct response adapter with options passed to response' do
|
240
|
+
Faraday::Response.register_middleware fish_response: fish_response
|
241
|
+
subject.response :fish_response, name: 'Bubbles'
|
242
|
+
expect { fish }.to_not output(
|
243
|
+
/warning: Using the last argument as keyword parameters is deprecated/
|
244
|
+
).to_stderr
|
245
|
+
expect(fish.name).to eq('Bubbles')
|
246
|
+
end
|
247
|
+
end
|
248
|
+
|
249
|
+
context 'when a plain adapter is added with named arguments' do
|
250
|
+
let(:conn) { Faraday::Connection.new {} }
|
251
|
+
|
252
|
+
let(:rabbit_adapter) do
|
253
|
+
Class.new(Faraday::Adapter) do
|
254
|
+
attr_accessor :name
|
255
|
+
|
256
|
+
def initialize(app, name:)
|
257
|
+
super(app)
|
258
|
+
@name = name
|
259
|
+
end
|
260
|
+
end
|
261
|
+
end
|
262
|
+
let(:rabbit) do
|
263
|
+
subject.adapter.build
|
264
|
+
end
|
265
|
+
|
266
|
+
it 'adds a handler to construct adapter with options passed to adapter' do
|
267
|
+
Faraday::Adapter.register_middleware rabbit_adapter: rabbit_adapter
|
268
|
+
subject.adapter :rabbit_adapter, name: 'Thumper'
|
269
|
+
expect { rabbit }.to_not output(
|
270
|
+
/warning: Using the last argument as keyword parameters is deprecated/
|
271
|
+
).to_stderr
|
272
|
+
expect(rabbit.name).to eq('Thumper')
|
273
|
+
end
|
274
|
+
end
|
275
|
+
|
276
|
+
context 'when handlers are directly added or updated' do
|
277
|
+
let(:conn) { Faraday::Connection.new {} }
|
278
|
+
|
279
|
+
let(:rock_handler) do
|
280
|
+
Class.new do
|
281
|
+
attr_accessor :name
|
282
|
+
|
283
|
+
def initialize(_app, name:)
|
284
|
+
@name = name
|
285
|
+
end
|
286
|
+
end
|
287
|
+
end
|
288
|
+
let(:rock) do
|
289
|
+
subject.handlers.find { |handler| handler == rock_handler }.build
|
290
|
+
end
|
291
|
+
|
292
|
+
it 'adds a handler to construct adapter with options passed to insert' do
|
293
|
+
subject.insert 0, rock_handler, name: 'Stony'
|
294
|
+
expect { rock }.to_not output(
|
295
|
+
/warning: Using the last argument as keyword parameters is deprecated/
|
296
|
+
).to_stderr
|
297
|
+
expect(rock.name).to eq('Stony')
|
298
|
+
end
|
299
|
+
|
300
|
+
it 'adds a handler with options passed to insert_after' do
|
301
|
+
subject.insert_after 0, rock_handler, name: 'Rocky'
|
302
|
+
expect { rock }.to_not output(
|
303
|
+
/warning: Using the last argument as keyword parameters is deprecated/
|
304
|
+
).to_stderr
|
305
|
+
expect(rock.name).to eq('Rocky')
|
306
|
+
end
|
307
|
+
|
308
|
+
it 'adds a handler with options passed to swap' do
|
309
|
+
subject.insert 0, rock_handler, name: 'Flint'
|
310
|
+
subject.swap 0, rock_handler, name: 'Chert'
|
311
|
+
expect { rock }.to_not output(
|
312
|
+
/warning: Using the last argument as keyword parameters is deprecated/
|
313
|
+
).to_stderr
|
314
|
+
expect(rock.name).to eq('Chert')
|
315
|
+
end
|
316
|
+
end
|
317
|
+
end
|
@@ -0,0 +1,83 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
RSpec.describe Faraday::Request::Authorization do
|
4
|
+
let(:conn) do
|
5
|
+
Faraday.new do |b|
|
6
|
+
b.request :authorization, auth_type, *auth_config
|
7
|
+
b.adapter :test do |stub|
|
8
|
+
stub.get('/auth-echo') do |env|
|
9
|
+
[200, {}, env[:request_headers]['Authorization']]
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
shared_examples 'does not interfere with existing authentication' do
|
16
|
+
context 'and request already has an authentication header' do
|
17
|
+
let(:response) { conn.get('/auth-echo', nil, authorization: 'OAuth oauth_token') }
|
18
|
+
|
19
|
+
it 'does not interfere with existing authorization' do
|
20
|
+
expect(response.body).to eq('OAuth oauth_token')
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
let(:response) { conn.get('/auth-echo') }
|
26
|
+
|
27
|
+
describe 'basic_auth' do
|
28
|
+
let(:auth_type) { :basic }
|
29
|
+
|
30
|
+
context 'when passed correct params' do
|
31
|
+
let(:auth_config) { %w[aladdin opensesame] }
|
32
|
+
|
33
|
+
it { expect(response.body).to eq('Basic YWxhZGRpbjpvcGVuc2VzYW1l') }
|
34
|
+
|
35
|
+
include_examples 'does not interfere with existing authentication'
|
36
|
+
end
|
37
|
+
|
38
|
+
context 'when passed very long values' do
|
39
|
+
let(:auth_config) { ['A' * 255, ''] }
|
40
|
+
|
41
|
+
it { expect(response.body).to eq("Basic #{'QUFB' * 85}Og==") }
|
42
|
+
|
43
|
+
include_examples 'does not interfere with existing authentication'
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
describe 'authorization' do
|
48
|
+
let(:auth_type) { :Bearer }
|
49
|
+
|
50
|
+
context 'when passed a string' do
|
51
|
+
let(:auth_config) { ['custom'] }
|
52
|
+
|
53
|
+
it { expect(response.body).to eq('Bearer custom') }
|
54
|
+
|
55
|
+
include_examples 'does not interfere with existing authentication'
|
56
|
+
end
|
57
|
+
|
58
|
+
context 'when passed a proc' do
|
59
|
+
let(:auth_config) { [-> { 'custom_from_proc' }] }
|
60
|
+
|
61
|
+
it { expect(response.body).to eq('Bearer custom_from_proc') }
|
62
|
+
|
63
|
+
include_examples 'does not interfere with existing authentication'
|
64
|
+
end
|
65
|
+
|
66
|
+
context 'when passed a callable' do
|
67
|
+
let(:callable) { double('Callable Authorizer', call: 'custom_from_callable') }
|
68
|
+
let(:auth_config) { [callable] }
|
69
|
+
|
70
|
+
it { expect(response.body).to eq('Bearer custom_from_callable') }
|
71
|
+
|
72
|
+
include_examples 'does not interfere with existing authentication'
|
73
|
+
end
|
74
|
+
|
75
|
+
context 'when passed too many arguments' do
|
76
|
+
let(:auth_config) { %w[baz foo] }
|
77
|
+
|
78
|
+
it { expect { response }.to raise_error(ArgumentError) }
|
79
|
+
|
80
|
+
include_examples 'does not interfere with existing authentication'
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
@@ -0,0 +1,74 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
RSpec.describe Faraday::Request::Instrumentation do
|
4
|
+
class FakeInstrumenter
|
5
|
+
attr_reader :instrumentations
|
6
|
+
|
7
|
+
def initialize
|
8
|
+
@instrumentations = []
|
9
|
+
end
|
10
|
+
|
11
|
+
def instrument(name, env)
|
12
|
+
@instrumentations << [name, env]
|
13
|
+
yield
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
let(:config) { {} }
|
18
|
+
let(:options) { Faraday::Request::Instrumentation::Options.from config }
|
19
|
+
let(:instrumenter) { FakeInstrumenter.new }
|
20
|
+
let(:conn) do
|
21
|
+
Faraday.new do |f|
|
22
|
+
f.request :instrumentation, config.merge(instrumenter: instrumenter)
|
23
|
+
f.adapter :test do |stub|
|
24
|
+
stub.get '/' do
|
25
|
+
[200, {}, 'ok']
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
it { expect(options.name).to eq('request.faraday') }
|
32
|
+
it 'defaults to ActiveSupport::Notifications' do
|
33
|
+
res = options.instrumenter
|
34
|
+
rescue NameError => e
|
35
|
+
expect(e.to_s).to match('ActiveSupport')
|
36
|
+
else
|
37
|
+
expect(res).to eq(ActiveSupport::Notifications)
|
38
|
+
end
|
39
|
+
|
40
|
+
it 'instruments with default name' do
|
41
|
+
expect(instrumenter.instrumentations.size).to eq(0)
|
42
|
+
|
43
|
+
res = conn.get '/'
|
44
|
+
expect(res.body).to eq('ok')
|
45
|
+
expect(instrumenter.instrumentations.size).to eq(1)
|
46
|
+
|
47
|
+
name, env = instrumenter.instrumentations.first
|
48
|
+
expect(name).to eq('request.faraday')
|
49
|
+
expect(env[:url].path).to eq('/')
|
50
|
+
end
|
51
|
+
|
52
|
+
context 'with custom name' do
|
53
|
+
let(:config) { { name: 'custom' } }
|
54
|
+
|
55
|
+
it { expect(options.name).to eq('custom') }
|
56
|
+
it 'instruments with custom name' do
|
57
|
+
expect(instrumenter.instrumentations.size).to eq(0)
|
58
|
+
|
59
|
+
res = conn.get '/'
|
60
|
+
expect(res.body).to eq('ok')
|
61
|
+
expect(instrumenter.instrumentations.size).to eq(1)
|
62
|
+
|
63
|
+
name, env = instrumenter.instrumentations.first
|
64
|
+
expect(name).to eq('custom')
|
65
|
+
expect(env[:url].path).to eq('/')
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
context 'with custom instrumenter' do
|
70
|
+
let(:config) { { instrumenter: :custom } }
|
71
|
+
|
72
|
+
it { expect(options.instrumenter).to eq(:custom) }
|
73
|
+
end
|
74
|
+
end
|