lenjador 1.2.1 → 2.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/spec/spec_helper.rb CHANGED
@@ -5,7 +5,7 @@ Bundler.setup
5
5
 
6
6
  require 'lenjador'
7
7
 
8
- Dir[File.dirname(__FILE__) + '/support/*.rb'].each {|f| require f}
8
+ Dir["#{File.dirname(__FILE__)}/support/*.rb"].sort.each { |f| require f }
9
9
 
10
10
  RSpec.configure do |config|
11
11
  config.run_all_when_everything_filtered = true
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lenjador
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.1
4
+ version: 2.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Salemove
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-05-28 00:00:00.000000000 Z
11
+ date: 2021-05-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: lru_redux
@@ -26,12 +26,26 @@ dependencies:
26
26
  version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: oj
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '3.6'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '3.6'
41
+ - !ruby/object:Gem::Dependency
42
+ name: benchmark-ips
29
43
  requirement: !ruby/object:Gem::Requirement
30
44
  requirements:
31
45
  - - ">="
32
46
  - !ruby/object:Gem::Version
33
47
  version: '0'
34
- type: :runtime
48
+ type: :development
35
49
  prerelease: false
36
50
  version_requirements: !ruby/object:Gem::Requirement
37
51
  requirements:
@@ -42,16 +56,30 @@ dependencies:
42
56
  name: bundler
43
57
  requirement: !ruby/object:Gem::Requirement
44
58
  requirements:
45
- - - "~>"
59
+ - - ">="
46
60
  - !ruby/object:Gem::Version
47
- version: '1.3'
61
+ version: '0'
48
62
  type: :development
49
63
  prerelease: false
50
64
  version_requirements: !ruby/object:Gem::Requirement
51
65
  requirements:
52
- - - "~>"
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: pry
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
53
81
  - !ruby/object:Gem::Version
54
- version: '1.3'
82
+ version: '0'
55
83
  - !ruby/object:Gem::Dependency
56
84
  name: rake
57
85
  requirement: !ruby/object:Gem::Requirement
@@ -67,7 +95,7 @@ dependencies:
67
95
  - !ruby/object:Gem::Version
68
96
  version: '0'
69
97
  - !ruby/object:Gem::Dependency
70
- name: bunny
98
+ name: rspec
71
99
  requirement: !ruby/object:Gem::Requirement
72
100
  requirements:
73
101
  - - ">="
@@ -81,7 +109,21 @@ dependencies:
81
109
  - !ruby/object:Gem::Version
82
110
  version: '0'
83
111
  - !ruby/object:Gem::Dependency
84
- name: benchmark-ips
112
+ name: rubocop-salemove
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: ruby-prof
85
127
  requirement: !ruby/object:Gem::Requirement
86
128
  requirements:
87
129
  - - ">="
@@ -103,6 +145,7 @@ extra_rdoc_files: []
103
145
  files:
104
146
  - ".gitignore"
105
147
  - ".rspec"
148
+ - ".rubocop.yml"
106
149
  - ".ruby-gemset"
107
150
  - ".ruby-version"
108
151
  - ".travis.yml"
@@ -123,15 +166,16 @@ files:
123
166
  - lib/lenjador/preprocessors/strategies/prune.rb
124
167
  - lib/lenjador/preprocessors/whitelist.rb
125
168
  - lib/lenjador/utils.rb
126
- - spec/adapters/stdout_adapter_spec.rb
127
- - spec/adapters/stdout_json_adapter_spec.rb
169
+ - profiler/logs.rb
170
+ - spec/lenjador/adapters/stdout_adapter_spec.rb
171
+ - spec/lenjador/adapters/stdout_json_adapter_spec.rb
172
+ - spec/lenjador/preprocessors/blacklist_spec.rb
173
+ - spec/lenjador/preprocessors/json_pointer_trie_spec.rb
174
+ - spec/lenjador/preprocessors/whitelist_spec.rb
175
+ - spec/lenjador/utils_spec.rb
128
176
  - spec/lenjador_spec.rb
129
- - spec/preprocessors/blacklist_spec.rb
130
- - spec/preprocessors/json_pointer_trie.rb
131
- - spec/preprocessors/whitelist_spec.rb
132
177
  - spec/spec_helper.rb
133
178
  - spec/support/implement_interface.rb
134
- - spec/utils_spec.rb
135
179
  homepage:
136
180
  licenses:
137
181
  - MIT
@@ -144,25 +188,24 @@ required_ruby_version: !ruby/object:Gem::Requirement
144
188
  requirements:
145
189
  - - ">="
146
190
  - !ruby/object:Gem::Version
147
- version: '0'
191
+ version: '2.4'
148
192
  required_rubygems_version: !ruby/object:Gem::Requirement
149
193
  requirements:
150
194
  - - ">="
151
195
  - !ruby/object:Gem::Version
152
196
  version: '0'
153
197
  requirements: []
154
- rubyforge_project:
155
- rubygems_version: 2.6.11
198
+ rubygems_version: 3.1.2
156
199
  signing_key:
157
200
  specification_version: 4
158
201
  summary: What description said
159
202
  test_files:
160
- - spec/adapters/stdout_adapter_spec.rb
161
- - spec/adapters/stdout_json_adapter_spec.rb
203
+ - spec/lenjador/adapters/stdout_adapter_spec.rb
204
+ - spec/lenjador/adapters/stdout_json_adapter_spec.rb
205
+ - spec/lenjador/preprocessors/blacklist_spec.rb
206
+ - spec/lenjador/preprocessors/json_pointer_trie_spec.rb
207
+ - spec/lenjador/preprocessors/whitelist_spec.rb
208
+ - spec/lenjador/utils_spec.rb
162
209
  - spec/lenjador_spec.rb
163
- - spec/preprocessors/blacklist_spec.rb
164
- - spec/preprocessors/json_pointer_trie.rb
165
- - spec/preprocessors/whitelist_spec.rb
166
210
  - spec/spec_helper.rb
167
211
  - spec/support/implement_interface.rb
168
- - spec/utils_spec.rb
@@ -1,48 +0,0 @@
1
- require 'spec_helper'
2
- require_relative '../../lib/lenjador/adapters/stdout_adapter'
3
-
4
- describe Lenjador::Adapters::StdoutAdapter do
5
- it 'creates a stdout logger' do
6
- io_logger = described_class.new(0)
7
-
8
- logger = io_logger.instance_variable_get(:@logger)
9
- expect(logger).to be_a Logger
10
- end
11
-
12
- describe '#log' do
13
- let(:adapter) { described_class.new(0) }
14
- let(:logger) { adapter.logger }
15
-
16
- context 'with only a message' do
17
- it 'stringifies it correctly' do
18
- expect(logger).to receive(:info).with('test')
19
-
20
- adapter.log :info, message: 'test'
21
- end
22
- end
23
-
24
- context 'with an empty message' do
25
- it 'stringifies it correctly' do
26
- expect(logger).to receive(:info).with(' {"a":"b"}')
27
-
28
- adapter.log :info, message: '', a: 'b'
29
- end
30
- end
31
-
32
- context 'with no message' do
33
- it 'stringifies it correctly' do
34
- expect(logger).to receive(:info).with('{"a":"b"}')
35
-
36
- adapter.log :info, a: 'b'
37
- end
38
- end
39
-
40
- context 'with a message and metadata' do
41
- it 'stringifies it correctly' do
42
- expect(logger).to receive(:info).with('test {"a":"b"}')
43
-
44
- adapter.log :info, message: 'test', a: 'b'
45
- end
46
- end
47
- end
48
- end
@@ -1,62 +0,0 @@
1
- require 'spec_helper'
2
- require 'json'
3
- require_relative '../../lib/lenjador/adapters/stdout_json_adapter'
4
-
5
- describe Lenjador::Adapters::StdoutJsonAdapter do
6
- let(:debug_level_code) { 0 }
7
- let(:debug_level) { Lenjador::Adapters::LOG_LEVELS[debug_level_code] }
8
- let(:info_level_code) { 1 }
9
- let(:info_level) { Lenjador::Adapters::LOG_LEVELS[info_level_code] }
10
-
11
- let(:stdout) { StringIO.new }
12
-
13
- around do |example|
14
- old_stdout = $stdout
15
- $stdout = stdout
16
-
17
- begin
18
- example.call
19
- ensure
20
- $stdout = old_stdout
21
- end
22
- end
23
-
24
- describe '#log' do
25
- context 'when below threshold' do
26
- let(:adapter) { described_class.new(debug_level_code, service_name) }
27
- let(:metadata) { {x: 'y'} }
28
- let(:event) { {a: 'b', x: 'y'} }
29
- let(:serialized_event) { JSON.dump(event) }
30
- let(:service_name) { 'my-service' }
31
- let(:application_name) { 'my_service' }
32
-
33
- before do
34
- allow(Lenjador::Utils).to receive(:build_event)
35
- .with(metadata, info_level, application_name)
36
- .and_return(event)
37
- end
38
-
39
- it 'sends serialized event to $stdout' do
40
- adapter.log(info_level, metadata)
41
- expect(output).to eq serialized_event + "\n"
42
- end
43
- end
44
-
45
- context 'when above threshold' do
46
- let(:adapter) { described_class.new(info_level_code, service_name) }
47
- let(:metadata) { {x: 'y'} }
48
- let(:service_name) { 'my-service' }
49
-
50
- it 'does not log the event' do
51
- adapter.log(debug_level, metadata)
52
- expect(output).to be_empty
53
- end
54
- end
55
- end
56
-
57
- private
58
-
59
- def output
60
- stdout.string
61
- end
62
- end
@@ -1,335 +0,0 @@
1
- require 'spec_helper'
2
- require_relative '../../lib/lenjador/preprocessors/whitelist'
3
-
4
- RSpec.describe Lenjador::Preprocessors::Whitelist, 'when :action is :mask or omitted' do
5
- subject(:processed_data) { described_class.new(config).process(data) }
6
-
7
- let(:config) { { pointers: pointers } }
8
- let(:pointers) { [] }
9
- let(:data) do
10
- {
11
- field: 'secret',
12
- data: {
13
- field: 'secret'
14
- },
15
- array: [{ field: 'secret' }]
16
- }
17
- end
18
-
19
- it 'masks all non-whitelisted fields' do
20
- expect(processed_data).to eq(
21
- field: '*****',
22
- data: '*****',
23
- array: '*****'
24
- )
25
- end
26
-
27
- context 'when pointer has trailing slash' do
28
- let(:pointers) { ['/field/'] }
29
-
30
- it 'throws exception' do
31
- expect { processed_data }.to raise_exception(Lenjador::Preprocessors::Whitelist::InvalidPointerFormatException)
32
- end
33
- end
34
-
35
- context 'with whitelisted field' do
36
- let(:pointers) { ['/field'] }
37
-
38
- it 'includes the field' do
39
- expect(processed_data).to eq(
40
- field: 'secret',
41
- data: '*****',
42
- array: '*****'
43
- )
44
- end
45
- end
46
-
47
- context 'with whitelisted nested field' do
48
- let(:pointers) { ['/data/field'] }
49
-
50
- it 'includes nested field' do
51
- expect(processed_data).to eq(
52
- field: '*****',
53
- data: {
54
- field: 'secret'
55
- },
56
- array: '*****'
57
- )
58
- end
59
- end
60
-
61
- context 'with whitelisted array element field' do
62
- let(:pointers) { ['/array/0/field'] }
63
-
64
- it 'includes array element' do
65
- expect(processed_data).to eq(
66
- field: '*****',
67
- data: '*****',
68
- array: [{ field: 'secret' }]
69
- )
70
- end
71
- end
72
-
73
- context 'with whitelisted hash' do
74
- it 'includes all whitelisted hash elements' do
75
- source = { foo: { bar: 'baz' } }
76
- target = { foo: { bar: 'baz' } }
77
- expect(process(['/foo/~'], source)).to eq(target)
78
- end
79
-
80
- it 'does not include nested elements' do
81
- source = { foo: { bar: { baz: 'asd' } } }
82
- target = { foo: { bar: { baz: '*****' } } }
83
- expect(process(['/foo/~'], source)).to eq(target)
84
- end
85
- end
86
-
87
- context 'with whitelisted array elements field with wildcard' do
88
- let(:data) do
89
- {
90
- array: [
91
- { field: 'data1', secret: 'secret1' },
92
- { field: 'data2', secret: 'secret2' }
93
- ]
94
- }
95
- end
96
- let(:pointers) { ['/array/~/field'] }
97
-
98
- it 'includes array elements field' do
99
- expect(processed_data).to include(
100
- array: [
101
- { field: 'data1', secret: '*****' },
102
- { field: 'data2', secret: '*****' }
103
- ]
104
- )
105
- end
106
- end
107
-
108
- context 'with whitelisted string array elements with wildcard' do
109
- let(:data) do
110
- { array: %w[secret secret] }
111
- end
112
- let(:pointers) { ['/array/~'] }
113
-
114
- it 'includes array elements' do
115
- expect(processed_data).to include(array: %w[secret secret])
116
- end
117
- end
118
-
119
- context 'with whitelisted string array elements in an array with wildcard' do
120
- let(:data) do
121
- {
122
- nested: [{ array: %w[secret secret] }]
123
- }
124
- end
125
- let(:pointers) { ['/nested/~/array/~'] }
126
-
127
- it 'includes array elements' do
128
- expect(processed_data).to include(nested: [{ array: %w[secret secret] }])
129
- end
130
- end
131
-
132
-
133
- context 'with whitelisted array element' do
134
- let(:pointers) { ['/array/0'] }
135
-
136
- it 'masks array element' do
137
- expect(processed_data).to include(array: [{ field: '*****' }])
138
- end
139
- end
140
-
141
- context 'with whitelisted array' do
142
- let(:pointers) { ['/array'] }
143
-
144
- it 'masks array' do
145
- expect(processed_data).to include(array: ['*****'])
146
- end
147
- end
148
-
149
- context 'with whitelisted hash' do
150
- let(:pointers) { ['/data'] }
151
-
152
- it 'masks hash' do
153
- expect(processed_data).to include(data: { field: '*****' })
154
- end
155
- end
156
-
157
- context 'when boolean present' do
158
- let(:data) { { bool: true } }
159
-
160
- it 'masks it with asteriks' do
161
- expect(processed_data).to eq(bool: '*****')
162
- end
163
- end
164
-
165
- context 'when field has slash in the name' do
166
- let(:data) do
167
- { 'field_with_/' => 'secret' }
168
- end
169
- let(:pointers) { ['/field_with_~1'] }
170
-
171
- it 'includes field' do
172
- expect(processed_data).to include('field_with_/'=> 'secret')
173
- end
174
- end
175
-
176
- context 'when field has tilde in the name' do
177
- let(:data) do
178
- { 'field_with_~' => 'secret' }
179
- end
180
- let(:pointers) { ['/field_with_~0'] }
181
-
182
- it 'includes field' do
183
- expect(processed_data).to include('field_with_~'=> 'secret')
184
- end
185
- end
186
-
187
- context 'when field has tilde and 1' do
188
- let(:data) do
189
- { 'field_with_~1' => 'secret' }
190
- end
191
- let(:pointers) { ['/field_with_~01'] }
192
-
193
- it 'includes field' do
194
- expect(processed_data).to include('field_with_~1'=> 'secret')
195
- end
196
- end
197
-
198
- def process(pointers, data)
199
- described_class.new(pointers: pointers).process(data)
200
- end
201
- end
202
-
203
- RSpec.describe Lenjador::Preprocessors::Whitelist, 'when :action is :exclude or :prune' do
204
- subject(:processed_data) { described_class.new(config).process(data) }
205
-
206
- let(:config) { { pointers: pointers, action: :prune } }
207
- let(:pointers) { [] }
208
- let(:data) do
209
- {
210
- field: 'secret',
211
- data: {
212
- field: 'secret'
213
- },
214
- array: [{ field: 'secret' }, { field2: 'secret' }]
215
- }
216
- end
217
-
218
- context 'when pointers is empty' do
219
- it 'prunes all fields from the input' do
220
- expect(processed_data).to eq({})
221
- end
222
- end
223
-
224
- context 'with whitelisted field' do
225
- let(:pointers) { ['/field'] }
226
-
227
- it 'includes the field' do
228
- expect(processed_data).to eq(field: 'secret')
229
- end
230
- end
231
-
232
- context 'with whitelisted nested field' do
233
- let(:pointers) { ['/data/field'] }
234
-
235
- it 'includes nested field' do
236
- expect(processed_data).to eq(data: { field: 'secret' })
237
- end
238
- end
239
-
240
- context 'with whitelisted array element field' do
241
- let(:pointers) { ['/array/0/field'] }
242
-
243
- it 'includes array element' do
244
- expect(processed_data).to eq(array: [{ field: 'secret' }])
245
- end
246
- end
247
-
248
- context 'with whitelisted hash' do
249
- it 'includes all whitelisted hash elements' do
250
- source = { foo: { bar: 'baz' } }
251
- target = { foo: { bar: 'baz' } }
252
- expect(process(['/foo/~'], source)).to eq(target)
253
- end
254
-
255
- it 'does not include nested elements' do
256
- source = { foo: { bar: { baz: 'asd' } } }
257
- target = { foo: { bar: {} } }
258
- expect(process(['/foo/~'], source)).to eq(target)
259
- end
260
- end
261
-
262
- context 'with whitelisted array elements field with wildcard' do
263
- let(:data) do
264
- {
265
- array: [
266
- { field: 'data1', secret: 'secret1' },
267
- { field: 'data2', secret: 'secret2' }
268
- ]
269
- }
270
- end
271
- let(:pointers) { ['/array/~/field'] }
272
-
273
- it 'includes array elements field' do
274
- expect(processed_data).to include(
275
- array: [
276
- { field: 'data1' },
277
- { field: 'data2' }
278
- ]
279
- )
280
- end
281
- end
282
-
283
- context 'with whitelisted string array elements with wildcard' do
284
- let(:data) do
285
- { array: %w[secret1 secret2] }
286
- end
287
- let(:pointers) { ['/array/~'] }
288
-
289
- it 'includes array elements' do
290
- expect(processed_data).to include(array: %w[secret1 secret2])
291
- end
292
- end
293
-
294
- context 'with whitelisted string array elements in an array with wildcard' do
295
- let(:data) do
296
- {
297
- nested: [{ array: %w[secret1 secret2] }]
298
- }
299
- end
300
- let(:pointers) { ['/nested/~/array/~'] }
301
-
302
- it 'includes array elements' do
303
- expect(processed_data).to include(nested: [{ array: %w[secret1 secret2] }])
304
- end
305
- end
306
-
307
-
308
- context 'with whitelisted array element' do
309
- let(:pointers) { ['/array/0'] }
310
-
311
- it 'masks array element' do
312
- expect(processed_data).to eq(array: [{}])
313
- end
314
- end
315
-
316
- context 'with whitelisted array' do
317
- let(:pointers) { ['/array'] }
318
-
319
- it 'masks array' do
320
- expect(processed_data).to include(array: [])
321
- end
322
- end
323
-
324
- context 'with whitelisted hash' do
325
- let(:pointers) { ['/data'] }
326
-
327
- it 'masks hash' do
328
- expect(processed_data).to include(data: {})
329
- end
330
- end
331
-
332
- def process(pointers, data)
333
- described_class.new(pointers: pointers, action: :prune).process(data)
334
- end
335
- end