Skip to content
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

Fix detection of insecure interpolations in unless parameter #47

Merged
merged 4 commits into from
Apr 26, 2024
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
2 changes: 1 addition & 1 deletion lib/puppet-lint/plugins/check_unsafe_interpolations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def check_unsafe_title(title)
def check_unsafe_interpolations(command_resources)
command_resources[:tokens].each do |token|
# Skip iteration if token isn't a command of type :NAME
next unless COMMANDS.include?(token.value) && token.type == :NAME
next unless COMMANDS.include?(token.value) && (token.type == :NAME || token.type == :UNLESS)
# Don't check the command if it is parameterised
next if parameterised?(token)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,19 +33,23 @@ class foo {

exec { 'bar':
command => "echo ${foo} ${bar}",
onlyif => "${baz}",
unless => "${bazz}",
}

}
PUPPET
end

it 'detects multiple unsafe exec command arguments' do
expect(problems).to have(2).problems
expect(problems).to have(4).problems
end

it 'creates two warnings' do
expect(problems).to contain_warning(msg)
expect(problems).to contain_warning(msg)
expect(problems).to contain_warning("unsafe interpolation of variable 'bar' in exec command")
expect(problems).to contain_warning("unsafe interpolation of variable 'baz' in exec command")
expect(problems).to contain_warning("unsafe interpolation of variable 'bazz' in exec command")
end
end

Expand Down
1 change: 1 addition & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
require 'puppet-lint'
require 'rspec/collection_matchers'

PuppetLint::Plugins.load_spec_helper