Skip to content

Commit da9a48d

Browse files
committed
Add ports types
1 parent b0d99ad commit da9a48d

File tree

7 files changed

+203
-0
lines changed

7 files changed

+203
-0
lines changed

README.md

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -463,6 +463,88 @@ Unacceptable input example:
463463
%.example.com
464464
465465
bob@example.com
466+
467+
#### `Stdlib::Port`
468+
469+
Matches a valid TCP/UDP Port number
470+
471+
Acceptable input examples:
472+
473+
```shell
474+
80
475+
476+
443
477+
478+
1337
479+
480+
65000
481+
```
482+
483+
Unacceptable input example:
484+
485+
-1
486+
487+
65536
488+
489+
'443'
490+
491+
'https'
492+
````
493+
494+
#### `Stdlib::Port::Privileged
495+
496+
Matches a valid TCP/UDP Pivlaged port i.e. < 1024
497+
498+
Acceptable input examples:
499+
500+
```shell
501+
80
502+
503+
443
504+
505+
1023
506+
```
507+
508+
Unacceptable input example:
509+
510+
```shell
511+
-1
512+
513+
1337
514+
515+
'443'
516+
517+
'https'
518+
```
519+
520+
#### `Stdlib::Port::Unprivileged`
521+
522+
Matches a valid TCP/UDP Pivlaged port i.e. >= 1024
523+
524+
Acceptable input examples:
525+
526+
```shell
527+
1024
528+
529+
1337
530+
531+
65000
532+
533+
```
534+
535+
Unacceptable input example:
536+
```shell
537+
-1
538+
539+
80
540+
541+
443
542+
543+
1023
544+
545+
'443'
546+
547+
'https'
466548
```
467549
468550
### Facts
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
require 'spec_helper'
2+
3+
if Puppet::Util::Package.versioncmp(Puppet.version, '4.5.0') >= 0
4+
describe 'Stdlib::Port::Privileged' do
5+
describe 'valid ports' do
6+
[
7+
80,
8+
443,
9+
1023,
10+
].each do |value|
11+
describe value.inspect do
12+
it { is_expected.to allow_value(value) }
13+
end
14+
end
15+
end
16+
17+
describe 'invalid path handling' do
18+
context 'garbage inputs' do
19+
[
20+
nil,
21+
[nil],
22+
[nil, nil],
23+
{ 'foo' => 'bar' },
24+
{},
25+
'',
26+
'https',
27+
'443',
28+
-1,
29+
1337,
30+
1024,
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
39+
end
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
require 'spec_helper'
2+
3+
if Puppet::Util::Package.versioncmp(Puppet.version, '4.5.0') >= 0
4+
describe 'Stdlib::Port::Unprivileged' do
5+
describe 'valid unprivilegedport' do
6+
[
7+
1024,
8+
1337,
9+
65_000,
10+
].each do |value|
11+
describe value.inspect do
12+
it { is_expected.to allow_value(value) }
13+
end
14+
end
15+
end
16+
17+
describe 'invalid path handling' do
18+
context 'garbage inputs' do
19+
[
20+
nil,
21+
[nil],
22+
[nil, nil],
23+
{ 'foo' => 'bar' },
24+
{},
25+
'',
26+
'https',
27+
'443',
28+
-1,
29+
80,
30+
443,
31+
1023,
32+
].each do |value|
33+
describe value.inspect do
34+
it { is_expected.not_to allow_value(value) }
35+
end
36+
end
37+
end
38+
end
39+
end
40+
end

spec/type_aliases/port_spec.rb

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
require 'spec_helper'
2+
3+
if Puppet::Util::Package.versioncmp(Puppet.version, '4.5.0') >= 0
4+
describe 'Stdlib::Port' do
5+
describe 'valid ports' do
6+
[
7+
80,
8+
443,
9+
1337,
10+
65_000,
11+
].each do |value|
12+
describe value.inspect do
13+
it { is_expected.to allow_value(value) }
14+
end
15+
end
16+
end
17+
18+
describe 'invalid path handling' do
19+
context 'garbage inputs' do
20+
[
21+
nil,
22+
[nil],
23+
[nil, nil],
24+
{ 'foo' => 'bar' },
25+
{},
26+
'',
27+
'https',
28+
'443',
29+
-1,
30+
65_536,
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
39+
end

types/port.pp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
type Stdlib::Port = Integer[0, 65535]

types/port/privileged.pp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
type Stdlib::Port::Privileged = Integer[1, 1023]

types/port/unprivileged.pp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
type Stdlib::Port::Unprivileged = Integer[1024, 65535]

0 commit comments

Comments
 (0)