3 describe 'validate_augeas' do
4 if Puppet.features.augeas?
5 describe 'signature validation' do
6 it { is_expected.not_to eq(nil) }
7 it { is_expected.to run.with_params.and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i) }
8 it { is_expected.to run.with_params('').and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i) }
9 it { is_expected.to run.with_params('', '', [], '', 'extra').and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i) }
10 it { is_expected.to run.with_params('one', 'one', 'MSG to User', '4th arg').and_raise_error(NoMethodError) }
13 describe 'valid inputs' do
15 ["root:x:0:0:root:/root:/bin/bash\n", 'Passwd.lns'],
16 ["proc /proc proc nodev,noexec,nosuid 0 0\n", 'Fstab.lns'],
19 inputs.each do |input|
20 it { is_expected.to run.with_params(*input) }
24 describe 'valid inputs which fail augeas validation' do
25 # The intent here is to make sure valid inputs raise exceptions when they
26 # don't specify an error message to display. This is the behvior in
29 ["root:x:0:0:root\n", 'Passwd.lns'],
30 ["127.0.1.1\n", 'Hosts.lns'],
33 inputs.each do |input|
34 it { is_expected.to run.with_params(*input).and_raise_error(Puppet::ParseError, %r{validate_augeas.*?matched less than it should}) }
38 describe 'when specifying nice error messages' do
39 # The intent here is to make sure the function returns the 4th argument
40 # in the exception thrown
42 ["root:x:0:0:root\n", 'Passwd.lns', [], 'Failed to validate passwd content'],
43 ["127.0.1.1\n", 'Hosts.lns', [], 'Wrong hosts content'],
46 inputs.each do |input|
47 it { is_expected.to run.with_params(*input).and_raise_error(Puppet::ParseError, %r{#{input[3]}}) }
51 describe 'matching additional tests' do
53 ["root:x:0:0:root:/root:/bin/bash\n", 'Passwd.lns', ['$file/foobar']],
54 ["root:x:0:0:root:/root:/bin/bash\n", 'Passwd.lns', ['$file/root/shell[.="/bin/sh"]', 'foobar']],
57 inputs.each do |input|
58 it { is_expected.to run.with_params(*input) }
62 describe 'failing additional tests' do
64 ["foobar:x:0:0:root:/root:/bin/bash\n", 'Passwd.lns', ['$file/foobar']],
65 ["root:x:0:0:root:/root:/bin/sh\n", 'Passwd.lns', ['$file/root/shell[.="/bin/sh"]', 'foobar']],
68 inputs.each do |input|
69 it { is_expected.to run.with_params(*input).and_raise_error(Puppet::ParseError, %r{testing path}) }
73 skip 'ruby-augeas not installed'