From 995b79dfc83676de74a18d87999b5ce4393a4752 Mon Sep 17 00:00:00 2001 From: Tim Meusel Date: Wed, 7 Aug 2024 16:21:38 +0200 Subject: [PATCH] (#9440) exec resource: set path param to path fact --- lib/puppet/type/exec.rb | 4 +++- spec/integration/application/agent_spec.rb | 25 ---------------------- spec/unit/provider/exec_spec.rb | 14 ------------ spec/unit/type/exec_spec.rb | 2 ++ 4 files changed, 5 insertions(+), 40 deletions(-) diff --git a/lib/puppet/type/exec.rb b/lib/puppet/type/exec.rb index fb47b133848..1cd8779362a 100644 --- a/lib/puppet/type/exec.rb +++ b/lib/puppet/type/exec.rb @@ -223,7 +223,9 @@ def sync newparam(:path) do desc "The search path used for command execution. Commands must be fully qualified if no path is specified. Paths - can be specified as an array or as a '#{File::PATH_SEPARATOR}' separated list." + can be specified as an array or as a '#{File::PATH_SEPARATOR}' separated list. Defaults to the `path` fact." + + defaultto Puppet.runtime[:facter].value('path') # Support both arrays and colon-separated fields. def value=(*values) diff --git a/spec/integration/application/agent_spec.rb b/spec/integration/application/agent_spec.rb index 5b033665289..c4179cc132b 100644 --- a/spec/integration/application/agent_spec.rb +++ b/spec/integration/application/agent_spec.rb @@ -649,31 +649,6 @@ def with_another_agent_running(&block) )).to_stdout .and output(/No more routes to fileserver/).to_stderr end - - it 'preserves the old cached catalog if validation fails with the old one' do - catalog_handler = -> (req, res) { - catalog = compile_to_catalog(<<-MANIFEST, node) - exec { 'unqualified_command': } - MANIFEST - - res.body = formatter.render(catalog) - res['Content-Type'] = formatter.mime - } - - server.start_server(mounts: {catalog: catalog_handler}) do |port| - Puppet[:serverport] = port - expect { - agent.command_line.args << '--test' - agent.run - }.to exit_with(1) - .and output(%r{Retrieving plugin}).to_stdout - .and output(%r{Validation of Exec\[unqualified_command\] failed: 'unqualified_command' is not qualified and no path was specified}).to_stderr - end - - # cached catalog should not be updated - cached_catalog = "#{File.join(Puppet[:client_datadir], 'catalog', Puppet[:certname])}.json" - expect(File).to_not be_exist(cached_catalog) - end end context "reporting" do diff --git a/spec/unit/provider/exec_spec.rb b/spec/unit/provider/exec_spec.rb index 3c9a676f6bf..8e3ada32985 100644 --- a/spec/unit/provider/exec_spec.rb +++ b/spec/unit/provider/exec_spec.rb @@ -73,20 +73,6 @@ def echo_from_ruby_exit_1(message) end context "when validating the command" do - it "redacts the arguments if the command is relative" do - expect { - apply_compiled_manifest(<<-MANIFEST) - exec { 'echo': - command => Sensitive.new('echo #{supersecret}') - } - MANIFEST - }.to raise_error do |err| - expect(err).to be_a(Puppet::Error) - expect(err.message).to match(/'echo' is not qualified and no path was specified. Please qualify the command or specify a path./) - expect(err.message).to_not match(/#{supersecret}/) - end - end - it "redacts the arguments if the command is a directory" do dir = tmpdir('exec') apply_compiled_manifest(<<-MANIFEST) diff --git a/spec/unit/type/exec_spec.rb b/spec/unit/type/exec_spec.rb index ebc6f48038a..48e33000b7f 100644 --- a/spec/unit/type/exec_spec.rb +++ b/spec/unit/type/exec_spec.rb @@ -910,6 +910,8 @@ def instance(path) let :abs do make_absolute('/bin/echo') end let :path do make_absolute('/bin') end + allow(Facter).to receive(:value).with('path').and_return('/usr/bin:/bin') + it "should fail with relative command and no path" do expect { type.new(:command => rel) }. to raise_error Puppet::Error, /no path was specified/