|
| 1 | +require 'spec_helper' |
| 2 | + |
| 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, /wrong number of arguments/i) } |
| 7 | + end |
| 8 | + |
| 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') } |
| 22 | + context 'with netmasks' do |
| 23 | + it { is_expected.to run.with_params('8.8.8.8/0') } |
| 24 | + it { is_expected.to run.with_params('8.8.8.8/16') } |
| 25 | + it { is_expected.to run.with_params('8.8.8.8/32') } |
| 26 | + it { is_expected.to run.with_params('8.8.8.8/255.255.0.0') } |
| 27 | + end |
| 28 | + end |
| 29 | + |
| 30 | + describe 'invalid inputs' do |
| 31 | + it { is_expected.to run.with_params({}).and_raise_error(Puppet::ParseError, /is not a string/) } |
| 32 | + it { is_expected.to run.with_params(1).and_raise_error(Puppet::ParseError, /is not a string/) } |
| 33 | + it { is_expected.to run.with_params(true).and_raise_error(Puppet::ParseError, /is not a string/) } |
| 34 | + it { is_expected.to run.with_params('one').and_raise_error(Puppet::ParseError, /is not a valid IP/) } |
| 35 | + it { is_expected.to run.with_params('0.0.0').and_raise_error(Puppet::ParseError, /is not a valid IP/) } |
| 36 | + it { is_expected.to run.with_params('0.0.0.256').and_raise_error(Puppet::ParseError, /is not a valid IP/) } |
| 37 | + it { is_expected.to run.with_params('0.0.0.0.0').and_raise_error(Puppet::ParseError, /is not a valid IP/) } |
| 38 | + it { is_expected.to run.with_params('1.2.3.4', {}).and_raise_error(Puppet::ParseError, /is not a string/) } |
| 39 | + it { is_expected.to run.with_params('1.2.3.4', 1).and_raise_error(Puppet::ParseError, /is not a string/) } |
| 40 | + it { is_expected.to run.with_params('1.2.3.4', true).and_raise_error(Puppet::ParseError, /is not a string/) } |
| 41 | + it { is_expected.to run.with_params('1.2.3.4', 'one').and_raise_error(Puppet::ParseError, /is not a valid IP/) } |
| 42 | + it { is_expected.to run.with_params('::1', {}).and_raise_error(Puppet::ParseError, /is not a string/) } |
| 43 | + it { is_expected.to run.with_params('::1', true).and_raise_error(Puppet::ParseError, /is not a string/) } |
| 44 | + it { is_expected.to run.with_params('::1', 'one').and_raise_error(Puppet::ParseError, /is not a valid IP/) } |
| 45 | + end |
| 46 | +end |
0 commit comments