diff --git a/README.md b/README.md index bd0802230..06c4a04ab 100644 --- a/README.md +++ b/README.md @@ -463,6 +463,88 @@ Unacceptable input example: %.example.com bob@example.com + +#### `Stdlib::Port` + +Matches a valid TCP/UDP Port number + +Acceptable input examples: + +```shell +80 + +443 + +1337 + +65000 +``` + +Unacceptable input example: + +-1 + +65536 + +'443' + +'https' +```` + +#### `Stdlib::Port::Privileged + +Matches a valid TCP/UDP Pivlaged port i.e. < 1024 + +Acceptable input examples: + +```shell +80 + +443 + +1023 +``` + +Unacceptable input example: + +```shell +-1 + +1337 + +'443' + +'https' +``` + +#### `Stdlib::Port::Unprivileged` + +Matches a valid TCP/UDP Pivlaged port i.e. >= 1024 + +Acceptable input examples: + +```shell +1024 + +1337 + +65000 + +``` + +Unacceptable input example: +```shell +-1 + +80 + +443 + +1023 + +'443' + +'https' ``` ### Facts diff --git a/spec/type_aliases/port__privileged_spec.rb b/spec/type_aliases/port__privileged_spec.rb new file mode 100644 index 000000000..51ddd2478 --- /dev/null +++ b/spec/type_aliases/port__privileged_spec.rb @@ -0,0 +1,39 @@ +require 'spec_helper' + +if Puppet::Util::Package.versioncmp(Puppet.version, '4.5.0') >= 0 + describe 'Stdlib::Port::Privileged' do + describe 'valid ports' do + [ + 80, + 443, + 1023, + ].each do |value| + describe value.inspect do + it { is_expected.to allow_value(value) } + end + end + end + + describe 'invalid path handling' do + context 'garbage inputs' do + [ + nil, + [nil], + [nil, nil], + { 'foo' => 'bar' }, + {}, + '', + 'https', + '443', + -1, + 1337, + 1024, + ].each do |value| + describe value.inspect do + it { is_expected.not_to allow_value(value) } + end + end + end + end + end +end diff --git a/spec/type_aliases/port__unprivileged_spec.rb b/spec/type_aliases/port__unprivileged_spec.rb new file mode 100644 index 000000000..0009e1f64 --- /dev/null +++ b/spec/type_aliases/port__unprivileged_spec.rb @@ -0,0 +1,40 @@ +require 'spec_helper' + +if Puppet::Util::Package.versioncmp(Puppet.version, '4.5.0') >= 0 + describe 'Stdlib::Port::Unprivileged' do + describe 'valid unprivilegedport' do + [ + 1024, + 1337, + 65_000, + ].each do |value| + describe value.inspect do + it { is_expected.to allow_value(value) } + end + end + end + + describe 'invalid path handling' do + context 'garbage inputs' do + [ + nil, + [nil], + [nil, nil], + { 'foo' => 'bar' }, + {}, + '', + 'https', + '443', + -1, + 80, + 443, + 1023, + ].each do |value| + describe value.inspect do + it { is_expected.not_to allow_value(value) } + end + end + end + end + end +end diff --git a/spec/type_aliases/port_spec.rb b/spec/type_aliases/port_spec.rb new file mode 100644 index 000000000..3c9582c19 --- /dev/null +++ b/spec/type_aliases/port_spec.rb @@ -0,0 +1,39 @@ +require 'spec_helper' + +if Puppet::Util::Package.versioncmp(Puppet.version, '4.5.0') >= 0 + describe 'Stdlib::Port' do + describe 'valid ports' do + [ + 80, + 443, + 1337, + 65_000, + ].each do |value| + describe value.inspect do + it { is_expected.to allow_value(value) } + end + end + end + + describe 'invalid path handling' do + context 'garbage inputs' do + [ + nil, + [nil], + [nil, nil], + { 'foo' => 'bar' }, + {}, + '', + 'https', + '443', + -1, + 65_536, + ].each do |value| + describe value.inspect do + it { is_expected.not_to allow_value(value) } + end + end + end + end + end +end diff --git a/types/port.pp b/types/port.pp new file mode 100644 index 000000000..edeef151e --- /dev/null +++ b/types/port.pp @@ -0,0 +1 @@ +type Stdlib::Port = Integer[0, 65535] diff --git a/types/port/privileged.pp b/types/port/privileged.pp new file mode 100644 index 000000000..3fbb7852c --- /dev/null +++ b/types/port/privileged.pp @@ -0,0 +1 @@ +type Stdlib::Port::Privileged = Integer[1, 1023] diff --git a/types/port/unprivileged.pp b/types/port/unprivileged.pp new file mode 100644 index 000000000..ebd29db6e --- /dev/null +++ b/types/port/unprivileged.pp @@ -0,0 +1 @@ +type Stdlib::Port::Unprivileged = Integer[1024, 65535]