mirror of
https://github.com/inspec/inspec
synced 2024-11-10 07:04:15 +00:00
Fix for invocation when calling npm under sudo (#4548)
Fix for invocation when calling npm under sudo
This commit is contained in:
commit
1db2941a9e
2 changed files with 13 additions and 5 deletions
|
@ -27,12 +27,20 @@ module Inspec::Resources
|
|||
return @info if defined?(@info)
|
||||
|
||||
if @location
|
||||
npm = "cd #{Shellwords.escape @location} && npm"
|
||||
command_separator = inspec.os.platform?("windows") ? ";" : "&&"
|
||||
invocation = "cd #{Shellwords.escape @location} #{command_separator} npm"
|
||||
else
|
||||
npm = "npm -g"
|
||||
invocation = "npm -g"
|
||||
end
|
||||
|
||||
cmd = inspec.command("#{npm} ls --json #{@package_name}")
|
||||
invocation = "#{invocation} ls --json #{@package_name}"
|
||||
|
||||
# If on unix, wrap in sh -c to protect against sudo
|
||||
unless inspec.os.platform?("windows")
|
||||
invocation = "sh -c '#{invocation}'"
|
||||
end
|
||||
|
||||
cmd = inspec.command(invocation)
|
||||
@info = {
|
||||
name: @package_name,
|
||||
type: "npm",
|
||||
|
|
|
@ -228,8 +228,8 @@ class MockLoader
|
|||
"/opt/chef/embedded/bin/gem list --local -a -q ^chef-sugar$" => cmd.call("gem-list-local-a-q-chef-sugar"),
|
||||
'c:\opscode\chef\embedded\bin\gem.bat list --local -a -q ^json$' => cmd.call("gem-list-local-a-q-json"),
|
||||
"/opt/opscode/embedded/bin/gem list --local -a -q ^knife-backup$" => cmd.call("gem-list-local-a-q-knife-backup"),
|
||||
"npm -g ls --json bower" => cmd.call("npm-g-ls--json-bower"),
|
||||
"cd /path/to/project && npm ls --json bower" => cmd.call("npm-ls--json-bower"),
|
||||
"sh -c 'npm -g ls --json bower'" => cmd.call("npm-g-ls--json-bower"),
|
||||
"sh -c 'cd /path/to/project && npm ls --json bower'" => cmd.call("npm-ls--json-bower"),
|
||||
"Rscript -e 'packageVersion(\"DBI\")'" => cmd.call("r-print-version"),
|
||||
"Rscript -e 'packageVersion(\"DoesNotExist\")'" => cmd.call("r-print-version-not-installed"),
|
||||
"perl -le 'eval \"require $ARGV[0]\" and print $ARGV[0]->VERSION or exit 1' DBD::Pg" => cmd.call("perl-print-version"),
|
||||
|
|
Loading…
Reference in a new issue