From 6c3aa83bf85ba91df83630b1814f6da41328b64d Mon Sep 17 00:00:00 2001 From: John Bond Date: Tue, 6 Jul 2021 15:55:29 +0200 Subject: [PATCH] Stdlib::Http::Method: Add new type for http methods This PR creates new new resources: * Stdlib::Http::Method for validating http methods * Stdlib::Http::Status This is just a copy of Stdlib::Httpstatus * make Stdlib::Httpstatus and alias to Stdlib::Http::Status Ideally we would deprecate Stdlib::Httpstatus in favour of Stdlib::Http::Status --- spec/type_aliases/http__method_spec.rb | 40 ++++++++++++++++++++++++ spec/type_aliases/http__status_spec.rb | 38 +++++++++++++++++++++++ types/http/method.pp | 42 ++++++++++++++++++++++++++ types/http/status.pp | 1 + types/httpstatus.pp | 2 +- 5 files changed, 122 insertions(+), 1 deletion(-) create mode 100644 spec/type_aliases/http__method_spec.rb create mode 100644 spec/type_aliases/http__status_spec.rb create mode 100644 types/http/method.pp create mode 100644 types/http/status.pp diff --git a/spec/type_aliases/http__method_spec.rb b/spec/type_aliases/http__method_spec.rb new file mode 100644 index 000000000..e80d02027 --- /dev/null +++ b/spec/type_aliases/http__method_spec.rb @@ -0,0 +1,40 @@ +require 'spec_helper' + +describe 'Stdlib::Http::Method' do + describe 'valid HTTP Methods' do + [ + 'HEAD', + 'GET', + 'PUT', + 'DELETE', + 'TRACE', + ].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', + '199', + 600, + 1_000, + 'Ok', + 'get', + ].each do |value| + describe value.inspect do + it { is_expected.not_to allow_value(value) } + end + end + end + end +end diff --git a/spec/type_aliases/http__status_spec.rb b/spec/type_aliases/http__status_spec.rb new file mode 100644 index 000000000..123612fc3 --- /dev/null +++ b/spec/type_aliases/http__status_spec.rb @@ -0,0 +1,38 @@ +require 'spec_helper' + +describe 'Stdlib::Http::Status' do + describe 'valid HTTP Status' do + [ + 200, + 302, + 404, + 418, + 503, + ].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', + '199', + 600, + 1_000, + ].each do |value| + describe value.inspect do + it { is_expected.not_to allow_value(value) } + end + end + end + end +end diff --git a/types/http/method.pp b/types/http/method.pp new file mode 100644 index 000000000..71fdf3c48 --- /dev/null +++ b/types/http/method.pp @@ -0,0 +1,42 @@ +# https://www.iana.org/assignments/http-methods/http-methods.xhtml +type Stdlib::Http::Method = Enum[ + 'ACL', + 'BASELINE-CONTROL', + 'BIND', + 'CHECKIN', + 'CHECKOUT', + 'CONNECT', + 'COPY', + 'DELETE', + 'GET', + 'HEAD', + 'LABEL', + 'LINK', + 'LOCK', + 'MERGE', + 'MKACTIVITY', + 'MKCALENDAR', + 'MKCOL', + 'MKREDIRECTREF', + 'MKWORKSPACE', + 'MOVE', + 'OPTIONS', + 'ORDERPATCH', + 'PATCH', + 'POST', + 'PRI', + 'PROPFIND', + 'PROPPATCH', + 'PUT', + 'REBIND', + 'REPORT', + 'SEARCH', + 'TRACE', + 'UNBIND', + 'UNCHECKOUT', + 'UNLINK', + 'UNLOCK', + 'UPDATE', + 'UPDATEREDIRECTREF', + 'VERSION-CONTROL', +] diff --git a/types/http/status.pp b/types/http/status.pp new file mode 100644 index 000000000..cc81e71e6 --- /dev/null +++ b/types/http/status.pp @@ -0,0 +1 @@ +type Stdlib::Http::Status = Integer[100, 599] diff --git a/types/httpstatus.pp b/types/httpstatus.pp index 146587be8..3385c9c62 100644 --- a/types/httpstatus.pp +++ b/types/httpstatus.pp @@ -1 +1 @@ -type Stdlib::HttpStatus = Integer[100, 599] +type Stdlib::HttpStatus = Stdlib::Http::Status