3 describe 'validate_augeas' do
4 unless Puppet.features.augeas?
5 skip "ruby-augeas not installed"
7 describe 'signature validation' do
8 it { is_expected.not_to eq(nil) }
9 it { is_expected.to run.with_params().and_raise_error(Puppet::ParseError, /wrong number of arguments/i) }
10 it { is_expected.to run.with_params('').and_raise_error(Puppet::ParseError, /wrong number of arguments/i) }
11 it { is_expected.to run.with_params('', '', [], '', 'extra').and_raise_error(Puppet::ParseError, /wrong number of arguments/i) }
12 it { is_expected.to run.with_params('one', 'one', 'MSG to User', '4th arg').and_raise_error(NoMethodError) }
15 describe 'valid inputs' do
17 [ "root:x:0:0:root:/root:/bin/bash\n", 'Passwd.lns' ],
18 [ "proc /proc proc nodev,noexec,nosuid 0 0\n", 'Fstab.lns'],
21 inputs.each do |input|
22 it { is_expected.to run.with_params(*input) }
26 describe 'valid inputs which fail augeas validation' do
27 # The intent here is to make sure valid inputs raise exceptions when they
28 # don't specify an error message to display. This is the behvior in
31 [ "root:x:0:0:root\n", 'Passwd.lns' ],
32 [ "127.0.1.1\n", 'Hosts.lns' ],
35 inputs.each do |input|
36 it { is_expected.to run.with_params(*input).and_raise_error(Puppet::ParseError, /validate_augeas.*?matched less than it should/) }
40 describe "when specifying nice error messages" do
41 # The intent here is to make sure the function returns the 4th argument
42 # in the exception thrown
44 [ "root:x:0:0:root\n", 'Passwd.lns', [], 'Failed to validate passwd content' ],
45 [ "127.0.1.1\n", 'Hosts.lns', [], 'Wrong hosts content' ],
48 inputs.each do |input|
49 it { is_expected.to run.with_params(*input).and_raise_error(Puppet::ParseError, /#{input[3]}/) }
53 describe "matching additional tests" do
55 [ "root:x:0:0:root:/root:/bin/bash\n", 'Passwd.lns', ['$file/foobar']],
56 [ "root:x:0:0:root:/root:/bin/bash\n", 'Passwd.lns', ['$file/root/shell[.="/bin/sh"]', 'foobar']],
59 inputs.each do |input|
60 it { is_expected.to run.with_params(*input) }
64 describe "failing additional tests" do
66 [ "foobar:x:0:0:root:/root:/bin/bash\n", 'Passwd.lns', ['$file/foobar']],
67 [ "root:x:0:0:root:/root:/bin/sh\n", 'Passwd.lns', ['$file/root/shell[.="/bin/sh"]', 'foobar']],
70 inputs.each do |input|
71 it { is_expected.to run.with_params(*input).and_raise_error(Puppet::ParseError, /testing path/) }