From aaf77cca7e9442cb07f2f0982ab745424d30e25a Mon Sep 17 00:00:00 2001 From: Ethan Borden Date: Mon, 6 Jan 2020 14:19:17 -0600 Subject: [PATCH 1/7] Added ability to filter logs based on app --- lib/hedgelog.rb | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/lib/hedgelog.rb b/lib/hedgelog.rb index e5d403b..312f56b 100755 --- a/lib/hedgelog.rb +++ b/lib/hedgelog.rb @@ -25,12 +25,19 @@ class Hedgelog attr_reader :level attr_writer :app - def initialize(logdev = STDOUT, shift_age = nil, shift_size = nil) + def initialize(logdev = STDOUT, shift_age = nil, shift_size = nil, scrubbers = nil) + unless scrubbers.nil? + scrubbers = scrubbers.map do |x| + return x if x instance_of?(Hedgelog::ScrubReplacement) + Hedgelog::ScrubReplacement.new(x, '**********') + end + scrubbers << Hedgelog::ScrubReplacement.new('password', '**********') + end @level = LEVELS[:debug] @channel = nil @logdev = nil @app = nil - @scrubber = Hedgelog::Scrubber.new + @scrubber = Hedgelog::Scrubber.new(scrubbers) @normalizer = Hedgelog::Normalizer.new @channel_context = Hedgelog::Context.new(@scrubber, @normalizer) From b02f71c6ad5a92198a34e5e8ca99f55a74d353b9 Mon Sep 17 00:00:00 2001 From: Ethan Borden Date: Mon, 6 Jan 2020 16:46:29 -0600 Subject: [PATCH 2/7] fixed frozen string error added rspec testing to confirm coverage --- lib/hedgelog.rb | 11 ++-------- lib/hedgelog/scrubber.rb | 13 ++++++++--- spec/hedgelog_spec.rb | 47 +++++++++++++++++++++++++++++++++++++--- 3 files changed, 56 insertions(+), 15 deletions(-) mode change 100644 => 100755 lib/hedgelog/scrubber.rb diff --git a/lib/hedgelog.rb b/lib/hedgelog.rb index 312f56b..69285e8 100755 --- a/lib/hedgelog.rb +++ b/lib/hedgelog.rb @@ -25,19 +25,12 @@ class Hedgelog attr_reader :level attr_writer :app - def initialize(logdev = STDOUT, shift_age = nil, shift_size = nil, scrubbers = nil) - unless scrubbers.nil? - scrubbers = scrubbers.map do |x| - return x if x instance_of?(Hedgelog::ScrubReplacement) - Hedgelog::ScrubReplacement.new(x, '**********') - end - scrubbers << Hedgelog::ScrubReplacement.new('password', '**********') - end + def initialize(logdev = STDOUT, shift_age = nil, shift_size = nil, cleaner=nil) @level = LEVELS[:debug] @channel = nil @logdev = nil @app = nil - @scrubber = Hedgelog::Scrubber.new(scrubbers) + @scrubber = Hedgelog::Scrubber.new(cleaner) @normalizer = Hedgelog::Normalizer.new @channel_context = Hedgelog::Context.new(@scrubber, @normalizer) diff --git a/lib/hedgelog/scrubber.rb b/lib/hedgelog/scrubber.rb old mode 100644 new mode 100755 index aa6730c..771b97e --- a/lib/hedgelog/scrubber.rb +++ b/lib/hedgelog/scrubber.rb @@ -3,9 +3,16 @@ class Hedgelog class Scrubber def initialize(replacements = nil) - @replacements = replacements || [ - ScrubReplacement.new('password', '**********') - ] + @replacements = [ScrubReplacement.new('password', '**********')] + unless replacements.nil? + replacements.each do |x| + if x.instance_of?(ScrubReplacement) + @replacements << x + else + @replacements << ScrubReplacement.new(x,'**********') + end + end + end end def scrub(data) diff --git a/spec/hedgelog_spec.rb b/spec/hedgelog_spec.rb index a33b8d3..841103b 100755 --- a/spec/hedgelog_spec.rb +++ b/spec/hedgelog_spec.rb @@ -60,7 +60,7 @@ describe '#add' do subject do - logger = Hedgelog.new(log_dev) + logger = Hedgelog.new(log_dev,nil,nil,scrubber) logger.level = log_level logger.add(severity, message, progname, data, &block) end @@ -69,6 +69,8 @@ let(:data) { {} } let(:block) { nil } let(:severity) { 1 } + let(:scrubber) {nil} + let(:wash) { '**********' } context 'when the severity is lower than the log level' do let(:log_level) { Logger::FATAL } @@ -84,11 +86,50 @@ end context 'when logging with a message and data' do - let(:data) { {bar: 'baz'} } - it 'writes the message in the json hash' do + let(:data) { {bar: 'baz', secret:'secret', password: 'do not see me'} } + + it 'writes the message in the json hash should not be able to see password' do + subject + expect(JSON.parse(log_results)).to include('message' => 'Foo') + expect(JSON.parse(log_results)['context']).to include('bar' => 'baz', 'secret' => 'secret', 'password' => wash) + end + + context 'When the scrubber is a string array' do + let(:scrubber) { ['secret'] } + + it 'writes the message and hash context while wiping secret info' do + subject + expect(JSON.parse(log_results)).to include('message' => 'Foo') + expect(JSON.parse(log_results)['context']).to include('bar' => 'baz','secret' => wash, 'password' => wash) + end + + end + '' + context 'When the scrubber is a ScrubReplacement array' do + + let(:scrubber) { [Hedgelog::ScrubReplacement.new('secret', wash)] } + + it 'writes message and hash context wipes secret and password' do subject expect(JSON.parse(log_results)).to include('message' => 'Foo') expect(JSON.parse(log_results)['context']).to include('bar' => 'baz') + expect(JSON.parse(log_results)['context']).to include('secret' => wash) + expect(JSON.parse(log_results)['context']).to include('password' => wash) + end + end + + context 'When the scrubber is a mixed array' do + let(:data) { {bar: 'baz', secret:'secret', password:'do not see me', mysterious:'hidden'} } + let(:scrubber) { [Hedgelog::ScrubReplacement.new('secret', wash), 'mysterious']} + + it 'writes message and hash context wipes secret, password, and mysterious' do + subject + expect(JSON.parse(log_results)).to include('message' => 'Foo') + expect(JSON.parse(log_results)['context']).to include('bar' => 'baz') + expect(JSON.parse(log_results)['context']).to include('secret' => wash) + expect(JSON.parse(log_results)['context']).to include('password' => wash) + expect(JSON.parse(log_results)['context']).to include('mysterious' => wash) + end end end From 3c9064450ba3fa5b92cdb4d5c0941cda403fb23c Mon Sep 17 00:00:00 2001 From: Ethan Borden Date: Wed, 8 Jan 2020 16:26:39 -0600 Subject: [PATCH 3/7] changing version number --- lib/hedgelog/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/hedgelog/version.rb b/lib/hedgelog/version.rb index 248545a..cb74392 100755 --- a/lib/hedgelog/version.rb +++ b/lib/hedgelog/version.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true class Hedgelog - VERSION = '0.1.12' + VERSION = '0.2.0' end From 8823576b3f3586bc92d66fa763c6dd4135f69140 Mon Sep 17 00:00:00 2001 From: Ethan Borden Date: Wed, 8 Jan 2020 16:48:54 -0600 Subject: [PATCH 4/7] style --- .idea/inspectionProfiles/Project_Default.xml | 6 +++++ .idea/misc.xml | 7 ++++++ .idea/modules.xml | 8 +++++++ .idea/vcs.xml | 6 +++++ lib/hedgelog.rb | 2 +- lib/hedgelog/scrubber.rb | 14 +++++------ spec/hedgelog/context_spec.rb | 6 ++--- spec/hedgelog_spec.rb | 25 +++++++++----------- spec/spec_helper.rb | 2 +- 9 files changed, 48 insertions(+), 28 deletions(-) create mode 100644 .idea/inspectionProfiles/Project_Default.xml create mode 100644 .idea/misc.xml create mode 100644 .idea/modules.xml create mode 100644 .idea/vcs.xml diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml new file mode 100644 index 0000000..b0db9b0 --- /dev/null +++ b/.idea/inspectionProfiles/Project_Default.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..8e2baaa --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,7 @@ + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..23afd25 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/lib/hedgelog.rb b/lib/hedgelog.rb index 69285e8..6a5074c 100755 --- a/lib/hedgelog.rb +++ b/lib/hedgelog.rb @@ -25,7 +25,7 @@ class Hedgelog attr_reader :level attr_writer :app - def initialize(logdev = STDOUT, shift_age = nil, shift_size = nil, cleaner=nil) + def initialize(logdev = STDOUT, shift_age = nil, shift_size = nil, cleaner = nil) @level = LEVELS[:debug] @channel = nil @logdev = nil diff --git a/lib/hedgelog/scrubber.rb b/lib/hedgelog/scrubber.rb index 771b97e..85b524b 100755 --- a/lib/hedgelog/scrubber.rb +++ b/lib/hedgelog/scrubber.rb @@ -4,14 +4,12 @@ class Hedgelog class Scrubber def initialize(replacements = nil) @replacements = [ScrubReplacement.new('password', '**********')] - unless replacements.nil? - replacements.each do |x| - if x.instance_of?(ScrubReplacement) - @replacements << x - else - @replacements << ScrubReplacement.new(x,'**********') - end - end + replacements&.each do |x| + @replacements << if x.instance_of?(ScrubReplacement) + x + else + ScrubReplacement.new(x, '**********') + end end end diff --git a/spec/hedgelog/context_spec.rb b/spec/hedgelog/context_spec.rb index f865090..e05c34c 100644 --- a/spec/hedgelog/context_spec.rb +++ b/spec/hedgelog/context_spec.rb @@ -85,9 +85,8 @@ context 'with valid keys in the hash' do it 'updates the context with the merged data' do expect(instance[:foo]).to eq 'bar' - # rubocop:disable Performance/RedundantMerge instance.merge!(baz: 'qux') - # rubocop:enable Performance/RedundantMerge + expect(instance.to_h).to include(foo: 'bar', baz: 'qux') end end @@ -95,9 +94,8 @@ context 'with existing, valid keys in the hash' do it 'updates the context with the merged data' do expect(instance[:foo]).to eq 'bar' - # rubocop:disable Performance/RedundantMerge instance.merge!(foo: 'qux') - # rubocop:enable Performance/RedundantMerge + expect(instance.to_h).to include(foo: 'bar') end end diff --git a/spec/hedgelog_spec.rb b/spec/hedgelog_spec.rb index 841103b..d00e6e4 100755 --- a/spec/hedgelog_spec.rb +++ b/spec/hedgelog_spec.rb @@ -60,7 +60,7 @@ describe '#add' do subject do - logger = Hedgelog.new(log_dev,nil,nil,scrubber) + logger = Hedgelog.new(log_dev, nil, nil, scrubber) logger.level = log_level logger.add(severity, message, progname, data, &block) end @@ -69,7 +69,7 @@ let(:data) { {} } let(:block) { nil } let(:severity) { 1 } - let(:scrubber) {nil} + let(:scrubber) { nil } let(:wash) { '**********' } context 'when the severity is lower than the log level' do @@ -86,7 +86,7 @@ end context 'when logging with a message and data' do - let(:data) { {bar: 'baz', secret:'secret', password: 'do not see me'} } + let(:data) { {bar: 'baz', secret: 'secret', password: 'do not see me'} } it 'writes the message in the json hash should not be able to see password' do subject @@ -100,27 +100,24 @@ it 'writes the message and hash context while wiping secret info' do subject expect(JSON.parse(log_results)).to include('message' => 'Foo') - expect(JSON.parse(log_results)['context']).to include('bar' => 'baz','secret' => wash, 'password' => wash) + expect(JSON.parse(log_results)['context']).to include('bar' => 'baz', 'secret' => wash, 'password' => wash) end - end - '' context 'When the scrubber is a ScrubReplacement array' do - let(:scrubber) { [Hedgelog::ScrubReplacement.new('secret', wash)] } it 'writes message and hash context wipes secret and password' do - subject - expect(JSON.parse(log_results)).to include('message' => 'Foo') - expect(JSON.parse(log_results)['context']).to include('bar' => 'baz') - expect(JSON.parse(log_results)['context']).to include('secret' => wash) - expect(JSON.parse(log_results)['context']).to include('password' => wash) + subject + expect(JSON.parse(log_results)).to include('message' => 'Foo') + expect(JSON.parse(log_results)['context']).to include('bar' => 'baz') + expect(JSON.parse(log_results)['context']).to include('secret' => wash) + expect(JSON.parse(log_results)['context']).to include('password' => wash) end end context 'When the scrubber is a mixed array' do - let(:data) { {bar: 'baz', secret:'secret', password:'do not see me', mysterious:'hidden'} } - let(:scrubber) { [Hedgelog::ScrubReplacement.new('secret', wash), 'mysterious']} + let(:data) { {bar: 'baz', secret: 'secret', password: 'do not see me', mysterious: 'hidden'} } + let(:scrubber) { [Hedgelog::ScrubReplacement.new('secret', wash), 'mysterious'] } it 'writes message and hash context wipes secret, password, and mysterious' do subject diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index de48741..99654fc 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -5,7 +5,7 @@ SimpleCov.minimum_coverage 99 -Dir[File.expand_path(File.join(File.dirname(__FILE__), 'support', '**', '*.rb'))].each { |f| require f } +Dir[File.expand_path(File.join(File.dirname(__FILE__), 'support', '**', '*.rb'))].sort.each { |f| require f } RSpec.configure do |config| config.include Matchers::Benchmark From 6728b1df0538728e5c626562ec9e49a868a2aec3 Mon Sep 17 00:00:00 2001 From: Ethan Borden Date: Wed, 8 Jan 2020 16:50:35 -0600 Subject: [PATCH 5/7] removed unintended files --- .idea/inspectionProfiles/Project_Default.xml | 6 ------ .idea/misc.xml | 7 ------- .idea/modules.xml | 8 -------- .idea/vcs.xml | 6 ------ 4 files changed, 27 deletions(-) delete mode 100644 .idea/inspectionProfiles/Project_Default.xml delete mode 100644 .idea/misc.xml delete mode 100644 .idea/modules.xml delete mode 100644 .idea/vcs.xml diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml deleted file mode 100644 index b0db9b0..0000000 --- a/.idea/inspectionProfiles/Project_Default.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml deleted file mode 100644 index 8e2baaa..0000000 --- a/.idea/misc.xml +++ /dev/null @@ -1,7 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml deleted file mode 100644 index 23afd25..0000000 --- a/.idea/modules.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml deleted file mode 100644 index 94a25f7..0000000 --- a/.idea/vcs.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file From d6bd36c602be59f0a141ea6bddedae12ae409262 Mon Sep 17 00:00:00 2001 From: Ethan Borden Date: Wed, 8 Jan 2020 16:53:45 -0600 Subject: [PATCH 6/7] version # change --- lib/hedgelog/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/hedgelog/version.rb b/lib/hedgelog/version.rb index cb74392..3a630f3 100755 --- a/lib/hedgelog/version.rb +++ b/lib/hedgelog/version.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true class Hedgelog - VERSION = '0.2.0' + VERSION = '0.2.1.alpha1' end From 06d6dd2d05eecdce7925018182af7a4c9742d942 Mon Sep 17 00:00:00 2001 From: Ethan Borden Date: Thu, 9 Jan 2020 14:43:17 -0600 Subject: [PATCH 7/7] reverted unintentional change --- spec/spec_helper.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 99654fc..de48741 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -5,7 +5,7 @@ SimpleCov.minimum_coverage 99 -Dir[File.expand_path(File.join(File.dirname(__FILE__), 'support', '**', '*.rb'))].sort.each { |f| require f } +Dir[File.expand_path(File.join(File.dirname(__FILE__), 'support', '**', '*.rb'))].each { |f| require f } RSpec.configure do |config| config.include Matchers::Benchmark