Skip to content

Commit

Permalink
Merge pull request #19103 from agrare/add_vmdb_settings_filter_passwo…
Browse files Browse the repository at this point in the history
…rds_method

Add a method to filter password keys from settings

(cherry picked from commit 473f3be)
  • Loading branch information
Fryguy authored and simaishi committed Aug 23, 2019
1 parent 3d378cf commit c0e274c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
7 changes: 7 additions & 0 deletions lib/vmdb/settings_walker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,13 @@ def mask_passwords!(settings)
walk_passwords(settings) { |k, _v, h| h[k] = "********" }
end

# Filter out any password attributes from the settings
#
# @param settings (see .walk)
def filter_passwords!(settings)
walk_passwords(settings) { |k, _v, h| h.respond_to?(:delete_field) ? h.delete_field(k) : h.delete(k) }
end

# Walks the settings and decrypts passwords it finds
#
# @param settings (see .walk)
Expand Down
8 changes: 8 additions & 0 deletions spec/lib/vmdb/settings_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -516,6 +516,14 @@
include_examples "password handling"
end

describe ".filter_passwords!" do
it "removes the field from the settings" do
stub_settings(:password => "abcd")
filtered = described_class.filter_passwords!(Settings.to_h)
expect(filtered.keys).to_not include(:password)
end
end

describe ".for_resource" do
let(:server) { FactoryBot.create(:miq_server) }

Expand Down

0 comments on commit c0e274c

Please sign in to comment.