Skip to content

Commit

Permalink
Add validation for order parameter
Browse files Browse the repository at this point in the history
Per discussion on #272, we're going to validate $order rather than worry
about needing to make substitutions on it.
  • Loading branch information
Morgan Haskel committed Feb 25, 2015
1 parent 2d60bcb commit 2ca56da
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
2 changes: 2 additions & 0 deletions manifests/fragment.pp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@
}
if !(is_string($order) or is_integer($order)) {
fail('$order is not a string or integer.')
} elsif $order =~ /[:\n\/]/ {
fail("Order cannot contain '/', ':', or '\n'.")
}
if $mode {
warning('The $mode parameter to concat::fragment is deprecated and has no effect')
Expand Down
28 changes: 28 additions & 0 deletions spec/unit/defines/concat_fragment_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,34 @@
expect { should }.to raise_error(Puppet::Error, /is not a string or integer/)
end
end

context '123:456' do
let(:title) { 'motd_header' }
let(:facts) {{ :concat_basedir => '/tmp', :is_pe => false }}
let(:params) {{ :order => '123:456', :target => '/etc/motd' }}

it 'should fail' do
expect { should }.to raise_error(Puppet::Error, /cannot contain/)
end
end
context '123/456' do
let(:title) { 'motd_header' }
let(:facts) {{ :concat_basedir => '/tmp', :is_pe => false }}
let(:params) {{ :order => '123/456', :target => '/etc/motd' }}

it 'should fail' do
expect { should }.to raise_error(Puppet::Error, /cannot contain/)
end
end
context '123\n456' do
let(:title) { 'motd_header' }
let(:facts) {{ :concat_basedir => '/tmp', :is_pe => false }}
let(:params) {{ :order => "123\n456", :target => '/etc/motd' }}

it 'should fail' do
expect { should }.to raise_error(Puppet::Error, /cannot contain/)
end
end
end # order =>

context 'more than one content source' do
Expand Down

0 comments on commit 2ca56da

Please sign in to comment.