Skip to content

Commit d403488

Browse files
committed
add port types
1 parent e5dff2f commit d403488

File tree

10 files changed

+223
-0
lines changed

10 files changed

+223
-0
lines changed

README.md

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -413,6 +413,90 @@ Unacceptable input example:
413413
/usr2/username/bin:/usr/local/bin:/usr/bin:.
414414
```
415415

416+
#### `Stdlib::Port`
417+
418+
Matches a valid TCP/UDP Port number
419+
420+
Acceptable input examples:
421+
422+
```shell
423+
80
424+
425+
443
426+
427+
1337
428+
429+
65000
430+
```
431+
432+
Unacceptable input example:
433+
434+
```shell
435+
-1
436+
437+
65536
438+
439+
'443'
440+
441+
'https'
442+
````
443+
444+
#### `Stdlib::Privilegedport`
445+
446+
Matches a valid TCP/UDP Pivlaged port i.e. < 1024
447+
448+
Acceptable input examples:
449+
450+
```shell
451+
80
452+
453+
443
454+
455+
1023
456+
```
457+
458+
Unacceptable input example:
459+
460+
```shell
461+
-1
462+
463+
1337
464+
465+
'443'
466+
467+
'https'
468+
```
469+
470+
#### `Stdlib::Unprivilegedport`
471+
472+
Matches a valid TCP/UDP Pivlaged port i.e. >= 1024
473+
474+
Acceptable input examples:
475+
476+
```shell
477+
1024
478+
479+
1337
480+
481+
65000
482+
```
483+
484+
Unacceptable input example:
485+
486+
```shell
487+
-1
488+
489+
80
490+
491+
443
492+
493+
1023
494+
495+
'443'
496+
497+
'https'
498+
```
499+
416500
### Facts
417501

418502
#### `package_provider`

spec/fixtures/test/manifests/port.pp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Class to test the Stdlib::Port type alias
2+
class test::port(
3+
Stdlib::Port $value,
4+
) {
5+
notice("Success")
6+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Class to test the Stdlib::Privilegedport type alias
2+
class test::privilegedport(
3+
Stdlib::Privilegedport $value,
4+
) {
5+
notice("Success")
6+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Class to test the Stdlib::Unprivilegedport type alias
2+
class test::unprivilegedport(
3+
Stdlib::Unprivilegedport $value,
4+
) {
5+
notice("Success")
6+
}

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+
65000,
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+
65536,
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: 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::Privilegedport' 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::Unprivilegedport' do
5+
describe 'valid unprivilegedport' do
6+
[
7+
1024,
8+
1337,
9+
65000,
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

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/privilegedport.pp

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

types/unprivilegedport.pp

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

0 commit comments

Comments
 (0)