flexirest 1.12.0 → 1.12.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 530331988751770dc906ba6b17ffafa88cc5213f8c99a67fb8e6335af2152082
4
- data.tar.gz: a55ce84b1ac4e3b1e17df27abefd3e2d9c7250a22e4368c5806a318a29ac72cd
3
+ metadata.gz: c7e62a7d0f69e17e808ebb5a91e63805618a5a0e9dee6fa4e1fabbbbe46c065b
4
+ data.tar.gz: e1961e477b96fac798530f5ea1dccdd55a6c1e1aca9f169f848492184d4b6820
5
5
  SHA512:
6
- metadata.gz: ef1ac1a698388648711b665eccbb43f0f52d751a75abe156221081f84198cdd3c426d6643db563f9bd57af9813c3ede8049114f1859603572105bec20357bfff
7
- data.tar.gz: 7f0ef624a7a958b33fcecd69f0d397e480ab98ffef1cbe3029cf87d2c290d02cb8be4b9f4c97903b6b495564dcb94607b64991ac530ec68851b13e7c474158b6
6
+ metadata.gz: 10a59eceb8374b68bd5b5a1556a5490ac8d1d1a125d2c64b56e78af6eebf5b54754813504bcb64e728211ee24c3f9ecc58791c3c5797517fbba0b3c45608be31
7
+ data.tar.gz: 66d9ef4f620f34c5657bf993e30020b3ceb49d5932a2340e4d7b9f3a0ed7e18082dd02e90c33907f25116df33c758b4ff425fd0fe9bf4fe90951fc2a73973c80
@@ -19,10 +19,10 @@ jobs:
19
19
  runs-on: ubuntu-latest
20
20
  strategy:
21
21
  matrix:
22
- ruby-version: ['3.0', '3.1', '3.2']
22
+ ruby-version: ['3.0', '3.1', '3.2', '3.3']
23
23
 
24
24
  steps:
25
- - uses: actions/checkout@v2
25
+ - uses: actions/checkout@v4
26
26
  - name: Set up Ruby
27
27
  uses: ruby/setup-ruby@v1
28
28
  with:
data/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # Changelog
2
2
 
3
+ ## 1.12.2
4
+
5
+ Bugfix:
6
+
7
+ - Changing the parameters in a `defaults` option to a mapping shouldn't mutate the parameters, meaning that retries should get the same as the original parameters (thanks to vskbjrn for the bug report)
8
+
9
+ ## 1.12.1
10
+
11
+ Bugfix:
12
+
13
+ - Usernames and passwords for simple authentication should be URL-encoded unless they're actually going in the URL (thanks to Scott Duke for the bug report)
14
+
3
15
  ## 1.12.0
4
16
 
5
17
  Bugfix:
@@ -92,7 +92,6 @@ module Flexirest
92
92
  if value.respond_to?(:call)
93
93
  @username = value
94
94
  else
95
- value = CGI::escape(value) if value.present? && !value.include?("%")
96
95
  @username = value
97
96
  end
98
97
  end
@@ -100,7 +99,6 @@ module Flexirest
100
99
 
101
100
  def username=(value)
102
101
  Flexirest::Logger.info "\033[1;4;32m#{name}\033[0m Username set to be #{value}"
103
- value = CGI::escape(value) if value.present? && !value.include?("%")
104
102
  @@username = value
105
103
  end
106
104
 
@@ -123,7 +121,6 @@ module Flexirest
123
121
  if value.respond_to?(:call)
124
122
  @password = value
125
123
  else
126
- value = CGI::escape(value) if value.present? && !value.include?("%")
127
124
  @password = value
128
125
  end
129
126
  end
@@ -131,7 +128,6 @@ module Flexirest
131
128
 
132
129
  def password=(value)
133
130
  Flexirest::Logger.info "\033[1;4;32m#{name}\033[0m Password set..."
134
- value = CGI::escape(value) if value.present? && !value.include?("%")
135
131
  @@password = value
136
132
  end
137
133
 
@@ -129,7 +129,11 @@ module Flexirest
129
129
  end
130
130
 
131
131
  def inject_basic_auth_in_url(url)
132
- url.gsub!(%r{//(.)}, "//#{username}:#{password}@\\1") if !url[%r{//[^/]*:[^/]*@}]
132
+ u = username
133
+ u = CGI::escape(u) if u.present? && !u.include?("%")
134
+ p = password
135
+ p = CGI::escape(p) if p.present? && !p.include?("%")
136
+ url.gsub!(%r{//(.)}, "//#{u}:#{p}@\\1") if !url[%r{//[^/]*:[^/]*@}]
133
137
  end
134
138
 
135
139
  def using_basic_auth?
@@ -340,6 +344,8 @@ module Flexirest
340
344
  params = {id:params}
341
345
  end
342
346
 
347
+ params = params.dup
348
+
343
349
  # Format includes parameter for jsonapi
344
350
  if proxy == :json_api
345
351
  JsonAPIProxy::Request::Params.translate(params, @object._include_associations)
@@ -1,3 +1,3 @@
1
1
  module Flexirest
2
- VERSION = "1.12.0"
2
+ VERSION = "1.12.2"
3
3
  end
@@ -81,18 +81,6 @@ describe Flexirest::Configuration do
81
81
  expect(SubConfigurationExample.username).to eq("john")
82
82
  end
83
83
 
84
- it "should escape the username" do
85
- Flexirest::Base.username = "bill@example.com"
86
- expect(Flexirest::Base.username).to eq("bill%40example.com")
87
- Flexirest::Base.username = nil
88
- end
89
-
90
- it "should not doubly escape the username" do
91
- Flexirest::Base.username = "bill%40example.com"
92
- expect(Flexirest::Base.username).to_not eq("bill%2540example.com")
93
- Flexirest::Base.username = nil
94
- end
95
-
96
84
  it "should remember the set password" do
97
85
  expect(ConfigurationExample.password).to eq("smith")
98
86
  end
@@ -107,18 +95,6 @@ describe Flexirest::Configuration do
107
95
  expect(SubConfigurationExample.password).to eq("smith")
108
96
  end
109
97
 
110
- it "should escape the password" do
111
- Flexirest::Base.password = "something@else"
112
- expect(Flexirest::Base.password).to eq("something%40else")
113
- Flexirest::Base.password = nil
114
- end
115
-
116
- it "should not doubly escape the password" do
117
- Flexirest::Base.password = "something%40else"
118
- expect(Flexirest::Base.password).to_not eq("something%2540else")
119
- Flexirest::Base.password = nil
120
- end
121
-
122
98
  it "should default to a form_encoded request_body_type" do
123
99
  expect(Flexirest::Base.request_body_type).to eq(:form_encoded)
124
100
  end
@@ -78,15 +78,15 @@ describe Flexirest::Request do
78
78
 
79
79
  class AuthenticatedExampleClient < Flexirest::Base
80
80
  base_url "http://www.example.com"
81
- username "john"
82
- password "smith"
81
+ username "john@example.com"
82
+ password "smith?$"
83
83
  get :all, "/"
84
84
  end
85
85
 
86
86
  class AuthenticatedBasicHeaderExampleClient < Flexirest::Base
87
87
  base_url "http://www.example.com"
88
- username "john"
89
- password "smith"
88
+ username "john@example.com"
89
+ password "smith?$"
90
90
  basic_auth_method :header
91
91
  get :all, "/"
92
92
  end
@@ -97,8 +97,8 @@ describe Flexirest::Request do
97
97
 
98
98
  class AuthenticatedBasicUrlExampleClient < Flexirest::Base
99
99
  base_url "http://www.example.com"
100
- username "john"
101
- password "smith"
100
+ username "john@example.com"
101
+ password "smith?$"
102
102
  basic_auth_method :url
103
103
  get :all, "/"
104
104
  end
@@ -173,6 +173,13 @@ describe Flexirest::Request do
173
173
  get :second_call, "/second_call"
174
174
  end
175
175
 
176
+ class SimpleRetryingExampleClient < Flexirest::Base
177
+ base_url "http://www.example.com"
178
+ get :all, "/objects", defaults: proc { |params| { type: params.delete(:object_type) } }
179
+
180
+ after_request -> (name, response) { raise Flexirest::CallbackRetryRequestException.new }
181
+ end
182
+
176
183
  class LazyLoadedExampleClient < ExampleClient
177
184
  base_url "http://www.example.com"
178
185
  lazy_load!
@@ -357,14 +364,14 @@ describe Flexirest::Request do
357
364
  mocked_response = ::FaradayResponseMock.new(OpenStruct.new(body:'{"result":true}', response_headers:{}))
358
365
 
359
366
  connection = double(Flexirest::Connection).as_null_object
360
- expect(Flexirest::ConnectionManager).to receive(:get_connection).with("http://john:smith@www.example.com").and_return(connection)
367
+ expect(Flexirest::ConnectionManager).to receive(:get_connection).with("http://john%40example.com:smith%3F%24@www.example.com").and_return(connection)
361
368
  expect(connection).to receive(:get).with("/", an_instance_of(Hash)).and_return(mocked_response)
362
369
  AuthenticatedExampleClient.all
363
370
  end
364
371
 
365
372
  it "should use the headers method for Basic auth when basic_auth_method is set to :header" do
366
373
  mocked_response = ::FaradayResponseMock.new(OpenStruct.new(body:'{"result":true}', response_headers:{}))
367
- headers_including_auth = hash_including({ "Authorization" => "Basic am9objpzbWl0aA==" })
374
+ headers_including_auth = hash_including({ "Authorization" => "Basic am9obkBleGFtcGxlLmNvbTpzbWl0aD8k" })
368
375
 
369
376
  connection = double(Flexirest::Connection).as_null_object
370
377
  expect(Flexirest::ConnectionManager).to receive(:get_connection).with("http://www.example.com").and_return(connection)
@@ -382,7 +389,7 @@ describe Flexirest::Request do
382
389
 
383
390
  it "should use the setting set on the parent class" do
384
391
  mocked_response = ::FaradayResponseMock.new(OpenStruct.new(body:'{"result":true}', response_headers:{}))
385
- headers_including_auth = hash_including({ "Authorization" => "Basic am9objpzbWl0aA==" })
392
+ headers_including_auth = hash_including({ "Authorization" => "Basic am9obkBleGFtcGxlLmNvbTpzbWl0aD8k" })
386
393
 
387
394
  connection = double(Flexirest::Connection).as_null_object
388
395
  expect(Flexirest::ConnectionManager).to receive(:get_connection).with("http://www.example.com").and_return(connection)
@@ -394,7 +401,7 @@ describe Flexirest::Request do
394
401
  mocked_response = ::FaradayResponseMock.new(OpenStruct.new(body:'{"result":true}', response_headers:{}))
395
402
 
396
403
  connection = double(Flexirest::Connection).as_null_object
397
- expect(Flexirest::ConnectionManager).to receive(:get_connection).with("http://john:smith@www.example.com").and_return(connection)
404
+ expect(Flexirest::ConnectionManager).to receive(:get_connection).with("http://john%40example.com:smith%3F%24@www.example.com").and_return(connection)
398
405
  expect(connection).to receive(:get) do |path, options|
399
406
  expect(path).to eq("/")
400
407
  expect(options[:headers]).to eq({"Accept"=>"application/hal+json, application/json;q=0.5", "Content-Type"=>"application/x-www-form-urlencoded; charset=utf-8"})
@@ -1395,6 +1402,13 @@ describe Flexirest::Request do
1395
1402
  expect(RetryingExampleClient.retries).to eq(2)
1396
1403
  end
1397
1404
 
1405
+ it "shouldn't destructively change params before retrying" do
1406
+ stub_request(:get, "http://www.example.com/objects?type=foo").
1407
+ to_return(status: 200, body: "", headers: {})
1408
+ SimpleRetryingExampleClient.all(object_type: 'foo')
1409
+
1410
+ expect(WebMock).to have_requested(:get, "www.example.com/objects?type=foo").twice
1411
+ end
1398
1412
 
1399
1413
  context "Direct URL requests" do
1400
1414
  class SameServerExampleClient < Flexirest::Base
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: flexirest
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.12.0
4
+ version: 1.12.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andy Jeffries
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-10-08 00:00:00.000000000 Z
11
+ date: 2024-01-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -407,7 +407,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
407
407
  - !ruby/object:Gem::Version
408
408
  version: '0'
409
409
  requirements: []
410
- rubygems_version: 3.4.6
410
+ rubygems_version: 3.4.10
411
411
  signing_key:
412
412
  specification_version: 4
413
413
  summary: This gem is for accessing REST services in a flexible way. ActiveResource