Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Story/TP-57214]:Prevent reuse of Password reset token #9

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/hedgelog.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ 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, cleaner = nil)
@level = LEVELS[:debug]
@channel = nil
@logdev = nil
@app = nil
@scrubber = Hedgelog::Scrubber.new
@scrubber = Hedgelog::Scrubber.new(cleaner)
@normalizer = Hedgelog::Normalizer.new
@channel_context = Hedgelog::Context.new(@scrubber, @normalizer)

Expand Down
11 changes: 8 additions & 3 deletions lib/hedgelog/scrubber.rb
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,14 @@
class Hedgelog
class Scrubber
def initialize(replacements = nil)
@replacements = replacements || [
ScrubReplacement.new('password', '**********')
]
@replacements = [ScrubReplacement.new('password', '**********')]
replacements&.each do |x|
@replacements << if x.instance_of?(ScrubReplacement)
x
else
ScrubReplacement.new(x, '**********')
end
end
end

def scrub(data)
Expand Down
2 changes: 1 addition & 1 deletion lib/hedgelog/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

class Hedgelog
VERSION = '0.1.12'
VERSION = '0.2.1.alpha1'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For future reference standard naming would be to reset the lower significance number when publishing. Since this is a minor version bump, the patch version should be reset, i.e. 0.2.0.alpha.1

https://semver.org/#spec-item-7

Copy link
Author

@emborden emborden Jan 9, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it was meant to be 0.2.0.alpha1, but when I published I published as just 0.2.0 on accident. So I bumped to 0.2.1.alpha1. to show I was in beta testing, and because of so that minor changes I made to pass spec and rubocop

end
6 changes: 2 additions & 4 deletions spec/hedgelog/context_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -85,19 +85,17 @@
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

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
Expand Down
46 changes: 42 additions & 4 deletions spec/hedgelog_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 }
Expand All @@ -84,11 +86,47 @@
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')
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

Expand Down