3 describe 'validate_ip_address' do
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, /wrong number of arguments/i) }
10 describe 'valid inputs' do
11 it { is_expected.to run.with_params('0.0.0.0') }
12 it { is_expected.to run.with_params('8.8.8.8') }
13 it { is_expected.to run.with_params('127.0.0.1') }
14 it { is_expected.to run.with_params('10.10.10.10') }
15 it { is_expected.to run.with_params('194.232.104.150') }
16 it { is_expected.to run.with_params('244.24.24.24') }
17 it { is_expected.to run.with_params('255.255.255.255') }
18 it { is_expected.to run.with_params('1.2.3.4', '5.6.7.8') }
19 it { is_expected.to run.with_params('3ffe:0505:0002::') }
20 it { is_expected.to run.with_params('3ffe:0505:0002::', '3ffe:0505:0002::2') }
21 it { is_expected.to run.with_params('::1/64') }
22 it { is_expected.to run.with_params('fe80::a00:27ff:fe94:44d6/64') }
24 context 'Checking for deprecation warning', if: Puppet.version.to_f < 4.0 do
26 ENV.delete('STDLIB_LOG_DEPRECATIONS')
28 # Checking for deprecation warning, which should only be provoked when the env variable for it is set.
29 it 'should display a single deprecation' do
30 ENV['STDLIB_LOG_DEPRECATIONS'] = "true"
31 scope.expects(:warning).with(includes('This method is deprecated'))
32 is_expected.to run.with_params('1.2.3.4')
34 it 'should display no warning for deprecation' do
35 ENV['STDLIB_LOG_DEPRECATIONS'] = "false"
36 scope.expects(:warning).with(includes('This method is deprecated')).never
37 is_expected.to run.with_params('1.2.3.4')
41 context 'with netmasks' do
42 it { is_expected.to run.with_params('8.8.8.8/0') }
43 it { is_expected.to run.with_params('8.8.8.8/16') }
44 it { is_expected.to run.with_params('8.8.8.8/32') }
45 it { is_expected.to run.with_params('8.8.8.8/255.255.0.0') }
49 describe 'invalid inputs' do
50 it { is_expected.to run.with_params({}).and_raise_error(Puppet::ParseError, /is not a string/) }
51 it { is_expected.to run.with_params(1).and_raise_error(Puppet::ParseError, /is not a string/) }
52 it { is_expected.to run.with_params(true).and_raise_error(Puppet::ParseError, /is not a string/) }
53 it { is_expected.to run.with_params('one').and_raise_error(Puppet::ParseError, /is not a valid IP/) }
54 it { is_expected.to run.with_params('0.0.0').and_raise_error(Puppet::ParseError, /is not a valid IP/) }
55 it { is_expected.to run.with_params('0.0.0.256').and_raise_error(Puppet::ParseError, /is not a valid IP/) }
56 it { is_expected.to run.with_params('0.0.0.0.0').and_raise_error(Puppet::ParseError, /is not a valid IP/) }
57 it { is_expected.to run.with_params('1.2.3.4', {}).and_raise_error(Puppet::ParseError, /is not a string/) }
58 it { is_expected.to run.with_params('1.2.3.4', 1).and_raise_error(Puppet::ParseError, /is not a string/) }
59 it { is_expected.to run.with_params('1.2.3.4', true).and_raise_error(Puppet::ParseError, /is not a string/) }
60 it { is_expected.to run.with_params('1.2.3.4', 'one').and_raise_error(Puppet::ParseError, /is not a valid IP/) }
61 it { is_expected.to run.with_params('::1', {}).and_raise_error(Puppet::ParseError, /is not a string/) }
62 it { is_expected.to run.with_params('::1', true).and_raise_error(Puppet::ParseError, /is not a string/) }
63 it { is_expected.to run.with_params('::1', 'one').and_raise_error(Puppet::ParseError, /is not a valid IP/) }