Skip to content

(FACT-3133) allow echo for Windows custom facts #2517

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

Merged
merged 1 commit into from
Sep 2, 2022
Merged
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: 4 additions & 0 deletions lib/facter/custom_facts/core/execution/windows.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ def search_paths
DEFAULT_COMMAND_EXTENSIONS = %w[.COM .EXE .BAT .CMD].freeze

def which(bin)
# `echo` is allowed for facter 3.x compatibility, otherwise
# all commands much be found on the PATH or absolute.
return bin if /^echo$/i =~ bin

if absolute_path?(bin)
return bin if File.executable?(bin)
else
Expand Down
10 changes: 10 additions & 0 deletions spec/custom_facts/core/execution/windows_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,16 @@
allow(ENV).to receive(:[]).with('PATHEXT').and_return nil
end

context 'when trying to use builtin windows commands' do
it 'allows echo' do
expect(executor.which('echo')).to eq 'echo'
end

it 'disallows other builtin windows commands' do
expect(executor.which('dir')).to eq nil
end
end

context 'when it is provided with an absolute path' do
it 'returns the path to binary if executable' do
allow(File).to receive(:executable?).with('C:\Tools\foo.exe').and_return true
Expand Down