Skip to content

Commit dd28f86

Browse files
committed
add Stdlib::base64 and Stdlib::Base32 types
1 parent e5dff2f commit dd28f86

File tree

7 files changed

+161
-0
lines changed

7 files changed

+161
-0
lines changed

README.md

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

416+
#### `Stdlib::Base32`
417+
418+
Matches paths a valid base32 string
419+
420+
Acceptable input example:
421+
422+
```shell
423+
ASDASDDASD3453453
424+
425+
asdasddasd3453453=
426+
427+
ASDASDDASD3453453==
428+
429+
asdasddasd3453453===
430+
```
431+
432+
Unacceptable input example:
433+
434+
```shell
435+
asdasd!@#$
436+
437+
=asdasd9879876876+/
438+
439+
asdads asdasd
440+
441+
asdasddasd3453453=======
442+
```
443+
444+
#### `Stdlib::Base64`
445+
446+
Matches paths a valid base64 string
447+
448+
Acceptable input example:
449+
450+
```shell
451+
asdasdASDSADA342386832/746+=
452+
453+
asdasdASDSADA34238683274/6+
454+
455+
asdasdASDSADA3423868327/46+==
456+
```
457+
458+
Unacceptable input example:
459+
460+
```shell
461+
asdasd!@#$
462+
463+
=asdasd9879876876+/
464+
465+
asda=sd9879876876+/
466+
467+
asdads asdasd
468+
```
469+
416470
### Facts
417471

418472
#### `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)