Skip to content

Commit

Permalink
coerce paths to be safer for docker::run
Browse files Browse the repository at this point in the history
  • Loading branch information
garethr committed Jun 25, 2014
1 parent 13dc200 commit 4d1454a
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 7 deletions.
14 changes: 8 additions & 6 deletions manifests/run.pp
Original file line number Diff line number Diff line change
Expand Up @@ -45,26 +45,28 @@
$links_array = any2array($links)
$lxc_conf_array = any2array($lxc_conf)

$sanitised_title = regsubst($title, '[^0-9A-Za-z.\-]', '-')

$provider = $::operatingsystem ? {
'Ubuntu' => 'upstart',
default => undef,
}

$notify = str2bool($restart_service) ? {
true => Service["docker-${title}"],
true => Service["docker-${sanitised_title}"],
default => undef,
}

case $::osfamily {
'Debian': {
$initscript = "/etc/init/docker-${title}.conf"
$initscript = "/etc/init/docker-${sanitised_title}.conf"
$init_template = 'docker/etc/init/docker-run.conf.erb'
$hasstatus = true
$hasrestart = false
$mode = '0644'
}
'RedHat': {
$initscript = "/etc/init.d/docker-${title}"
$initscript = "/etc/init.d/docker-${sanitised_title}"
$init_template = 'docker/etc/init.d/docker-run.erb'
$hasstatus = undef
$hasrestart = undef
Expand All @@ -82,7 +84,7 @@
notify => $notify,
}

service { "docker-${title}":
service { "docker-${sanitised_title}":
ensure => $running,
enable => true,
hasstatus => $hasstatus,
Expand All @@ -92,10 +94,10 @@
}

if str2bool($restart_service) {
File[$initscript] ~> Service["docker-${title}"]
File[$initscript] ~> Service["docker-${sanitised_title}"]
}
else {
File[$initscript] -> Service["docker-${title}"]
File[$initscript] -> Service["docker-${sanitised_title}"]
}
}

16 changes: 15 additions & 1 deletion spec/defines/run_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@
let(:params) { {'command' => 'command', 'image' => 'base', 'dns' => '8.8.8.8'} }
it { should contain_file(initscript).with_content(/--dns 8.8.8.8/) }
end

context 'when disabling network' do
let(:params) { {'command' => 'command', 'image' => 'base', 'disable_network' => true} }
it { should contain_file(initscript).with_content(/-n false/) }
Expand Down Expand Up @@ -133,6 +133,20 @@
it { should contain_file(initscript).with_content(/--net host/) }
end

context 'with an title that will not format into a path' do
let(:title) { 'this/that' }
let(:params) { {'image' => 'base'} }

if osfamily == 'Debian'
new_initscript = '/etc/init/docker-this-that.conf'
else
new_initscript = '/etc/init.d/docker-this-that'
end

it { should contain_service('docker-this-that') }
it { should contain_file(new_initscript) }
end

context 'with an invalid title' do
let(:title) { 'with spaces' }
it do
Expand Down

0 comments on commit 4d1454a

Please sign in to comment.