Skip to content

Commit

Permalink
Merge pull request #40 from ekohl/escape-puppet-command-options
Browse files Browse the repository at this point in the history
shell escape Puppet command options
  • Loading branch information
bastelfreak authored Jan 8, 2024
2 parents 007c8d0 + 43426d8 commit 9b9d6ce
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
5 changes: 3 additions & 2 deletions lib/beaker_puppet_helpers/module_utils.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# frozen_string_literal: true

require 'shellwords'
require 'beaker/command'
require 'puppet/modulebuilder'

Expand All @@ -21,8 +22,8 @@ def install_puppet_module_via_pmt_on(hosts, module_name, version = nil, module_r
block_on hosts do |host|
puppet_opts = {}
puppet_opts.merge!(host[:default_module_install_opts]) if host[:default_module_install_opts]
puppet_opts[:version] = version if version
puppet_opts[:module_repository] = module_repository if module_repository
puppet_opts[:version] = Shellwords.escape(version) if version
puppet_opts[:module_repository] = Shellwords.escape(module_repository) if module_repository

on host, Beaker::PuppetCommand.new('module', ['install', module_name], puppet_opts)
end
Expand Down
7 changes: 7 additions & 0 deletions spec/beaker_puppet_helpers/module_utils_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,13 @@ def logger
dsl.install_puppet_module_via_pmt_on(host, 'test', '1.2.3')
end

it 'escapes the version parameter' do
expect(Beaker::PuppetCommand).to receive(:new).with('module', %w[install test], { version: '\\>\\=\\ 4.0\\ \\<\\ 6.0' }).once
expect(dsl).to receive(:on).with(host, anything).once

dsl.install_puppet_module_via_pmt_on(host, 'test', '>= 4.0 < 6.0')
end

it 'accepts the module_repository parameter' do
expect(Beaker::PuppetCommand).to receive(:new).with('module', %w[install test], { module_repository: 'http://forge.example.com' }).once
expect(dsl).to receive(:on).with(host, anything).once
Expand Down

0 comments on commit 9b9d6ce

Please sign in to comment.