Scrub credentials as whole words, don't capture matching substrings
This commit is contained in:
parent
2063111ab5
commit
27b37ea838
@ -32,7 +32,7 @@ module Vagrant
|
||||
def self.desensitize(string)
|
||||
string = string.to_s.dup
|
||||
sensitive_strings.each do |remove|
|
||||
string.gsub!(remove, REPLACEMENT_TEXT)
|
||||
string.gsub!(/(\W|^)#{remove}(\W|$)/, " #{REPLACEMENT_TEXT} ")
|
||||
end
|
||||
string
|
||||
end
|
||||
|
||||
@ -94,5 +94,18 @@ describe Vagrant::Util::CredentialScrubber do
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "with sensitive words that are part of non-sensitive words" do
|
||||
let(:to_scrub){ ["a"] }
|
||||
|
||||
it "should not remove parts of words" do
|
||||
result = subject.desensitize(string)
|
||||
to_scrub.each do |registered_value|
|
||||
expect(result).not_to match(/(\W|^)#{registered_value}(\W|$)/)
|
||||
end
|
||||
expect(result).to include("my-birthday")
|
||||
expect(result).to include("my-cats-birthday")
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user