2012-12-06 11:33:43 +01:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2015-06-01 13:21:59 +02:00
|
|
|
describe 'validate_augeas' do
|
|
|
|
unless Puppet.features.augeas?
|
|
|
|
skip "ruby-augeas not installed"
|
|
|
|
else
|
|
|
|
describe 'signature validation' do
|
|
|
|
it { is_expected.not_to eq(nil) }
|
|
|
|
it { is_expected.to run.with_params().and_raise_error(Puppet::ParseError, /wrong number of arguments/i) }
|
|
|
|
it { is_expected.to run.with_params('').and_raise_error(Puppet::ParseError, /wrong number of arguments/i) }
|
|
|
|
it { is_expected.to run.with_params('', '', [], '', 'extra').and_raise_error(Puppet::ParseError, /wrong number of arguments/i) }
|
|
|
|
it { is_expected.to run.with_params('one', 'one', 'MSG to User', '4th arg').and_raise_error(NoMethodError) }
|
2012-12-06 11:33:43 +01:00
|
|
|
end
|
|
|
|
|
2015-06-01 13:21:59 +02:00
|
|
|
describe 'valid inputs' do
|
2012-12-06 11:33:43 +01:00
|
|
|
inputs = [
|
|
|
|
[ "root:x:0:0:root:/root:/bin/bash\n", 'Passwd.lns' ],
|
|
|
|
[ "proc /proc proc nodev,noexec,nosuid 0 0\n", 'Fstab.lns'],
|
|
|
|
]
|
|
|
|
|
|
|
|
inputs.each do |input|
|
2015-06-01 13:21:59 +02:00
|
|
|
it { is_expected.to run.with_params(*input) }
|
2012-12-06 11:33:43 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-06-01 13:21:59 +02:00
|
|
|
describe 'valid inputs which fail augeas validation' do
|
2012-12-06 11:33:43 +01:00
|
|
|
# The intent here is to make sure valid inputs raise exceptions when they
|
|
|
|
# don't specify an error message to display. This is the behvior in
|
|
|
|
# 2.2.x and prior.
|
|
|
|
inputs = [
|
|
|
|
[ "root:x:0:0:root\n", 'Passwd.lns' ],
|
|
|
|
[ "127.0.1.1\n", 'Hosts.lns' ],
|
|
|
|
]
|
|
|
|
|
|
|
|
inputs.each do |input|
|
2015-06-01 13:21:59 +02:00
|
|
|
it { is_expected.to run.with_params(*input).and_raise_error(Puppet::ParseError, /validate_augeas.*?matched less than it should/) }
|
2012-12-06 11:33:43 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-06-01 13:21:59 +02:00
|
|
|
describe "when specifying nice error messages" do
|
2015-03-10 23:43:51 +01:00
|
|
|
# The intent here is to make sure the function returns the 4th argument
|
2012-12-06 11:33:43 +01:00
|
|
|
# in the exception thrown
|
|
|
|
inputs = [
|
|
|
|
[ "root:x:0:0:root\n", 'Passwd.lns', [], 'Failed to validate passwd content' ],
|
|
|
|
[ "127.0.1.1\n", 'Hosts.lns', [], 'Wrong hosts content' ],
|
|
|
|
]
|
|
|
|
|
|
|
|
inputs.each do |input|
|
2015-06-01 13:21:59 +02:00
|
|
|
it { is_expected.to run.with_params(*input).and_raise_error(Puppet::ParseError, /#{input[3]}/) }
|
2012-12-06 11:33:43 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-06-01 13:21:59 +02:00
|
|
|
describe "matching additional tests" do
|
2012-12-06 11:33:43 +01:00
|
|
|
inputs = [
|
|
|
|
[ "root:x:0:0:root:/root:/bin/bash\n", 'Passwd.lns', ['$file/foobar']],
|
|
|
|
[ "root:x:0:0:root:/root:/bin/bash\n", 'Passwd.lns', ['$file/root/shell[.="/bin/sh"]', 'foobar']],
|
|
|
|
]
|
|
|
|
|
|
|
|
inputs.each do |input|
|
2015-06-01 13:21:59 +02:00
|
|
|
it { is_expected.to run.with_params(*input) }
|
2012-12-06 11:33:43 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-06-01 13:21:59 +02:00
|
|
|
describe "failing additional tests" do
|
2012-12-06 11:33:43 +01:00
|
|
|
inputs = [
|
|
|
|
[ "foobar:x:0:0:root:/root:/bin/bash\n", 'Passwd.lns', ['$file/foobar']],
|
|
|
|
[ "root:x:0:0:root:/root:/bin/sh\n", 'Passwd.lns', ['$file/root/shell[.="/bin/sh"]', 'foobar']],
|
|
|
|
]
|
|
|
|
|
|
|
|
inputs.each do |input|
|
2015-06-01 13:21:59 +02:00
|
|
|
it { is_expected.to run.with_params(*input).and_raise_error(Puppet::ParseError, /testing path/) }
|
2012-12-06 11:33:43 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|