lhc 12.3.0 → 13.4.0.pre.pro1766.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (71) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/rubocop.yml +15 -0
  3. data/.github/workflows/test.yml +15 -0
  4. data/.rubocop.yml +344 -19
  5. data/.ruby-version +1 -1
  6. data/Gemfile.activesupport5 +1 -1
  7. data/Gemfile.activesupport6 +1 -1
  8. data/README.md +102 -2
  9. data/Rakefile +3 -3
  10. data/lhc.gemspec +6 -3
  11. data/lib/lhc.rb +70 -59
  12. data/lib/lhc/concerns/lhc/fix_invalid_encoding_concern.rb +1 -0
  13. data/lib/lhc/config.rb +16 -0
  14. data/lib/lhc/endpoint.rb +3 -0
  15. data/lib/lhc/error.rb +7 -3
  16. data/lib/lhc/interceptor.rb +4 -0
  17. data/lib/lhc/interceptors.rb +1 -0
  18. data/lib/lhc/interceptors/auth.rb +10 -5
  19. data/lib/lhc/interceptors/caching.rb +70 -44
  20. data/lib/lhc/interceptors/logging.rb +4 -2
  21. data/lib/lhc/interceptors/monitoring.rb +46 -11
  22. data/lib/lhc/interceptors/retry.rb +2 -0
  23. data/lib/lhc/interceptors/rollbar.rb +3 -2
  24. data/lib/lhc/interceptors/throttle.rb +7 -2
  25. data/lib/lhc/interceptors/zipkin.rb +2 -0
  26. data/lib/lhc/railtie.rb +0 -1
  27. data/lib/lhc/request.rb +37 -4
  28. data/lib/lhc/response.rb +1 -0
  29. data/lib/lhc/response/data.rb +1 -1
  30. data/lib/lhc/rspec.rb +1 -2
  31. data/lib/lhc/scrubber.rb +45 -0
  32. data/lib/lhc/scrubbers/auth_scrubber.rb +32 -0
  33. data/lib/lhc/scrubbers/body_scrubber.rb +30 -0
  34. data/lib/lhc/scrubbers/headers_scrubber.rb +40 -0
  35. data/lib/lhc/scrubbers/params_scrubber.rb +14 -0
  36. data/lib/lhc/version.rb +1 -1
  37. data/spec/config/scrubs_spec.rb +108 -0
  38. data/spec/error/to_s_spec.rb +13 -8
  39. data/spec/formats/multipart_spec.rb +2 -2
  40. data/spec/formats/plain_spec.rb +1 -1
  41. data/spec/interceptors/after_response_spec.rb +1 -1
  42. data/spec/interceptors/caching/main_spec.rb +2 -2
  43. data/spec/interceptors/caching/multilevel_cache_spec.rb +139 -0
  44. data/spec/interceptors/caching/options_spec.rb +0 -11
  45. data/spec/interceptors/define_spec.rb +1 -0
  46. data/spec/interceptors/logging/main_spec.rb +21 -1
  47. data/spec/interceptors/monitoring/caching_spec.rb +66 -0
  48. data/spec/interceptors/response_competition_spec.rb +2 -2
  49. data/spec/interceptors/return_response_spec.rb +2 -2
  50. data/spec/interceptors/rollbar/main_spec.rb +27 -15
  51. data/spec/request/scrubbed_headers_spec.rb +101 -0
  52. data/spec/request/scrubbed_options_spec.rb +185 -0
  53. data/spec/request/scrubbed_params_spec.rb +25 -0
  54. data/spec/response/data_spec.rb +2 -2
  55. data/spec/spec_helper.rb +1 -0
  56. data/spec/support/zipkin_mock.rb +1 -0
  57. metadata +59 -26
  58. data/.rubocop.localch.yml +0 -325
  59. data/Gemfile.activesupport4 +0 -4
  60. data/cider-ci.yml +0 -6
  61. data/cider-ci/bin/bundle +0 -51
  62. data/cider-ci/bin/ruby_install +0 -8
  63. data/cider-ci/bin/ruby_version +0 -25
  64. data/cider-ci/jobs/rspec-activesupport-4.yml +0 -28
  65. data/cider-ci/jobs/rspec-activesupport-5.yml +0 -27
  66. data/cider-ci/jobs/rspec-activesupport-6.yml +0 -28
  67. data/cider-ci/jobs/rubocop.yml +0 -18
  68. data/cider-ci/task_components/bundle.yml +0 -22
  69. data/cider-ci/task_components/rspec.yml +0 -36
  70. data/cider-ci/task_components/rubocop.yml +0 -29
  71. data/cider-ci/task_components/ruby.yml +0 -15
@@ -45,17 +45,17 @@ describe LHC::Error do
45
45
 
46
46
  context 'some mocked response' do
47
47
  let(:request) do
48
- double('request',
48
+ double('LHC::Request',
49
49
  method: 'GET',
50
50
  url: 'http://example.com/sessions',
51
- headers: { 'Bearer Token' => "aaaaaaaa-bbbb-cccc-dddd-eeee" },
52
- options: { followlocation: true,
53
- auth: { bearer: "aaaaaaaa-bbbb-cccc-dddd-eeee" },
54
- params: { limit: 20 }, url: "http://example.com/sessions" })
51
+ scrubbed_headers: { 'Bearer Token' => LHC::Scrubber::SCRUB_DISPLAY },
52
+ scrubbed_options: { followlocation: true,
53
+ auth: { bearer: LHC::Scrubber::SCRUB_DISPLAY },
54
+ params: { limit: 20 }, url: "http://example.com/sessions" })
55
55
  end
56
56
 
57
57
  let(:response) do
58
- double('response',
58
+ double('LHC::Response',
59
59
  request: request,
60
60
  code: 500,
61
61
  options: { return_code: :internal_error, response_headers: "" },
@@ -64,11 +64,16 @@ describe LHC::Error do
64
64
 
65
65
  subject { LHC::Error.new('The error message', response) }
66
66
 
67
+ before do
68
+ allow(request).to receive(:is_a?).with(LHC::Request).and_return(true)
69
+ allow(response).to receive(:is_a?).with(LHC::Response).and_return(true)
70
+ end
71
+
67
72
  it 'produces correct debug output' do
68
73
  expect(subject.to_s.split("\n")).to eq(<<-MSG.strip_heredoc.split("\n"))
69
74
  GET http://example.com/sessions
70
- Options: {:followlocation=>true, :auth=>{:bearer=>"aaaaaaaa-bbbb-cccc-dddd-eeee"}, :params=>{:limit=>20}, :url=>"http://example.com/sessions"}
71
- Headers: {"Bearer Token"=>"aaaaaaaa-bbbb-cccc-dddd-eeee"}
75
+ Options: {:followlocation=>true, :auth=>{:bearer=>"#{LHC::Scrubber::SCRUB_DISPLAY}"}, :params=>{:limit=>20}, :url=>"http://example.com/sessions"}
76
+ Headers: {"Bearer Token"=>"#{LHC::Scrubber::SCRUB_DISPLAY}"}
72
77
  Response Code: 500 (internal_error)
73
78
  Response Options: {:return_code=>:internal_error, :response_headers=>""}
74
79
  {"status":500,"message":"undefined"}
@@ -6,14 +6,14 @@ describe LHC do
6
6
  include ActionDispatch::TestProcess
7
7
 
8
8
  context 'multipart' do
9
- let(:file) { fixture_file_upload(Tempfile.new, 'image/jpeg') }
9
+ let(:file) { Rack::Test::UploadedFile.new(Tempfile.new) }
10
10
  let(:body) { { size: 2231 }.to_json }
11
11
  let(:location) { 'http://local.ch/uploads/image.jpg' }
12
12
 
13
13
  it 'formats requests to be multipart/form-data' do
14
14
  stub_request(:post, 'http://local.ch/') do |request|
15
15
  raise 'Content-Type header wrong' unless request.headers['Content-Type'] == 'multipart/form-data'
16
- raise 'Body wrongly formatted' unless request.body.match(/file=%23%3CActionDispatch%3A%3AHttp%3A%3AUploadedFile%3A.*%3E&type=Image/)
16
+ raise 'Body wrongly formatted' unless request.body.match?(/file=%23%3CActionDispatch%3A%3AHttp%3A%3AUploadedFile%3A.*%3E&type=Image/)
17
17
  end.to_return(status: 200, body: body, headers: { 'Location' => location })
18
18
  response = LHC.multipart.post(
19
19
  'http://local.ch',
@@ -6,7 +6,7 @@ describe LHC do
6
6
  include ActionDispatch::TestProcess
7
7
 
8
8
  context 'plain' do
9
- let(:file) { fixture_file_upload(Tempfile.new, 'image/jpeg') }
9
+ let(:file) { Rack::Test::UploadedFile.new(Tempfile.new) }
10
10
 
11
11
  it 'leaves plains requests unformatted' do
12
12
  stub_request(:post, 'http://local.ch/')
@@ -14,7 +14,7 @@ describe LHC do
14
14
  uri = URI.parse(response.request.url)
15
15
  path = [
16
16
  'web',
17
- Rails.application.class.parent_name,
17
+ ((ActiveSupport.gem_version >= Gem::Version.new('6.0.0')) ? Rails.application.class.module_parent_name : Rails.application.class.parent_name).underscore,
18
18
  Rails.env,
19
19
  response.request.method,
20
20
  uri.scheme,
@@ -47,7 +47,7 @@ describe LHC::Caching do
47
47
 
48
48
  it 'lets you configure the cache key that will be used' do
49
49
  LHC.config.endpoint(:local, 'http://local.ch', cache: { key: 'STATICKEY' })
50
- expect(Rails.cache).to receive(:fetch).with("LHC_CACHE(v#{LHC::Caching::CACHE_VERSION}): STATICKEY").and_call_original
50
+ expect(Rails.cache).to receive(:fetch).at_least(:once).with("LHC_CACHE(v#{LHC::Caching::CACHE_VERSION}): STATICKEY").and_call_original
51
51
  expect(Rails.cache).to receive(:write).with("LHC_CACHE(v#{LHC::Caching::CACHE_VERSION}): STATICKEY", anything, anything).and_call_original
52
52
  stub
53
53
  LHC.get(:local)
@@ -66,8 +66,8 @@ describe LHC::Caching do
66
66
  stub
67
67
  LHC.config.endpoint(:local, 'http://local.ch', cache: true)
68
68
  original_response = LHC.get(:local)
69
- cached_response = LHC.get(:local)
70
69
  expect(original_response.from_cache?).to eq false
70
+ cached_response = LHC.get(:local)
71
71
  expect(cached_response.from_cache?).to eq true
72
72
  end
73
73
  end
@@ -0,0 +1,139 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rails_helper'
4
+
5
+ describe LHC::Caching do
6
+ let(:redis_url) { 'redis://localhost:6379/0' }
7
+ let(:redis_cache) do
8
+ spy('ActiveSupport::Cache::RedisCacheStore')
9
+ end
10
+
11
+ before do
12
+ Rails.cache.clear
13
+ LHC.config.interceptors = [LHC::Caching]
14
+ ActiveSupport::Cache::RedisCacheStore.new(url: redis_url).clear
15
+ allow(ActiveSupport::Cache::RedisCacheStore).to receive(:new).and_return(redis_cache)
16
+ allow(redis_cache).to receive(:present?).and_return(true)
17
+ end
18
+
19
+ let!(:request_stub) do
20
+ stub_request(:get, "http://local.ch/")
21
+ .to_return(body: '<h1>Hi there</h1>')
22
+ end
23
+
24
+ def request
25
+ LHC.get('http://local.ch', cache: true)
26
+ end
27
+
28
+ def response_has_been_cached_and_served_from_cache!
29
+ original_response = request
30
+ cached_response = request
31
+
32
+ expect(original_response.body).to eq cached_response.body
33
+ expect(original_response.code).to eq cached_response.code
34
+ expect(original_response.headers).to eq cached_response.headers
35
+ expect(original_response.options[:return_code]).to eq cached_response.options[:return_code]
36
+ expect(original_response.mock).to eq cached_response.mock
37
+
38
+ assert_requested request_stub, times: 1
39
+ end
40
+
41
+ context 'only local cache has been configured' do
42
+ before do
43
+ LHC::Caching.cache = Rails.cache
44
+ end
45
+
46
+ it 'serves a response from local cache without trying the central cache' do
47
+ expect(Rails.cache).to receive(:fetch).at_least(:once).and_call_original
48
+ expect(Rails.cache).to receive(:write).and_call_original
49
+ expect(-> { response_has_been_cached_and_served_from_cache! })
50
+ .to output(%Q{[LHC] served from local cache: "LHC_CACHE(v1): GET http://local.ch"\n}).to_stdout
51
+ end
52
+ end
53
+
54
+ context 'local and central cache have been configured' do
55
+ before do
56
+ LHC::Caching.cache = Rails.cache
57
+ LHC::Caching.central = {
58
+ read: redis_url,
59
+ write: redis_url
60
+ }
61
+ end
62
+
63
+ context 'found in central cache' do
64
+ it 'serves it from central cache if found there' do
65
+ expect(redis_cache).to receive(:fetch).and_return(nil,
66
+ body: '<h1>Hi there</h1>', code: 200, headers: nil, return_code: nil, mock: :webmock)
67
+ expect(redis_cache).to receive(:write).and_return(true)
68
+ expect(Rails.cache).to receive(:fetch).and_call_original
69
+ expect(Rails.cache).to receive(:write).and_call_original
70
+ expect(-> { response_has_been_cached_and_served_from_cache! })
71
+ .to output(%Q{[LHC] served from central cache: "LHC_CACHE(v1): GET http://local.ch"\n}).to_stdout
72
+ end
73
+ end
74
+
75
+ context 'not found in central cache' do
76
+ it 'serves it from local cache if found there' do
77
+ expect(redis_cache).to receive(:fetch).and_return(nil, nil)
78
+ expect(redis_cache).to receive(:write).and_return(true)
79
+ expect(Rails.cache).to receive(:fetch).at_least(:once).and_call_original
80
+ expect(Rails.cache).to receive(:write).and_call_original
81
+ expect(-> { response_has_been_cached_and_served_from_cache! })
82
+ .to output(%Q{[LHC] served from local cache: "LHC_CACHE(v1): GET http://local.ch"\n}).to_stdout
83
+ end
84
+ end
85
+ end
86
+
87
+ context 'only central read configured' do
88
+ before do
89
+ LHC::Caching.cache = Rails.cache
90
+ LHC::Caching.central = {
91
+ read: redis_url
92
+ }
93
+ end
94
+
95
+ it 'still serves responses from cache, but does not write them back' do
96
+ expect(redis_cache).to receive(:fetch).and_return(nil, body: '<h1>Hi there</h1>', code: 200, headers: nil, return_code: nil, mock: :webmock)
97
+ expect(redis_cache).not_to receive(:write)
98
+ expect(Rails.cache).to receive(:fetch).and_call_original
99
+ expect(Rails.cache).to receive(:write).and_call_original
100
+ expect(-> { response_has_been_cached_and_served_from_cache! })
101
+ .to output(%Q{[LHC] served from central cache: "LHC_CACHE(v1): GET http://local.ch"\n}).to_stdout
102
+ end
103
+ end
104
+
105
+ context 'only central write configured' do
106
+ before do
107
+ LHC::Caching.cache = Rails.cache
108
+ LHC::Caching.central = {
109
+ write: redis_url
110
+ }
111
+ end
112
+
113
+ it 'still writes responses to cache, but does not retrieve them from there' do
114
+ expect(redis_cache).not_to receive(:fetch)
115
+ expect(redis_cache).to receive(:write).and_return(true)
116
+ expect(Rails.cache).to receive(:fetch).at_least(:once).and_call_original
117
+ expect(Rails.cache).to receive(:write).and_call_original
118
+ expect(-> { response_has_been_cached_and_served_from_cache! })
119
+ .to output(%Q{[LHC] served from local cache: "LHC_CACHE(v1): GET http://local.ch"\n}).to_stdout
120
+ end
121
+ end
122
+
123
+ context 'central cache configured only' do
124
+ before do
125
+ LHC::Caching.cache = nil
126
+ LHC::Caching.central = {
127
+ read: redis_url,
128
+ write: redis_url
129
+ }
130
+ end
131
+
132
+ it 'does not inquire the local cache for information neither to write them' do
133
+ expect(redis_cache).to receive(:fetch).and_return(nil, body: '<h1>Hi there</h1>', code: 200, headers: nil, return_code: nil, mock: :webmock)
134
+ expect(redis_cache).to receive(:write).and_return(true)
135
+ expect(-> { response_has_been_cached_and_served_from_cache! })
136
+ .to output(%Q{[LHC] served from central cache: "LHC_CACHE(v1): GET http://local.ch"\n}).to_stdout
137
+ end
138
+ end
139
+ end
@@ -20,17 +20,6 @@ describe LHC::Caching do
20
20
  default_cache.clear
21
21
  end
22
22
 
23
- it 'maps deprecated cache options' do
24
- expected_options = { expires_in: 5.minutes, race_condition_ttl: 15.seconds }
25
- expected_key = "LHC_CACHE(v1): key"
26
- expect(default_cache).to receive(:write).with(expected_key, anything, expected_options)
27
- expect(lambda {
28
- LHC.get('http://local.ch', cache: true, cache_expires_in: 5.minutes, cache_key: 'key', cache_race_condition_ttl: 15.seconds)
29
- }).to output(
30
- /Cache options have changed! cache_expires_in, cache_key, cache_race_condition_ttl are deprecated and will be removed in future versions./
31
- ).to_stderr
32
- end
33
-
34
23
  it 'does cache' do
35
24
  expect(default_cache).to receive(:fetch)
36
25
  expect(default_cache).to receive(:write)
@@ -7,6 +7,7 @@ describe LHC do
7
7
  before(:each) do
8
8
  class SomeInterceptor < LHC::Interceptor
9
9
  end
10
+
10
11
  class AnotherInterceptor < LHC::Interceptor
11
12
  end
12
13
  end
@@ -8,7 +8,7 @@ describe LHC::Logging do
8
8
  before(:each) do
9
9
  LHC.config.interceptors = [LHC::Logging]
10
10
  LHC::Logging.logger = logger
11
- stub_request(:get, 'http://local.ch').to_return(status: 200)
11
+ stub_request(:get, /http:\/\/local.ch.*/).to_return(status: 200)
12
12
  end
13
13
 
14
14
  it 'does log information before and after every request made with LHC' do
@@ -34,4 +34,24 @@ describe LHC::Logging do
34
34
  )
35
35
  end
36
36
  end
37
+
38
+ context 'sensitive data' do
39
+ before :each do
40
+ LHC.config.scrubs[:params] << 'api_key'
41
+ LHC.config.scrubs[:headers] << 'private_key'
42
+ LHC.get('http://local.ch', params: { api_key: '123-abc' }, headers: { private_key: 'abc-123' })
43
+ end
44
+
45
+ it 'does log not log sensitive params information before every request made with LHC' do
46
+ expect(logger).to have_received(:info).once.with(
47
+ a_string_including("Params={:api_key=>\"#{LHC::Scrubber::SCRUB_DISPLAY}\"}")
48
+ )
49
+ end
50
+
51
+ it 'does log not log sensitive headers information before every request made with LHC' do
52
+ expect(logger).to have_received(:info).once.with(
53
+ a_string_including(":private_key=>\"#{LHC::Scrubber::SCRUB_DISPLAY}\"")
54
+ )
55
+ end
56
+ end
37
57
  end
@@ -0,0 +1,66 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rails_helper'
4
+
5
+ describe LHC::Monitoring do
6
+ let(:stub) do
7
+ stub_request(:get, 'http://local.ch').to_return(status: 200, body: 'The Website')
8
+ end
9
+
10
+ module Statsd
11
+ def self.count(_path, _value); end
12
+
13
+ def self.timing(_path, _value); end
14
+ end
15
+
16
+ before(:each) do
17
+ LHC::Monitoring.statsd = Statsd
18
+ Rails.cache.clear
19
+ allow(Statsd).to receive(:count).with('lhc.dummy.test.local_ch.get.before_request', 1)
20
+ allow(Statsd).to receive(:count).with('lhc.dummy.test.local_ch.get.count', 1)
21
+ allow(Statsd).to receive(:count).with('lhc.dummy.test.local_ch.get.after_request', 1)
22
+ allow(Statsd).to receive(:count).with('lhc.dummy.test.local_ch.get.200', 1)
23
+ end
24
+
25
+ context 'interceptors configured correctly' do
26
+ before do
27
+ LHC.config.interceptors = [LHC::Caching, LHC::Monitoring]
28
+ end
29
+
30
+ context 'requesting with cache option' do
31
+ it 'monitors miss/hit for caching' do
32
+ stub
33
+ expect(Statsd).to receive(:count).with('lhc.dummy.test.local_ch.get.cache.miss', 1)
34
+ expect(Statsd).to receive(:count).with('lhc.dummy.test.local_ch.get.cache.hit', 1)
35
+ LHC.get('http://local.ch', cache: true)
36
+ LHC.get('http://local.ch', cache: true)
37
+ end
38
+ end
39
+
40
+ context 'request uncached' do
41
+ it 'requesting without cache option' do
42
+ stub
43
+ expect(Statsd).not_to receive(:count).with('lhc.dummy.test.local_ch.get.cache.miss', 1)
44
+ expect(Statsd).not_to receive(:count).with('lhc.dummy.test.local_ch.get.cache.hit', 1)
45
+ LHC.get('http://local.ch')
46
+ LHC.get('http://local.ch')
47
+ end
48
+ end
49
+ end
50
+
51
+ context 'wrong interceptor order' do
52
+ before(:each) do
53
+ LHC.config.interceptors = [LHC::Monitoring, LHC::Caching] # monitoring needs to be after Caching
54
+ end
55
+
56
+ it 'does monitors miss/hit for caching and warns about wrong order of interceptors' do
57
+ stub
58
+ expect(Statsd).not_to receive(:count).with('lhc.dummy.test.local_ch.get.cache.miss', 1)
59
+ expect(Statsd).not_to receive(:count).with('lhc.dummy.test.local_ch.get.cache.hit', 1)
60
+ expect(-> {
61
+ LHC.get('http://local.ch', cache: true)
62
+ LHC.get('http://local.ch', cache: true)
63
+ }).to output("[WARNING] Your interceptors must include LHC::Caching and LHC::Monitoring and also in that order.\n[WARNING] Your interceptors must include LHC::Caching and LHC::Monitoring and also in that order.\n").to_stderr
64
+ end
65
+ end
66
+ end
@@ -12,7 +12,7 @@ describe LHC do
12
12
 
13
13
  def before_request
14
14
  if @@cached
15
- return LHC::Response.new(Typhoeus::Response.new(response_body: 'Im served from local cache'), nil)
15
+ return LHC::Response.new(Typhoeus::Response.new(response_code: 200, return_code: :ok, response_body: 'Im served from local cache'), nil)
16
16
  end
17
17
  end
18
18
  end
@@ -22,7 +22,7 @@ describe LHC do
22
22
 
23
23
  def before_request
24
24
  if request.response.nil?
25
- return LHC::Response.new(Typhoeus::Response.new(response_body: 'Im served from remote cache'), nil)
25
+ return LHC::Response.new(Typhoeus::Response.new(response_code: 200, return_code: :ok, response_body: 'Im served from remote cache'), nil)
26
26
  end
27
27
  end
28
28
  end
@@ -8,7 +8,7 @@ describe LHC do
8
8
  class CacheInterceptor < LHC::Interceptor
9
9
 
10
10
  def before_request
11
- LHC::Response.new(Typhoeus::Response.new(response_body: 'Im served from cache'), nil)
11
+ LHC::Response.new(Typhoeus::Response.new(response_code: 200, return_code: :ok, response_body: 'Im served from cache'), nil)
12
12
  end
13
13
  end
14
14
  LHC.configure { |c| c.interceptors = [CacheInterceptor] }
@@ -23,7 +23,7 @@ describe LHC do
23
23
  before(:each) do
24
24
  class AnotherInterceptor < LHC::Interceptor
25
25
  def before_request
26
- LHC::Response.new(Typhoeus::Response.new({}), nil)
26
+ LHC::Response.new(Typhoeus::Response.new(response_code: 200, return_code: :ok), nil)
27
27
  end
28
28
  end
29
29
  end
@@ -36,22 +36,34 @@ describe LHC::Rollbar do
36
36
  )
37
37
  end
38
38
 
39
- context 'additional params' do
40
- it 'does report errors to rollbar with additional data' do
41
- stub_request(:get, 'http://local.ch')
42
- .to_return(status: 400)
43
- expect(-> { LHC.get('http://local.ch', rollbar: { additional: 'data' }) })
44
- .to raise_error LHC::BadRequest
45
- expect(::Rollbar).to have_received(:warning)
46
- .with(
47
- 'Status: 400 URL: http://local.ch',
48
- hash_including(
49
- response: anything,
50
- request: anything,
51
- additional: 'data'
52
- )
39
+ it 'does report errors to rollbar with additional data' do
40
+ stub_request(:get, 'http://local.ch')
41
+ .to_return(status: 400)
42
+ expect(-> { LHC.get('http://local.ch', rollbar: { additional: 'data' }) })
43
+ .to raise_error LHC::BadRequest
44
+ expect(::Rollbar).to have_received(:warning)
45
+ .with(
46
+ 'Status: 400 URL: http://local.ch',
47
+ hash_including(
48
+ response: anything,
49
+ request: anything,
50
+ additional: 'data'
53
51
  )
54
- end
52
+ )
53
+ end
54
+
55
+ it 'scrubs sensitive data' do
56
+ LHC.config.scrubs[:params] << 'api_key'
57
+ LHC.config.scrubs[:headers] << 'private_key'
58
+ stub_request(:get, 'http://local.ch?api_key=123-abc').to_return(status: 400)
59
+ expect(-> { LHC.get('http://local.ch', params: { api_key: '123-abc' }, headers: { private_key: 'abc-123' }) })
60
+ .to raise_error LHC::BadRequest
61
+ expect(::Rollbar).to have_received(:warning)
62
+ .with(
63
+ 'Status: 400 URL: http://local.ch',
64
+ response: hash_including(body: anything, code: anything, headers: anything, time: anything, timeout?: anything),
65
+ request: hash_including(url: anything, method: anything, headers: hash_including(private_key: LHC::Scrubber::SCRUB_DISPLAY), params: { api_key: LHC::Scrubber::SCRUB_DISPLAY })
66
+ )
55
67
  end
56
68
  end
57
69
  end