Skip to content

add Stdlib::base64 and Stdlib::Base32 types #840

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 26, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 55 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,61 @@ Unacceptable input example:
[email protected]
```

#### `Stdlib::Base32`

Matches paths a valid base32 string

Acceptable input example:

```shell
ASDASDDASD3453453

asdasddasd3453453=

ASDASDDASD3453453==

asdasddasd3453453===
```

Unacceptable input example:

```shell
asdasd!@#$

=asdasd9879876876+/

asdads asdasd

asdasddasd3453453=======
```

#### `Stdlib::Base64`

Matches paths a valid base64 string

Acceptable input example:

```shell
asdasdASDSADA342386832/746+=

asdasdASDSADA34238683274/6+

asdasdASDSADA3423868327/46+==
```

Unacceptable input example:

```shell
asdasd!@#$

=asdasd9879876876+/

asda=sd9879876876+/

asdads asdasd
```


### Facts

#### `package_provider`
Expand Down
6 changes: 6 additions & 0 deletions spec/fixtures/test/manifests/base32.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Class to test the Stdlib::Base32 type alias
class test::base32 (
Stdlib::Base32 $value,
) {
notice('Success')
}
6 changes: 6 additions & 0 deletions spec/fixtures/test/manifests/base64.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Class to test the Stdlib::Base64 type alias
class test::base64 (
Stdlib::Base64 $value,
) {
notice('Success')
}
53 changes: 53 additions & 0 deletions spec/type_aliases/base32_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
require 'spec_helper'

if Puppet::Util::Package.versioncmp(Puppet.version, '4.5.0') >= 0
describe 'Stdlib::Base32' do
describe 'valid handling' do
%w[
ASDASDDASD3453453
ASDASDDASD3453453=
ASDASDDASD3453453==
ASDASDDASD3453453===
ASDASDDASD3453453====
ASDASDDASD3453453=====
ASDASDDASD3453453======
asdasddasd3453453
asdasddasd3453453=
asdasddasd3453453==
asdasddasd3453453===
asdasddasd3453453====
asdasddasd3453453=====
asdasddasd3453453======
].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],
{ 'foo' => 'bar' },
{},
'',
'asdasd!@#$',
'=asdasd9879876876+/',
'asda=sd9879876876+/',
'asdaxsd9879876876+/===',
'asdads asdasd',
'asdasddasd3453453=======',
'asdaSddasd',
'asdasddasd1',
'asdasddasd9',
].each do |value|
describe value.inspect do
it { is_expected.not_to allow_value(value) }
end
end
end
end
end
end
38 changes: 38 additions & 0 deletions spec/type_aliases/base64_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
require 'spec_helper'

if Puppet::Util::Package.versioncmp(Puppet.version, '4.5.0') >= 0
describe 'Stdlib::Base64' do
describe 'valid handling' do
%w[
asdasdASDSADA342386832/746+=
asdasdASDSADA34238683274/6+
asdasdASDSADA3423868327/46+==
].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],
{ 'foo' => 'bar' },
{},
'',
'asdasd!@#$',
'=asdasd9879876876+/',
'asda=sd9879876876+/',
'asdaxsd9879876876+/===',
'asdads asdasd',
].each do |value|
describe value.inspect do
it { is_expected.not_to allow_value(value) }
end
end
end
end
end
end
2 changes: 2 additions & 0 deletions types/base32.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Type to match base32 String
type Stdlib::Base32 = Pattern[/^[a-z2-7]+={,6}$/, /^[A-Z2-7]+={,6}$/]
2 changes: 2 additions & 0 deletions types/base64.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Type to match base64 String
type Stdlib::Base64 = Pattern[/^[a-zA-Z0-9\/\+]+={,2}$/]