(#14467) Warn when removing relative paths
Due to changes made to Facter in commit
634f2f6a57b461926afcb2e07dcfe4ed659f5b0c, Facter no longer looks
for facts in relative directories for security reasons. This
change could result in users not getting all of their facts. This
commit alerts users if a relative directory has been excluded from
the search path.
Due to feedback on this pull request on IRC, change message to be
debug instead of warn.
Hailee Kenney authored 12 years ago
Jeff Weiss committed 12 years ago
60 | 60 |
# This allows others to register additional paths we should search.
|
61 | 61 |
result += Facter.search_path
|
62 | 62 |
|
63 | |
result.select { |dir| valid_search_path? dir }
|
|
63 |
result.select do |dir|
|
|
64 |
good = valid_search_path? dir
|
|
65 |
Facter.debugonce("Relative directory #{dir} removed from search path.") unless good
|
|
66 |
good
|
|
67 |
end
|
64 | 68 |
end
|
65 | 69 |
|
66 | 70 |
def valid_search_path?(path)
|
43 | 43 |
@@debug = 0
|
44 | 44 |
@@timing = 0
|
45 | 45 |
@@messages = {}
|
|
46 |
@@debug_messages = {}
|
46 | 47 |
|
47 | 48 |
# module methods
|
48 | 49 |
|
|
67 | 68 |
puts GREEN + string + RESET
|
68 | 69 |
end
|
69 | 70 |
end
|
|
71 |
|
|
72 |
# Debug once.
|
|
73 |
def self.debugonce(msg)
|
|
74 |
if msg and not msg.empty? and @@debug_messages[msg].nil?
|
|
75 |
@@debug_messages[msg] = true
|
|
76 |
debug(msg)
|
|
77 |
end
|
|
78 |
end
|
70 | 79 |
|
71 | 80 |
def self.debugging?
|
72 | 81 |
@@debug != 0
|
109 | 109 |
paths.should be_include(dir)
|
110 | 110 |
end
|
111 | 111 |
end
|
112 | |
|
|
112 |
|
|
113 |
it "should warn the user when an invalid search path has been excluded" do
|
|
114 |
dirs = $LOAD_PATH.collect { |d| File.join(d, "facter") }
|
|
115 |
@loader.stubs(:valid_search_path?).returns(false)
|
|
116 |
dirs.each do |dir|
|
|
117 |
Facter.expects(:debugonce).with("Relative directory #{dir} removed from search path.").once
|
|
118 |
end
|
|
119 |
paths = @loader.search_path
|
|
120 |
end
|
|
121 |
|
|
122 |
|
113 | 123 |
it "should exclude invalid search paths" do
|
114 | 124 |
dirs = $LOAD_PATH.collect { |d| File.join(d, "facter") }
|
115 | 125 |
@loader.stubs(:valid_search_path?).returns(false)
|