lhc 15.1.1 → 16.0.0.pre.pro2162

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 301499c3239741a748386c3e33d552611f2817f2880579b3df9e320b336db894
4
- data.tar.gz: 27c61057ca12aa70076e0fbe71da8cf8f0eac225420dcdd11ba297336aea85e8
3
+ metadata.gz: 624333537e8e35fa6ece5b46b1748263e023b439060c8e8b6b7ca0572db52ead
4
+ data.tar.gz: 588b9c2328f9ef96fa6709d6d12580083712e863838cb6e3b75b9dfb2e0efe35
5
5
  SHA512:
6
- metadata.gz: 890dd068ed2902de6990b1b90ef5082f4f6d0c26e65022db14157615dd858f7302a8419b8457f6da403f3423aabdfa13f0838a748846f7f93e13339c0415eca6
7
- data.tar.gz: e66683421af741d105294a5eb5fb33f26dbab024653b51647f3597e3256cd2bb114202d1599e4f0019f6157b08123afea794c68ddddd6f286518a99476c9dc9d
6
+ metadata.gz: d038ab78edbddf4f9d3cd8c4f8dd85285448a79498df99f02e9893bf04a68a80fc17fa286555399752452c1e68701307eb2d45112df1bb31df7f96b81c531b23
7
+ data.tar.gz: d45a0a5e8990644c7748527affe7fcee24f481f10043f6368ca90a5bbe8b76ad6e32fbfecc85e65e8f21765799926576ad815f443b34617540b6da8594f66d2b
data/README.md CHANGED
@@ -618,18 +618,12 @@ Adds the following to body of all requests:
618
618
 
619
619
  ##### Reauthenticate
620
620
 
621
- The current implementation offers only reauthentication for _client access tokens_.
622
- Make sure that your interceptors contain `LHC::Auth` and `LHC::Retry`, whereas `LHC::Retry` comes _after_ `LHC::Auth` in the chain.
623
- Provide the refresh token as following:
624
- ```ruby
625
- LHC.get('http://local.ch', auth: { bearer: -> { access_token }, refresh_client_token: -> { TokenRefreshUtil.client_access_token(true) })
626
- ```
627
- Where `TokenRefreshUtil.client_access_token(true)` forces a refresh of the token and returns the new token. It is also expected that this implementation will handle invalidating caches if necessary.
621
+ The current implementation can only offer reauthenticate for _client access tokens_. For this to work the following has to be given:
628
622
 
629
- You can also set a global `refresh_client_token`. This is not recommended for apps with multiple endpoint and different access tokens.
630
- ```ruby
631
- LHC::Auth.refresh_client_token = -> { TokenRefreshUtil.client_access_token(true) }
632
- ```
623
+ * You have configured and implemented `LHC::Auth.refresh_client_token = -> { TokenRefreshUtil.client_access_token(true) }` which when called will force a refresh of the token and return the new value. It is also expected that this implementation will handle invalidating caches if necessary.
624
+ * Your interceptors contain `LHC::Auth` and `LHC::Retry`, whereas `LHC::Retry` comes _after_ `LHC::Auth` in the chain.
625
+
626
+ ##### Bearer Authentication with client access token
633
627
 
634
628
  Reauthentication will be initiated if:
635
629
 
data/lhc.gemspec CHANGED
@@ -24,7 +24,6 @@ Gem::Specification.new do |s|
24
24
 
25
25
  s.add_dependency 'activesupport', '>= 5.2'
26
26
  s.add_dependency 'addressable'
27
- s.add_dependency 'local_uri'
28
27
  s.add_dependency 'typhoeus', '>= 0.11'
29
28
 
30
29
  s.add_development_dependency 'geminabox'
data/lib/lhc/error.rb CHANGED
@@ -75,7 +75,7 @@ class LHC::Error < StandardError
75
75
  debug << "Options: #{request.scrubbed_options}"
76
76
  debug << "Headers: #{request.scrubbed_headers}"
77
77
  debug << "Response Code: #{response.code} (#{response.options[:return_code]})"
78
- debug << "Response Options: #{response.scrubbed_options}"
78
+ debug << "Response Options: #{response.options}"
79
79
  debug << response.body
80
80
  debug << _message
81
81
  debug.map { |str| self.class.fix_invalid_encoding(str) }.join("\n")
@@ -56,9 +56,14 @@ class LHC::Auth < LHC::Interceptor
56
56
  # rubocop:enable Style/AccessorMethodName
57
57
 
58
58
  def reauthenticate!
59
- # refresh token and update header
60
- token = refresh_client_token_option.call
61
- set_bearer_authorization_header(token)
59
+ # refresh access_token
60
+ refresh_client_token_option.call
61
+
62
+ # Now as the token is refreshe
63
+ # we need to use the refreshed bearer token
64
+ # in the authorization header
65
+ bearer_authentication! if auth_options[:bearer]
66
+
62
67
  # trigger LHC::Retry and ensure we do not trigger reauthenticate!
63
68
  # again should it fail another time
64
69
  new_options = request.options.dup
data/lib/lhc/request.rb CHANGED
@@ -72,7 +72,6 @@ class LHC::Request
72
72
 
73
73
  def scrubbed_options
74
74
  scrubbed_options = options.deep_dup
75
- scrubbed_options[:cache] = LHC::CacheScrubber.new(scrubbed_options[:cache]).scrubbed
76
75
  scrubbed_options[:params] = LHC::ParamsScrubber.new(scrubbed_options[:params]).scrubbed
77
76
  scrubbed_options[:headers] = LHC::HeadersScrubber.new(scrubbed_options[:headers], scrubbed_options[:auth]).scrubbed
78
77
  scrubbed_options[:auth] = LHC::AuthScrubber.new(scrubbed_options[:auth]).scrubbed
data/lib/lhc/response.rb CHANGED
@@ -54,12 +54,6 @@ class LHC::Response
54
54
  request.format
55
55
  end
56
56
 
57
- def scrubbed_options
58
- scrubbed_options = options.deep_dup
59
- scrubbed_options[:effective_url] = LHC::EffectiveUrlScrubber.new(scrubbed_options[:effective_url]).scrubbed
60
- scrubbed_options
61
- end
62
-
63
57
  private
64
58
 
65
59
  attr_accessor :raw
data/lib/lhc/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module LHC
4
- VERSION ||= '15.1.1'
4
+ VERSION ||= '16.0.0-pro2162'
5
5
  end
data/lib/lhc.rb CHANGED
@@ -1,6 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'local_uri'
4
3
  require 'typhoeus'
5
4
  require 'active_support/core_ext/object/blank'
6
5
  require 'active_support/core_ext/hash/keys'
@@ -120,10 +119,6 @@ module LHC
120
119
  'lhc/scrubbers/auth_scrubber'
121
120
  autoload :BodyScrubber,
122
121
  'lhc/scrubbers/body_scrubber'
123
- autoload :CacheScrubber,
124
- 'lhc/scrubbers/cache_scrubber'
125
- autoload :EffectiveUrlScrubber,
126
- 'lhc/scrubbers/effective_url_scrubber'
127
122
  autoload :HeadersScrubber,
128
123
  'lhc/scrubbers/headers_scrubber'
129
124
  autoload :ParamsScrubber,
@@ -55,12 +55,10 @@ describe LHC::Error do
55
55
  end
56
56
 
57
57
  let(:response) do
58
- options = { return_code: :internal_error, response_headers: "" }
59
58
  double('LHC::Response',
60
59
  request: request,
61
60
  code: 500,
62
- options: options,
63
- scrubbed_options: options,
61
+ options: { return_code: :internal_error, response_headers: "" },
64
62
  body: '{"status":500,"message":"undefined"}')
65
63
  end
66
64
 
@@ -5,7 +5,10 @@ require 'rails_helper'
5
5
  describe LHC::Auth do
6
6
  let(:initial_token) { '123456' }
7
7
  let(:refresh_token) { 'abcdef' }
8
- let(:options) { { bearer: initial_token, refresh_client_token: -> { refresh_token } } }
8
+
9
+ let(:options) do
10
+ { bearer: -> { DummyAuthentication.access_token }, refresh_client_token: -> { DummyAuthentication.refresh_token } }
11
+ end
9
12
  let!(:auth_failing) do
10
13
  stub_request(:get, 'http://local.ch')
11
14
  .with(headers: { 'Authorization' => "Bearer #{initial_token}" })
@@ -17,6 +20,23 @@ describe LHC::Auth do
17
20
  end
18
21
 
19
22
  before(:each) do
23
+ class DummyAuthentication
24
+
25
+ def self.refresh_token
26
+ # updates access_token
27
+ end
28
+
29
+ def self.access_token
30
+ # this is used as bearer token
31
+ end
32
+ end
33
+
34
+ # It does not matter what value this method returns it is not use by LHC.
35
+ # That method needs just to make sure that the value of the access_token
36
+ # is the new valid token
37
+ allow(DummyAuthentication).to receive(:refresh_token).and_return(nil)
38
+
39
+ allow(DummyAuthentication).to receive(:access_token).and_return(initial_token, refresh_token)
20
40
  LHC.config.interceptors = [LHC::Auth, LHC::Retry]
21
41
  end
22
42
 
@@ -18,12 +18,9 @@ describe LHC::Request do
18
18
  let(:params) { { api_key: 'api-key-params' } }
19
19
  let(:headers) { { private_key: 'private-key-header' } }
20
20
  let(:body) { { user_token: 'user-token-body' } }
21
- let(:cache) do
22
- { key: "LHS_REQUEST_CYCLE_CACHE(v1) POST http://local.ch?#{params}" }
23
- end
24
21
 
25
22
  let(:request) do
26
- response = LHC.post(:local, params: params, headers: headers, body: body, cache: cache)
23
+ response = LHC.post(:local, params: params, headers: headers, body: body)
27
24
  response.request
28
25
  end
29
26
 
@@ -33,8 +30,6 @@ describe LHC::Request do
33
30
  expect(request.scrubbed_options[:body]).to include(user_token: LHC::Scrubber::SCRUB_DISPLAY)
34
31
  expect(request.scrubbed_options[:auth][:bearer_token]).to eq(LHC::Scrubber::SCRUB_DISPLAY)
35
32
  expect(request.scrubbed_options[:auth][:basic]).to be nil
36
- expect(request.scrubbed_options[:cache])
37
- .to include(key: "LHS_REQUEST_CYCLE_CACHE(v1) POST http://local.ch?{:api_key=>\"[FILTERED]\"}")
38
33
  end
39
34
 
40
35
  context 'when bearer auth is not a proc' do
@@ -58,19 +53,6 @@ describe LHC::Request do
58
53
  end
59
54
  end
60
55
 
61
- context 'when parameter should not get scrubbed' do
62
- let(:params) { { any_parameter: 'any-parameter' } }
63
-
64
- let(:cache) do
65
- { key: "LHS_REQUEST_CYCLE_CACHE(v1) POST http://local.ch?#{params}" }
66
- end
67
-
68
- it 'does not scrubb the parameter' do
69
- expect(request.scrubbed_options[:cache])
70
- .to include(key: "LHS_REQUEST_CYCLE_CACHE(v1) POST http://local.ch?#{params}")
71
- end
72
- end
73
-
74
56
  context 'when body data is nested' do
75
57
  let(:body) do
76
58
  {
@@ -122,8 +104,6 @@ describe LHC::Request do
122
104
  expect(request.scrubbed_options[:headers]).not_to include(private_key: LHC::Scrubber::SCRUB_DISPLAY)
123
105
  expect(request.scrubbed_options[:body]).not_to include(user_token: LHC::Scrubber::SCRUB_DISPLAY)
124
106
  expect(request.scrubbed_options[:auth][:bearer_token]).not_to eq(LHC::Scrubber::SCRUB_DISPLAY)
125
- expect(request.scrubbed_options[:cache])
126
- .not_to include(key: "LHS_REQUEST_CYCLE_CACHE(v1) POST http://local.ch?{:api_key=>\"[FILTERED]\"}")
127
107
  end
128
108
  end
129
109
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lhc
3
3
  version: !ruby/object:Gem::Version
4
- version: 15.1.1
4
+ version: 16.0.0.pre.pro2162
5
5
  platform: ruby
6
6
  authors:
7
7
  - https://github.com/local-ch/lhc/contributors
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-11-01 00:00:00.000000000 Z
11
+ date: 2021-10-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -38,20 +38,6 @@ dependencies:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
- - !ruby/object:Gem::Dependency
42
- name: local_uri
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - ">="
46
- - !ruby/object:Gem::Version
47
- version: '0'
48
- type: :runtime
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - ">="
53
- - !ruby/object:Gem::Version
54
- version: '0'
55
41
  - !ruby/object:Gem::Dependency
56
42
  name: typhoeus
57
43
  requirement: !ruby/object:Gem::Requirement
@@ -287,8 +273,6 @@ files:
287
273
  - lib/lhc/scrubber.rb
288
274
  - lib/lhc/scrubbers/auth_scrubber.rb
289
275
  - lib/lhc/scrubbers/body_scrubber.rb
290
- - lib/lhc/scrubbers/cache_scrubber.rb
291
- - lib/lhc/scrubbers/effective_url_scrubber.rb
292
276
  - lib/lhc/scrubbers/headers_scrubber.rb
293
277
  - lib/lhc/scrubbers/params_scrubber.rb
294
278
  - lib/lhc/test/cache_helper.rb
@@ -417,7 +401,6 @@ files:
417
401
  - spec/response/effective_url_spec.rb
418
402
  - spec/response/headers_spec.rb
419
403
  - spec/response/options_spec.rb
420
- - spec/response/scrubbed_options_spec.rb
421
404
  - spec/response/success_spec.rb
422
405
  - spec/response/time_spec.rb
423
406
  - spec/spec_helper.rb
@@ -444,9 +427,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
444
427
  version: '2.7'
445
428
  required_rubygems_version: !ruby/object:Gem::Requirement
446
429
  requirements:
447
- - - ">="
430
+ - - ">"
448
431
  - !ruby/object:Gem::Version
449
- version: '0'
432
+ version: 1.3.1
450
433
  requirements:
451
434
  - Ruby >= 2.0.0
452
435
  rubygems_version: 3.1.4
@@ -577,7 +560,6 @@ test_files:
577
560
  - spec/response/effective_url_spec.rb
578
561
  - spec/response/headers_spec.rb
579
562
  - spec/response/options_spec.rb
580
- - spec/response/scrubbed_options_spec.rb
581
563
  - spec/response/success_spec.rb
582
564
  - spec/response/time_spec.rb
583
565
  - spec/spec_helper.rb
@@ -1,35 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- class LHC::CacheScrubber < LHC::Scrubber
4
- def initialize(data)
5
- super(data)
6
- scrub_cache_options!
7
- end
8
-
9
- private
10
-
11
- def scrub_cache_options!
12
- return if scrubbed.blank?
13
- return if scrub_elements.blank?
14
-
15
- scrub_cache_key!
16
- end
17
-
18
- def scrub_cache_key!
19
- return if scrubbed[:key].blank?
20
-
21
- scrub_elements.each do |scrub_element|
22
- matches = scrubbed[:key].match(/:#{scrub_element}=>"(.*?)"/)
23
- next if matches.nil?
24
-
25
- value = matches[-1]
26
- scrubbed[:key].gsub!(value, SCRUB_DISPLAY)
27
- end
28
- end
29
-
30
- def scrub_elements
31
- # The cache key includes the whole request url inklusive params.
32
- # We need to scrub those params from the cache key.
33
- LHC.config.scrubs[:params]
34
- end
35
- end
@@ -1,32 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- class LHC::EffectiveUrlScrubber < LHC::Scrubber
4
- def initialize(data)
5
- super(data)
6
- scrub_effective_url_options!
7
- end
8
-
9
- private
10
-
11
- def scrub_effective_url_options!
12
- return if scrubbed.blank?
13
- return if scrub_elements.blank?
14
-
15
- scrub_effective_url!
16
- end
17
-
18
- def scrub_effective_url!
19
- return if scrubbed.blank?
20
-
21
- scrub_elements.each do |scrub_element|
22
- uri = LocalUri::URI.new(scrubbed)
23
- self.scrubbed = CGI.unescape(uri.query.merge(scrub_element => SCRUB_DISPLAY).to_s)
24
- end
25
- end
26
-
27
- def scrub_elements
28
- # The effective url includes the params of the request
29
- # so we need to scrub those params from the effective url.
30
- LHC.config.scrubs[:params]
31
- end
32
- end
@@ -1,20 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'rails_helper'
4
-
5
- describe LHC::Response do
6
- let(:options) do
7
- { effective_url: 'http://local.ch?api_key=api-key' }
8
- end
9
-
10
- let(:raw_response) { OpenStruct.new(options: options) }
11
-
12
- before do
13
- LHC.config.scrubs[:params] << 'api_key'
14
- end
15
-
16
- it 'scrubbes effective url' do
17
- response = LHC::Response.new(raw_response, nil)
18
- expect(response.scrubbed_options[:effective_url]).to eq "http://local.ch?api_key=#{LHC::Scrubber::SCRUB_DISPLAY}"
19
- end
20
- end