|
13 | 13 | end |
14 | 14 |
|
15 | 15 | it "allows configuring the Faraday when a block is given" do |
16 | | - assert ElastomerClient::Client.new.connection.builder.handlers.none? { |handler| handler.klass == FaradayMiddleware::Instrumentation } |
| 16 | + assert ElastomerClient::Client.new.connection.builder.handlers.none? { |handler| handler.klass == ElastomerClient::Middleware::OpaqueId } |
17 | 17 |
|
18 | 18 | c = ElastomerClient::Client.new do |connection| |
19 | 19 | assert_kind_of(Faraday::Connection, connection) |
20 | 20 |
|
21 | | - connection.use :instrumentation |
| 21 | + connection.request :opaque_id |
22 | 22 | end |
23 | 23 |
|
24 | | - assert c.connection.builder.handlers.any? { |handler| handler.klass == FaradayMiddleware::Instrumentation } |
| 24 | + assert c.connection.builder.handlers.any? { |handler| handler.klass == ElastomerClient::Middleware::OpaqueId } |
25 | 25 | end |
26 | 26 |
|
27 | 27 | it "use Faraday's default adapter if none is specified" do |
|
145 | 145 | }) |
146 | 146 | client = ElastomerClient::Client.new(**client_params) |
147 | 147 |
|
148 | | - connection = Faraday::Connection.new |
149 | | - basic_auth_spy = Spy.on(connection, :basic_auth).and_return(nil) |
| 148 | + expected = "Basic #{["my_user:my_secret_password"].pack("m0")}" |
150 | 149 |
|
151 | | - Faraday.stub(:new, $client_params[:url], connection) do |
152 | | - client.ping |
153 | | - end |
154 | | - |
155 | | - assert basic_auth_spy.has_been_called_with?("my_user", "my_secret_password") |
| 150 | + assert_equal expected, client.connection.headers["Authorization"] |
156 | 151 | end |
157 | 152 |
|
158 | 153 | it "ignores basic authentication if password is missing" do |
|
161 | 156 | }) |
162 | 157 | client = ElastomerClient::Client.new(**client_params) |
163 | 158 |
|
164 | | - connection = Faraday::Connection.new |
165 | | - basic_auth_spy = Spy.on(connection, :basic_auth).and_return(nil) |
166 | | - |
167 | | - Faraday.stub(:new, $client_params[:url], connection) do |
168 | | - client.ping |
169 | | - end |
170 | | - |
171 | | - refute_predicate basic_auth_spy, :has_been_called? |
| 159 | + refute client.connection.headers.key?("Authorization") |
172 | 160 | end |
173 | 161 |
|
174 | 162 | it "ignores basic authentication if username is missing" do |
|
177 | 165 | }) |
178 | 166 | client = ElastomerClient::Client.new(**client_params) |
179 | 167 |
|
180 | | - connection = Faraday::Connection.new |
181 | | - basic_auth_spy = Spy.on(connection, :basic_auth).and_return(nil) |
182 | | - |
183 | | - Faraday.stub(:new, $client_params[:url], connection) do |
184 | | - client.ping |
185 | | - end |
186 | | - |
187 | | - refute_predicate basic_auth_spy, :has_been_called? |
| 168 | + refute client.connection.headers.key?("Authorization") |
188 | 169 | end |
189 | 170 |
|
190 | 171 | it "can use token authentication" do |
191 | 172 | client_params = $client_params.merge(token_auth: "my_secret_token") |
192 | 173 | client = ElastomerClient::Client.new(**client_params) |
193 | 174 |
|
194 | | - connection = Faraday::Connection.new |
195 | | - token_auth_spy = Spy.on(connection, :token_auth).and_return(nil) |
196 | | - |
197 | | - Faraday.stub(:new, $client_params[:url], connection) do |
198 | | - client.ping |
199 | | - end |
200 | | - |
201 | | - assert token_auth_spy.has_been_called_with?("my_secret_token") |
| 175 | + assert_equal %(Token token="my_secret_token"), client.connection.headers["Authorization"] |
202 | 176 | end |
203 | 177 |
|
204 | 178 | it "prefers token authentication over basic" do |
|
208 | 182 | }, token_auth: "my_secret_token") |
209 | 183 | client = ElastomerClient::Client.new(**client_params) |
210 | 184 |
|
211 | | - connection = Faraday::Connection.new |
212 | | - basic_auth_spy = Spy.on(connection, :basic_auth).and_return(nil) |
213 | | - token_auth_spy = Spy.on(connection, :token_auth).and_return(nil) |
214 | | - |
215 | | - Faraday.stub(:new, $client_params[:url], connection) do |
216 | | - client.ping |
217 | | - end |
218 | | - |
219 | | - refute_predicate basic_auth_spy, :has_been_called? |
220 | | - assert token_auth_spy.has_been_called_with?("my_secret_token") |
| 185 | + assert_equal %(Token token="my_secret_token"), client.connection.headers["Authorization"] |
221 | 186 | end |
222 | 187 | end |
223 | 188 |
|
|
372 | 337 | it "adding retry logic retries up to 2 times" do |
373 | 338 | retry_count = 0 |
374 | 339 |
|
| 340 | + # :retry maps to Faraday::Request::Retry on Faraday 1.x and Faraday::Retry::Middleware |
| 341 | + # on Faraday 2.x (via faraday-retry). Look up whichever the running Faraday registers. |
| 342 | + retry_klass = Faraday::Request.lookup_middleware(:retry) |
| 343 | + |
375 | 344 | retry_options = { |
376 | 345 | max: 2, |
377 | 346 | interval: 0.05, |
378 | 347 | methods: [:get], |
379 | | - exceptions: Faraday::Request::Retry::DEFAULT_EXCEPTIONS + [Faraday::ConnectionFailed], |
| 348 | + exceptions: retry_klass::DEFAULT_EXCEPTIONS + [Faraday::ConnectionFailed], |
380 | 349 | retry_block: proc { |env, options, retries, exc| retry_count += 1 } |
381 | 350 | } |
382 | 351 | retry_client = ElastomerClient::Client.new(port: 9205) do |connection| |
|
0 commit comments