Skip to content

Commit

Permalink
Merge pull request #120 from chef/BP-219/hide-ssh-password-in-logs
Browse files Browse the repository at this point in the history
do not log password in ssh connection output
  • Loading branch information
srenatus authored Jun 28, 2016
2 parents 34e46b5 + 25b4589 commit 2fc29b3
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/train/transports/ssh_connection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,9 @@ def session(retry_options = {})
#
# @api private
def to_s
"#{@username}@#{@hostname}<#{@options.inspect}>"
options_to_print = @options.clone
options_to_print[:password] = '<hidden>' if options_to_print.key?(:password)
"#{@username}@#{@hostname}<#{options_to_print.inspect}>"
end

class OS < OSCommon
Expand Down
9 changes: 9 additions & 0 deletions test/unit/transports/ssh_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,15 @@ def detect_family
end
end

describe 'converting connection to string for logging' do
it "masks passwords" do
assert_output(/.*:password=>"<hidden>".*/) do
connection = cls.new(conf).connection
puts "#{connection}"
end
end
end

describe 'failed configuration' do
it 'works with a minimum valid config' do
cls.new(conf).connection
Expand Down

0 comments on commit 2fc29b3

Please sign in to comment.