Skip to content

Commit 4f9dc7f

Browse files
authored
Merge pull request #840 from b4ldr/type_base64
add Stdlib::base64 and Stdlib::Base32 types
2 parents b0d99ad + 84ee87c commit 4f9dc7f

File tree

7 files changed

+162
-0
lines changed

7 files changed

+162
-0
lines changed

README.md

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -465,6 +465,61 @@ Unacceptable input example:
465465
466466
```
467467

468+
#### `Stdlib::Base32`
469+
470+
Matches paths a valid base32 string
471+
472+
Acceptable input example:
473+
474+
```shell
475+
ASDASDDASD3453453
476+
477+
asdasddasd3453453=
478+
479+
ASDASDDASD3453453==
480+
481+
asdasddasd3453453===
482+
```
483+
484+
Unacceptable input example:
485+
486+
```shell
487+
asdasd!@#$
488+
489+
=asdasd9879876876+/
490+
491+
asdads asdasd
492+
493+
asdasddasd3453453=======
494+
```
495+
496+
#### `Stdlib::Base64`
497+
498+
Matches paths a valid base64 string
499+
500+
Acceptable input example:
501+
502+
```shell
503+
asdasdASDSADA342386832/746+=
504+
505+
asdasdASDSADA34238683274/6+
506+
507+
asdasdASDSADA3423868327/46+==
508+
```
509+
510+
Unacceptable input example:
511+
512+
```shell
513+
asdasd!@#$
514+
515+
=asdasd9879876876+/
516+
517+
asda=sd9879876876+/
518+
519+
asdads asdasd
520+
```
521+
522+
468523
### Facts
469524

470525
#### `package_provider`
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Class to test the Stdlib::Base32 type alias
2+
class test::base32 (
3+
Stdlib::Base32 $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::Base64 type alias
2+
class test::base64 (
3+
Stdlib::Base64 $value,
4+
) {
5+
notice('Success')
6+
}

spec/type_aliases/base32_spec.rb

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
require 'spec_helper'
2+
3+
if Puppet::Util::Package.versioncmp(Puppet.version, '4.5.0') >= 0
4+
describe 'Stdlib::Base32' do
5+
describe 'valid handling' do
6+
%w[
7+
ASDASDDASD3453453
8+
ASDASDDASD3453453=
9+
ASDASDDASD3453453==
10+
ASDASDDASD3453453===
11+
ASDASDDASD3453453====
12+
ASDASDDASD3453453=====
13+
ASDASDDASD3453453======
14+
asdasddasd3453453
15+
asdasddasd3453453=
16+
asdasddasd3453453==
17+
asdasddasd3453453===
18+
asdasddasd3453453====
19+
asdasddasd3453453=====
20+
asdasddasd3453453======
21+
].each do |value|
22+
describe value.inspect do
23+
it { is_expected.to allow_value(value) }
24+
end
25+
end
26+
end
27+
28+
describe 'invalid path handling' do
29+
context 'garbage inputs' do
30+
[
31+
[nil],
32+
[nil, nil],
33+
{ 'foo' => 'bar' },
34+
{},
35+
'',
36+
'asdasd!@#$',
37+
'=asdasd9879876876+/',
38+
'asda=sd9879876876+/',
39+
'asdaxsd9879876876+/===',
40+
'asdads asdasd',
41+
'asdasddasd3453453=======',
42+
'asdaSddasd',
43+
'asdasddasd1',
44+
'asdasddasd9',
45+
].each do |value|
46+
describe value.inspect do
47+
it { is_expected.not_to allow_value(value) }
48+
end
49+
end
50+
end
51+
end
52+
end
53+
end

spec/type_aliases/base64_spec.rb

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
require 'spec_helper'
2+
3+
if Puppet::Util::Package.versioncmp(Puppet.version, '4.5.0') >= 0
4+
describe 'Stdlib::Base64' do
5+
describe 'valid handling' do
6+
%w[
7+
asdasdASDSADA342386832/746+=
8+
asdasdASDSADA34238683274/6+
9+
asdasdASDSADA3423868327/46+==
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, nil],
22+
{ 'foo' => 'bar' },
23+
{},
24+
'',
25+
'asdasd!@#$',
26+
'=asdasd9879876876+/',
27+
'asda=sd9879876876+/',
28+
'asdaxsd9879876876+/===',
29+
'asdads asdasd',
30+
].each do |value|
31+
describe value.inspect do
32+
it { is_expected.not_to allow_value(value) }
33+
end
34+
end
35+
end
36+
end
37+
end
38+
end

types/base32.pp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Type to match base32 String
2+
type Stdlib::Base32 = Pattern[/^[a-z2-7]+={,6}$/, /^[A-Z2-7]+={,6}$/]

types/base64.pp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Type to match base64 String
2+
type Stdlib::Base64 = Pattern[/^[a-zA-Z0-9\/\+]+={,2}$/]

0 commit comments

Comments
 (0)