Skip to content

Commit b9a40c8

Browse files
authored
Merge pull request #843 from b4ldr/type_ip
update Stdlib::*::ip* types
2 parents d5f3fe2 + 5400d09 commit b9a40c8

File tree

10 files changed

+236
-3
lines changed

10 files changed

+236
-3
lines changed

README.md

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -601,6 +601,110 @@ asda=sd9879876876+/
601601
asdads asdasd
602602
```
603603
604+
#### `Stdlib::Ipv4`
605+
606+
Matches on valid IPv4 addresses
607+
608+
Acceptable input example:
609+
610+
```shell
611+
0.0.0.0
612+
613+
192.0.2.1
614+
615+
127.0.0.1
616+
```
617+
618+
Unacceptable input example:
619+
620+
```shell
621+
0000
622+
623+
0.0.0.0.
624+
625+
0.0.0.256
626+
627+
2001:0db8::1
628+
629+
1.2.3.4.5
630+
```
631+
632+
#### `Stdlib::Ipv6`
633+
634+
Matches on valid IPv6 addresses
635+
636+
Acceptable input example:
637+
638+
```shell
639+
2001:0db8:85a3:0000:0000:8a2e:0370:7334
640+
641+
fe80:0000:0000:0000:0204:61ff:fe9d:f156
642+
643+
2001:db8::
644+
645+
::1
646+
647+
2001:db8::80
648+
```
649+
650+
Unacceptable input example:
651+
652+
```shell
653+
0.0.0.0
654+
655+
192.0.2.1
656+
657+
127.0.0.1
658+
659+
2000:7334
660+
661+
::ffff:2.3.4
662+
663+
foobar2001:db8::1
664+
```
665+
666+
#### `Stdlib::Ip_address`
667+
668+
Matches on valid IPv4 or IPv6 addresses
669+
670+
Acceptable input example:
671+
672+
```shell
673+
0.0.0.0
674+
675+
192.0.2.1
676+
677+
127.0.0.1
678+
679+
2001:0db8:85a3:0000:0000:8a2e:0370:7334
680+
681+
fe80:0000:0000:0000:0204:61ff:fe9d:f156
682+
683+
2001:db8::
684+
685+
::1
686+
687+
2001:db8::80
688+
```
689+
690+
Unacceptable input example:
691+
692+
```shell
693+
0000
694+
695+
0.0.0.0.
696+
697+
0.0.0.256
698+
699+
1.2.3.4.5
700+
701+
2000:7334
702+
703+
::ffff:2.3.4
704+
705+
foobar2001:db8::1
706+
```
707+
604708
605709
### Facts
606710
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
require 'spec_helper'
2+
3+
if Puppet::Util::Package.versioncmp(Puppet.version, '4.5.0') >= 0
4+
describe 'Stdlib::Compat::Ip_address' do
5+
describe 'accepts ipv4 and ipv6 addresses' do
6+
[
7+
'224.0.0.0',
8+
'255.255.255.255',
9+
'0.0.0.0',
10+
'192.88.99.0',
11+
'2001:0db8:85a3:0000:0000:8a2e:0370:7334',
12+
'fa76:8765:34ac:0823:ab76:eee9:0987:1111',
13+
].each do |value|
14+
describe value.inspect do
15+
it { is_expected.to allow_value(value) }
16+
end
17+
end
18+
end
19+
describe 'rejects other values' do
20+
[
21+
nil,
22+
[nil],
23+
[nil, nil],
24+
{ 'foo' => 'bar' },
25+
{},
26+
'',
27+
'nope',
28+
'77',
29+
'4.4.4',
30+
'2001:0db8:85a3:000000:0000:8a2e:0370:7334',
31+
].each do |value|
32+
describe value.inspect do
33+
it { is_expected.not_to allow_value(value) }
34+
end
35+
end
36+
end
37+
end
38+
end
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
require 'spec_helper'
2+
3+
if Puppet::Util::Package.versioncmp(Puppet.version, '4.5.0') >= 0
4+
describe 'Stdlib::Compat::Ipv4' do
5+
describe 'accepts ipv4 addresses' do
6+
SharedData::IPV4_PATTERNS.each do |value|
7+
describe value.inspect do
8+
it { is_expected.to allow_value(value) }
9+
end
10+
end
11+
end
12+
describe 'rejects other values' do
13+
SharedData::IPV4_NEGATIVE_PATTERNS.each do |value|
14+
describe value.inspect do
15+
it { is_expected.not_to allow_value(value) }
16+
end
17+
end
18+
end
19+
end
20+
end
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
require 'spec_helper'
2+
3+
if Puppet::Util::Package.versioncmp(Puppet.version, '4.5.0') >= 0
4+
describe 'Stdlib::Compat::Ipv6' do
5+
describe 'accepts ipv6 addresses' do
6+
[
7+
'2001:0db8:85a3:0000:0000:8a2e:0370:7334',
8+
'fa76:8765:34ac:0823:ab76:eee9:0987:1111',
9+
'fe80:0000:0000:0000:0204:61ff:fe9d:f156',
10+
'fe80:0:0:0:204:61ff:fe9d:f156',
11+
'fe80::204:61ff:fe9d:f156',
12+
'fe80:0:0:0:0204:61ff:254.157.241.86',
13+
'::1',
14+
'fe80::',
15+
'2001::',
16+
].each do |value|
17+
describe value.inspect do
18+
it { is_expected.to allow_value(value) }
19+
end
20+
end
21+
end
22+
describe 'rejects other values' do
23+
[
24+
nil,
25+
[nil],
26+
[nil, nil],
27+
{ 'foo' => 'bar' },
28+
{},
29+
'',
30+
'nope',
31+
'77',
32+
'4.4.4',
33+
'2000:7334',
34+
'::ffff:2.3.4',
35+
'::ffff:257.1.2.3',
36+
'::ffff:12345678901234567890.1.26',
37+
].each do |value|
38+
describe value.inspect do
39+
it { is_expected.not_to allow_value(value) }
40+
end
41+
end
42+
end
43+
end
44+
end

spec/type_aliases/ip_address.rb

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
require 'spec_helper'
22

33
if Puppet::Util::Package.versioncmp(Puppet.version, '4.5.0') >= 0
4-
describe 'Stdlib::Compat::Ip_address' do
4+
describe 'Stdlib::Ip_address' do
55
describe 'accepts ipv4 and ipv6 addresses' do
66
[
77
'224.0.0.0',
@@ -18,10 +18,22 @@
1818
end
1919
describe 'rejects other values' do
2020
[
21+
nil,
22+
[nil],
23+
[nil, nil],
24+
{ 'foo' => 'bar' },
25+
{},
26+
'',
2127
'nope',
2228
'77',
2329
'4.4.4',
2430
'2001:0db8:85a3:000000:0000:8a2e:0370:7334',
31+
'2001::0db8::1',
32+
' 2001:0db8::1',
33+
'2001:0db8::1 ',
34+
' 2001:0db8::1 ',
35+
'foobar2001:0db8::1',
36+
'2001:0db8::1foobar',
2537
].each do |value|
2638
describe value.inspect do
2739
it { is_expected.not_to allow_value(value) }

spec/type_aliases/ipv4_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
require 'spec_helper'
22

33
if Puppet::Util::Package.versioncmp(Puppet.version, '4.5.0') >= 0
4-
describe 'Stdlib::Compat::Ipv4' do
4+
describe 'Stdlib::Ipv4' do
55
describe 'accepts ipv4 addresses' do
66
SharedData::IPV4_PATTERNS.each do |value|
77
describe value.inspect do

spec/type_aliases/ipv6_spec.rb

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
require 'spec_helper'
22

33
if Puppet::Util::Package.versioncmp(Puppet.version, '4.5.0') >= 0
4-
describe 'Stdlib::Compat::Ipv6' do
4+
describe 'Stdlib::Ipv6' do
55
describe 'accepts ipv6 addresses' do
66
[
77
'2001:0db8:85a3:0000:0000:8a2e:0370:7334',
@@ -21,13 +21,25 @@
2121
end
2222
describe 'rejects other values' do
2323
[
24+
nil,
25+
[nil],
26+
[nil, nil],
27+
{ 'foo' => 'bar' },
28+
{},
29+
'',
2430
'nope',
2531
'77',
2632
'4.4.4',
2733
'2000:7334',
2834
'::ffff:2.3.4',
2935
'::ffff:257.1.2.3',
3036
'::ffff:12345678901234567890.1.26',
37+
'2001::0db8::1',
38+
' 2001:0db8::1',
39+
'2001:0db8::1 ',
40+
' 2001:0db8::1 ',
41+
'foobar2001:0db8::1',
42+
'2001:0db8::1foobar',
3143
].each do |value|
3244
describe value.inspect do
3345
it { is_expected.not_to allow_value(value) }

types/ip_address.pp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
type Stdlib::Ip_address = Variant[Stdlib::Ipv4, Stdlib::Ipv6]

types/ipv4.pp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
type Stdlib::Ipv4 = Stdlib::Compat::Ipv4

types/ipv6.pp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
type Stdlib::Ipv6 = Pattern[/^((([0-9A-Fa-f]{1,4}:){7}([0-9A-Fa-f]{1,4}|:))|(([0-9A-Fa-f]{1,4}:){6}(:[0-9A-Fa-f]{1,4}|((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9A-Fa-f]{1,4}:){5}(((:[0-9A-Fa-f]{1,4}){1,2})|:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9A-Fa-f]{1,4}:){4}(((:[0-9A-Fa-f]{1,4}){1,3})|((:[0-9A-Fa-f]{1,4})?:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){3}(((:[0-9A-Fa-f]{1,4}){1,4})|((:[0-9A-Fa-f]{1,4}){0,2}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){2}(((:[0-9A-Fa-f]{1,4}){1,5})|((:[0-9A-Fa-f]{1,4}){0,3}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){1}(((:[0-9A-Fa-f]{1,4}){1,6})|((:[0-9A-Fa-f]{1,4}){0,4}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(:(((:[0-9A-Fa-f]{1,4}){1,7})|((:[0-9A-Fa-f]{1,4}){0,5}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:)))(%.+)?$/]

0 commit comments

Comments
 (0)