3 describe 'validate_ip_address' do
4 describe 'signature validation' do
5 it { is_expected.not_to eq(nil) }
6 it { is_expected.to run.with_params.and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i) }
9 describe 'valid inputs' do
10 it { is_expected.to run.with_params('0.0.0.0') }
11 it { is_expected.to run.with_params('8.8.8.8') }
12 it { is_expected.to run.with_params('127.0.0.1') }
13 it { is_expected.to run.with_params('10.10.10.10') }
14 it { is_expected.to run.with_params('194.232.104.150') }
15 it { is_expected.to run.with_params('244.24.24.24') }
16 it { is_expected.to run.with_params('255.255.255.255') }
17 it { is_expected.to run.with_params('1.2.3.4', '5.6.7.8') }
18 it { is_expected.to run.with_params('3ffe:0505:0002::') }
19 it { is_expected.to run.with_params('3ffe:0505:0002::', '3ffe:0505:0002::2') }
20 it { is_expected.to run.with_params('::1/64') }
21 it { is_expected.to run.with_params('fe80::a00:27ff:fe94:44d6/64') }
23 context 'Checking for deprecation warning', :if => Puppet.version.to_f < 4.0 do
25 ENV.delete('STDLIB_LOG_DEPRECATIONS')
27 # Checking for deprecation warning, which should only be provoked when the env variable for it is set.
28 it 'displays a single deprecation' do
29 ENV['STDLIB_LOG_DEPRECATIONS'] = 'true'
30 expect(scope).to receive(:warning).with(include('This method is deprecated'))
31 is_expected.to run.with_params('1.2.3.4')
33 it 'displays no warning for deprecation' do
34 ENV['STDLIB_LOG_DEPRECATIONS'] = 'false'
35 expect(scope).to receive(:warning).with(include('This method is deprecated')).never
36 is_expected.to run.with_params('1.2.3.4')
40 context 'with netmasks' do
41 it { is_expected.to run.with_params('8.8.8.8/0') }
42 it { is_expected.to run.with_params('8.8.8.8/16') }
43 it { is_expected.to run.with_params('8.8.8.8/32') }
44 it { is_expected.to run.with_params('8.8.8.8/255.255.0.0') }
48 describe 'invalid inputs' do
49 it { is_expected.to run.with_params({}).and_raise_error(Puppet::ParseError, %r{is not a string}) }
50 it { is_expected.to run.with_params(1).and_raise_error(Puppet::ParseError, %r{is not a string}) }
51 it { is_expected.to run.with_params(true).and_raise_error(Puppet::ParseError, %r{is not a string}) }
52 it { is_expected.to run.with_params('one').and_raise_error(Puppet::ParseError, %r{is not a valid IP}) }
53 it { is_expected.to run.with_params('0.0.0').and_raise_error(Puppet::ParseError, %r{is not a valid IP}) }
54 it { is_expected.to run.with_params('0.0.0.256').and_raise_error(Puppet::ParseError, %r{is not a valid IP}) }
55 it { is_expected.to run.with_params('0.0.0.0.0').and_raise_error(Puppet::ParseError, %r{is not a valid IP}) }
56 it { is_expected.to run.with_params('1.2.3.4', {}).and_raise_error(Puppet::ParseError, %r{is not a string}) }
57 it { is_expected.to run.with_params('1.2.3.4', 1).and_raise_error(Puppet::ParseError, %r{is not a string}) }
58 it { is_expected.to run.with_params('1.2.3.4', true).and_raise_error(Puppet::ParseError, %r{is not a string}) }
59 it { is_expected.to run.with_params('1.2.3.4', 'one').and_raise_error(Puppet::ParseError, %r{is not a valid IP}) }
60 it { is_expected.to run.with_params('::1', {}).and_raise_error(Puppet::ParseError, %r{is not a string}) }
61 it { is_expected.to run.with_params('::1', true).and_raise_error(Puppet::ParseError, %r{is not a string}) }
62 it { is_expected.to run.with_params('::1', 'one').and_raise_error(Puppet::ParseError, %r{is not a valid IP}) }