lhc 13.2.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 (43) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/rubocop.yml +3 -15
  3. data/.github/workflows/test.yml +3 -15
  4. data/.rubocop.yml +341 -19
  5. data/README.md +45 -0
  6. data/lhc.gemspec +3 -1
  7. data/lib/lhc/concerns/lhc/fix_invalid_encoding_concern.rb +1 -0
  8. data/lib/lhc/config.rb +16 -0
  9. data/lib/lhc/endpoint.rb +3 -0
  10. data/lib/lhc/error.rb +4 -2
  11. data/lib/lhc/interceptors/auth.rb +10 -1
  12. data/lib/lhc/interceptors/caching.rb +5 -0
  13. data/lib/lhc/interceptors/logging.rb +4 -2
  14. data/lib/lhc/interceptors/monitoring.rb +7 -1
  15. data/lib/lhc/interceptors/retry.rb +2 -0
  16. data/lib/lhc/interceptors/rollbar.rb +3 -2
  17. data/lib/lhc/interceptors/throttle.rb +7 -2
  18. data/lib/lhc/interceptors/zipkin.rb +2 -0
  19. data/lib/lhc/interceptors.rb +1 -0
  20. data/lib/lhc/request.rb +30 -1
  21. data/lib/lhc/response/data.rb +1 -1
  22. data/lib/lhc/response.rb +1 -0
  23. data/lib/lhc/scrubber.rb +45 -0
  24. data/lib/lhc/scrubbers/auth_scrubber.rb +32 -0
  25. data/lib/lhc/scrubbers/body_scrubber.rb +30 -0
  26. data/lib/lhc/scrubbers/headers_scrubber.rb +40 -0
  27. data/lib/lhc/scrubbers/params_scrubber.rb +14 -0
  28. data/lib/lhc/version.rb +1 -1
  29. data/lib/lhc.rb +70 -59
  30. data/spec/config/scrubs_spec.rb +108 -0
  31. data/spec/error/to_s_spec.rb +6 -6
  32. data/spec/formats/multipart_spec.rb +1 -1
  33. data/spec/interceptors/caching/multilevel_cache_spec.rb +1 -1
  34. data/spec/interceptors/define_spec.rb +1 -0
  35. data/spec/interceptors/logging/main_spec.rb +21 -1
  36. data/spec/interceptors/rollbar/main_spec.rb +27 -15
  37. data/spec/request/scrubbed_headers_spec.rb +101 -0
  38. data/spec/request/scrubbed_options_spec.rb +185 -0
  39. data/spec/request/scrubbed_params_spec.rb +25 -0
  40. data/spec/response/data_spec.rb +2 -2
  41. data/spec/support/zipkin_mock.rb +1 -0
  42. metadata +34 -8
  43. data/.rubocop.localch.yml +0 -325
data/lib/lhc.rb CHANGED
@@ -6,131 +6,142 @@ require 'active_support/core_ext/hash/keys'
6
6
 
7
7
  module LHC
8
8
  autoload :BasicMethodsConcern,
9
- 'lhc/concerns/lhc/basic_methods_concern'
9
+ 'lhc/concerns/lhc/basic_methods_concern'
10
10
  autoload :ConfigurationConcern,
11
- 'lhc/concerns/lhc/configuration_concern'
11
+ 'lhc/concerns/lhc/configuration_concern'
12
12
  autoload :FixInvalidEncodingConcern,
13
- 'lhc/concerns/lhc/fix_invalid_encoding_concern'
13
+ 'lhc/concerns/lhc/fix_invalid_encoding_concern'
14
14
  autoload :FormatsConcern,
15
- 'lhc/concerns/lhc/formats_concern'
15
+ 'lhc/concerns/lhc/formats_concern'
16
16
 
17
17
  include BasicMethodsConcern
18
18
  include ConfigurationConcern
19
19
  include FormatsConcern
20
20
 
21
21
  autoload :Auth,
22
- 'lhc/interceptors/auth'
22
+ 'lhc/interceptors/auth'
23
23
  autoload :Caching,
24
- 'lhc/interceptors/caching'
24
+ 'lhc/interceptors/caching'
25
25
  autoload :DefaultTimeout,
26
- 'lhc/interceptors/default_timeout'
26
+ 'lhc/interceptors/default_timeout'
27
27
  autoload :Logging,
28
- 'lhc/interceptors/logging'
28
+ 'lhc/interceptors/logging'
29
29
  autoload :Prometheus,
30
- 'lhc/interceptors/prometheus'
30
+ 'lhc/interceptors/prometheus'
31
31
  autoload :Retry,
32
- 'lhc/interceptors/retry'
32
+ 'lhc/interceptors/retry'
33
33
  autoload :Throttle,
34
- 'lhc/interceptors/throttle'
34
+ 'lhc/interceptors/throttle'
35
35
 
36
36
  autoload :Config,
37
- 'lhc/config'
37
+ 'lhc/config'
38
38
  autoload :Endpoint,
39
- 'lhc/endpoint'
39
+ 'lhc/endpoint'
40
40
 
41
41
  autoload :Error,
42
- 'lhc/error'
42
+ 'lhc/error'
43
43
  autoload :ClientError,
44
- 'lhc/errors/client_error'
44
+ 'lhc/errors/client_error'
45
45
  autoload :BadRequest,
46
- 'lhc/errors/client_error'
46
+ 'lhc/errors/client_error'
47
47
  autoload :Unauthorized,
48
- 'lhc/errors/client_error'
48
+ 'lhc/errors/client_error'
49
49
  autoload :PaymentRequired,
50
- 'lhc/errors/client_error'
50
+ 'lhc/errors/client_error'
51
51
  autoload :Forbidden,
52
- 'lhc/errors/client_error'
52
+ 'lhc/errors/client_error'
53
53
  autoload :Forbidden,
54
- 'lhc/errors/client_error'
54
+ 'lhc/errors/client_error'
55
55
  autoload :NotFound,
56
- 'lhc/errors/client_error'
56
+ 'lhc/errors/client_error'
57
57
  autoload :MethodNotAllowed,
58
- 'lhc/errors/client_error'
58
+ 'lhc/errors/client_error'
59
59
  autoload :NotAcceptable,
60
- 'lhc/errors/client_error'
60
+ 'lhc/errors/client_error'
61
61
  autoload :ProxyAuthenticationRequired,
62
- 'lhc/errors/client_error'
62
+ 'lhc/errors/client_error'
63
63
  autoload :RequestTimeout,
64
- 'lhc/errors/client_error'
64
+ 'lhc/errors/client_error'
65
65
  autoload :Conflict,
66
- 'lhc/errors/client_error'
66
+ 'lhc/errors/client_error'
67
67
  autoload :Gone,
68
- 'lhc/errors/client_error'
68
+ 'lhc/errors/client_error'
69
69
  autoload :LengthRequired,
70
- 'lhc/errors/client_error'
70
+ 'lhc/errors/client_error'
71
71
  autoload :PreconditionFailed,
72
- 'lhc/errors/client_error'
72
+ 'lhc/errors/client_error'
73
73
  autoload :RequestEntityTooLarge,
74
- 'lhc/errors/client_error'
74
+ 'lhc/errors/client_error'
75
75
  autoload :RequestUriToLong,
76
- 'lhc/errors/client_error'
76
+ 'lhc/errors/client_error'
77
77
  autoload :UnsupportedMediaType,
78
- 'lhc/errors/client_error'
78
+ 'lhc/errors/client_error'
79
79
  autoload :RequestedRangeNotSatisfiable,
80
- 'lhc/errors/client_error'
80
+ 'lhc/errors/client_error'
81
81
  autoload :ExpectationFailed,
82
- 'lhc/errors/client_error'
82
+ 'lhc/errors/client_error'
83
83
  autoload :UnprocessableEntity,
84
- 'lhc/errors/client_error'
84
+ 'lhc/errors/client_error'
85
85
  autoload :Locked,
86
- 'lhc/errors/client_error'
86
+ 'lhc/errors/client_error'
87
87
  autoload :FailedDependency,
88
- 'lhc/errors/client_error'
88
+ 'lhc/errors/client_error'
89
89
  autoload :UpgradeRequired,
90
- 'lhc/errors/client_error'
90
+ 'lhc/errors/client_error'
91
91
  autoload :ParserError,
92
- 'lhc/errors/parser_error'
92
+ 'lhc/errors/parser_error'
93
93
  autoload :ServerError,
94
- 'lhc/errors/server_error'
94
+ 'lhc/errors/server_error'
95
95
  autoload :InternalServerError,
96
- 'lhc/errors/server_error'
96
+ 'lhc/errors/server_error'
97
97
  autoload :NotImplemented,
98
- 'lhc/errors/server_error'
98
+ 'lhc/errors/server_error'
99
99
  autoload :BadGateway,
100
- 'lhc/errors/server_error'
100
+ 'lhc/errors/server_error'
101
101
  autoload :ServiceUnavailable,
102
- 'lhc/errors/server_error'
102
+ 'lhc/errors/server_error'
103
103
  autoload :GatewayTimeout,
104
- 'lhc/errors/server_error'
104
+ 'lhc/errors/server_error'
105
105
  autoload :HttpVersionNotSupported,
106
- 'lhc/errors/server_error'
106
+ 'lhc/errors/server_error'
107
107
  autoload :InsufficientStorage,
108
- 'lhc/errors/server_error'
108
+ 'lhc/errors/server_error'
109
109
  autoload :NotExtended,
110
- 'lhc/errors/server_error'
110
+ 'lhc/errors/server_error'
111
111
  autoload :Timeout,
112
- 'lhc/errors/timeout'
112
+ 'lhc/errors/timeout'
113
113
  autoload :UnknownError,
114
- 'lhc/errors/unknown_error'
114
+ 'lhc/errors/unknown_error'
115
+
116
+ autoload :Scrubber,
117
+ 'lhc/scrubber'
118
+ autoload :AuthScrubber,
119
+ 'lhc/scrubbers/auth_scrubber'
120
+ autoload :BodyScrubber,
121
+ 'lhc/scrubbers/body_scrubber'
122
+ autoload :HeadersScrubber,
123
+ 'lhc/scrubbers/headers_scrubber'
124
+ autoload :ParamsScrubber,
125
+ 'lhc/scrubbers/params_scrubber'
115
126
 
116
127
  autoload :Interceptor,
117
- 'lhc/interceptor'
128
+ 'lhc/interceptor'
118
129
  autoload :Interceptors,
119
- 'lhc/interceptors'
130
+ 'lhc/interceptors'
120
131
  autoload :Formats,
121
- 'lhc/formats'
132
+ 'lhc/formats'
122
133
  autoload :Format,
123
- 'lhc/format'
134
+ 'lhc/format'
124
135
  autoload :Monitoring,
125
- 'lhc/interceptors/monitoring'
136
+ 'lhc/interceptors/monitoring'
126
137
  autoload :Request,
127
- 'lhc/request'
138
+ 'lhc/request'
128
139
  autoload :Response,
129
- 'lhc/response'
140
+ 'lhc/response'
130
141
  autoload :Rollbar,
131
- 'lhc/interceptors/rollbar'
142
+ 'lhc/interceptors/rollbar'
132
143
  autoload :Zipkin,
133
- 'lhc/interceptors/zipkin'
144
+ 'lhc/interceptors/zipkin'
134
145
 
135
146
  require 'lhc/railtie' if defined?(Rails)
136
147
  end
@@ -0,0 +1,108 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rails_helper'
4
+
5
+ describe LHC do
6
+ it 'has a default value for scrubs' do
7
+ expect(LHC.config.scrubs[:auth]).to eq [:bearer, :basic]
8
+ expect(LHC.config.scrubs[:params]).to eq []
9
+ expect(LHC.config.scrubs[:headers]).to eq []
10
+ expect(LHC.config.scrubs[:body]).to eq ['password', 'password_confirmation']
11
+ end
12
+
13
+ describe 'auth' do
14
+ context 'when only bearer auth should get scrubbed' do
15
+ before(:each) do
16
+ LHC.configure do |c|
17
+ c.scrubs[:auth] = [:bearer]
18
+ end
19
+ end
20
+
21
+ it 'has only bearer auth in scrubs' do
22
+ expect(LHC.config.scrubs[:auth]).to eq([:bearer])
23
+ expect(LHC.config.scrubs[:params]).to eq []
24
+ expect(LHC.config.scrubs[:headers]).to eq []
25
+ expect(LHC.config.scrubs[:body]).to eq ['password', 'password_confirmation']
26
+ end
27
+ end
28
+ end
29
+
30
+ context 'params' do
31
+ context 'when additional param "api_key" should be scrubbed' do
32
+ before(:each) do
33
+ LHC.configure do |c|
34
+ c.scrubs[:params] << 'api_key'
35
+ end
36
+ end
37
+
38
+ it 'has "api_key" in scrubs' do
39
+ expect(LHC.config.scrubs[:auth]).to eq [:bearer, :basic]
40
+ expect(LHC.config.scrubs[:params]).to eq ['api_key']
41
+ expect(LHC.config.scrubs[:headers]).to eq []
42
+ expect(LHC.config.scrubs[:body]).to eq ['password', 'password_confirmation']
43
+ end
44
+ end
45
+ end
46
+
47
+ context 'headers' do
48
+ context 'when additional header "private_key" should be scrubbed' do
49
+ before(:each) do
50
+ LHC.configure do |c|
51
+ c.scrubs[:headers] << 'private_key'
52
+ end
53
+ end
54
+
55
+ it 'has "private_key" in scrubs' do
56
+ expect(LHC.config.scrubs[:auth]).to eq [:bearer, :basic]
57
+ expect(LHC.config.scrubs[:params]).to eq []
58
+ expect(LHC.config.scrubs[:headers]).to eq ['private_key']
59
+ expect(LHC.config.scrubs[:body]).to eq ['password', 'password_confirmation']
60
+ end
61
+ end
62
+ end
63
+
64
+ context 'body' do
65
+ context 'when only password should get scrubbed' do
66
+ before(:each) do
67
+ LHC.configure do |c|
68
+ c.scrubs[:body] = ['password']
69
+ end
70
+ end
71
+
72
+ it 'has password in scrubs' do
73
+ expect(LHC.config.scrubs[:auth]).to eq [:bearer, :basic]
74
+ expect(LHC.config.scrubs[:params]).to eq []
75
+ expect(LHC.config.scrubs[:headers]).to eq []
76
+ expect(LHC.config.scrubs[:body]).to eq(['password'])
77
+ end
78
+ end
79
+
80
+ context 'when "user_token" should be scrubbed' do
81
+ before(:each) do
82
+ LHC.configure do |c|
83
+ c.scrubs[:body] << 'user_token'
84
+ end
85
+ end
86
+
87
+ it 'has user_token in scrubs' do
88
+ expect(LHC.config.scrubs[:auth]).to eq [:bearer, :basic]
89
+ expect(LHC.config.scrubs[:params]).to eq []
90
+ expect(LHC.config.scrubs[:headers]).to eq []
91
+ expect(LHC.config.scrubs[:body]).to eq(['password', 'password_confirmation', 'user_token'])
92
+ end
93
+ end
94
+ end
95
+
96
+ context 'when nothing should be scrubbed' do
97
+ before(:each) do
98
+ LHC.configure do |c|
99
+ c.scrubs = {}
100
+ end
101
+ end
102
+
103
+ it 'does not have scrubs' do
104
+ expect(LHC.config.scrubs.blank?).to be true
105
+ expect(LHC.config.scrubs[:auth]).to be nil
106
+ end
107
+ end
108
+ end
@@ -48,10 +48,10 @@ describe LHC::Error do
48
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
@@ -72,8 +72,8 @@ describe LHC::Error do
72
72
  it 'produces correct debug output' do
73
73
  expect(subject.to_s.split("\n")).to eq(<<-MSG.strip_heredoc.split("\n"))
74
74
  GET http://example.com/sessions
75
- Options: {:followlocation=>true, :auth=>{:bearer=>"aaaaaaaa-bbbb-cccc-dddd-eeee"}, :params=>{:limit=>20}, :url=>"http://example.com/sessions"}
76
- 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}"}
77
77
  Response Code: 500 (internal_error)
78
78
  Response Options: {:return_code=>:internal_error, :response_headers=>""}
79
79
  {"status":500,"message":"undefined"}
@@ -13,7 +13,7 @@ describe LHC do
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',
@@ -63,7 +63,7 @@ describe LHC::Caching do
63
63
  context 'found in central cache' do
64
64
  it 'serves it from central cache if found there' do
65
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)
66
+ body: '<h1>Hi there</h1>', code: 200, headers: nil, return_code: nil, mock: :webmock)
67
67
  expect(redis_cache).to receive(:write).and_return(true)
68
68
  expect(Rails.cache).to receive(:fetch).and_call_original
69
69
  expect(Rails.cache).to receive(:write).and_call_original
@@ -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
@@ -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
@@ -0,0 +1,101 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rails_helper'
4
+
5
+ describe LHC::Request do
6
+ let(:headers) { { private_key: 'xyz-123' } }
7
+ let(:response) { LHC.get(:local, headers: headers) }
8
+ let(:auth) { {} }
9
+
10
+ before :each do
11
+ LHC.config.endpoint(:local, 'http://local.ch', auth: auth)
12
+ stub_request(:get, 'http://local.ch').with(headers: headers)
13
+ end
14
+
15
+ it 'scrubs "private_key"' do
16
+ LHC.config.scrubs[:headers] << 'private_key'
17
+ expect(response.request.scrubbed_headers).to include(private_key: LHC::Scrubber::SCRUB_DISPLAY)
18
+ end
19
+
20
+ it 'does not add a new attribute when a non existing header should be scrubbed' do
21
+ LHC.config.scrubs[:headers] << 'anything'
22
+ expect(response.request.scrubbed_headers).not_to include('anything' => LHC::Scrubber::SCRUB_DISPLAY)
23
+ end
24
+
25
+ context 'when strings instead of symbols are provided' do
26
+ let(:headers) { { 'private_key' => 'xyz-123' } }
27
+
28
+ it 'scrubs "private_key"' do
29
+ LHC.config.scrubs[:headers] << 'private_key'
30
+ expect(response.request.scrubbed_headers).to include('private_key' => LHC::Scrubber::SCRUB_DISPLAY)
31
+ end
32
+ end
33
+
34
+ context 'other authentication strategy' do
35
+ let(:api_key) { '123456' }
36
+ let(:authorization_header) { { 'Authorization' => "Apikey #{api_key}" } }
37
+ let(:headers) { authorization_header }
38
+
39
+ it 'provides srubbed Authorization header' do
40
+ LHC.config.scrubs[:headers] << 'Authorization'
41
+ expect(response.request.scrubbed_headers).to include('Authorization' => LHC::Scrubber::SCRUB_DISPLAY)
42
+ expect(response.request.headers).to include(authorization_header)
43
+ end
44
+ end
45
+
46
+ describe 'auth' do
47
+ before :each do
48
+ LHC.config.interceptors = [LHC::Auth]
49
+ stub_request(:get, 'http://local.ch').with(headers: authorization_header)
50
+ end
51
+
52
+ let(:request) do
53
+ response = LHC.get(:local)
54
+ response.request
55
+ end
56
+
57
+ context 'bearer authentication' do
58
+ let(:bearer_token) { '123456' }
59
+ let(:authorization_header) { { 'Authorization' => "Bearer #{bearer_token}" } }
60
+ let(:auth) { { bearer: -> { bearer_token } } }
61
+
62
+ it 'provides srubbed request headers' do
63
+ expect(request.scrubbed_headers).to include('Authorization' => "Bearer #{LHC::Scrubber::SCRUB_DISPLAY}")
64
+ expect(request.headers).to include(authorization_header)
65
+ end
66
+
67
+ context 'when nothing should get scrubbed' do
68
+ before :each do
69
+ LHC.config.scrubs = {}
70
+ end
71
+
72
+ it 'does not filter beaerer auth' do
73
+ expect(request.scrubbed_headers).to include(authorization_header)
74
+ end
75
+ end
76
+ end
77
+
78
+ context 'basic authentication' do
79
+ let(:username) { 'steve' }
80
+ let(:password) { 'abcdefg' }
81
+ let(:credentials_base_64_codiert) { Base64.strict_encode64("#{username}:#{password}").chomp }
82
+ let(:authorization_header) { { 'Authorization' => "Basic #{credentials_base_64_codiert}" } }
83
+ let(:auth) { { basic: { username: username, password: password } } }
84
+
85
+ it 'provides srubbed request headers' do
86
+ expect(request.scrubbed_headers).to include('Authorization' => "Basic #{LHC::Scrubber::SCRUB_DISPLAY}")
87
+ expect(request.headers).to include(authorization_header)
88
+ end
89
+
90
+ context 'when nothing should get scrubbed' do
91
+ before :each do
92
+ LHC.config.scrubs = {}
93
+ end
94
+
95
+ it 'does not filter basic auth' do
96
+ expect(request.scrubbed_headers).to include(authorization_header)
97
+ end
98
+ end
99
+ end
100
+ end
101
+ end