Skip to content

Commit

Permalink
add Stdlib::Filesource
Browse files Browse the repository at this point in the history
  • Loading branch information
b4ldr committed Nov 30, 2017
1 parent e5dff2f commit cb97581
Show file tree
Hide file tree
Showing 4 changed files with 103 additions and 1 deletion.
34 changes: 33 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -409,8 +409,40 @@ C:\\

Unacceptable input example:

#### `Stdlib::Filesource`

Matches paths valid values for the source parameter of the puppet file type

Acceptable input example:

```shell
/usr2/username/bin:/usr/local/bin:/usr/bin:.
http://example.com
https://example.com
file:///hello/bla
/usr2/username/bin
C:\foo\bar
/var/opt/../lib/puppet
puppet:///modules/foo/bar.log
```

Unacceptable input example:

```shell
*/Users//nope
\Users/hc/wksp/stdlib
C:noslashes
puppet:///foo/bar.log
ftp://ftp.example.com
```

### Facts
Expand Down
6 changes: 6 additions & 0 deletions spec/fixtures/test/manifests/filesource.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Class to test the Stdlib::Filesource type alias
class test::filesource (
Stdlib::Filesource $value,
) {
notice('Success')
}
55 changes: 55 additions & 0 deletions spec/type_aliases/filesource_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
require 'spec_helper'

if Puppet::Util::Package.versioncmp(Puppet.version, '4.5.0') >= 0
describe 'Stdlib::Filesource' do
describe 'valid handling' do
%w(
https://hello.com
https://notcreative.org
https://canstillaccepthttps.co.uk
http://anhttp.com
http://runningoutofideas.gov
file:///hello/bla
file:///foo/bar.log
puppet:///modules/foo/bar.log
/usr2/username/bin:/usr/local/bin:/usr/bin:.
C:/
C:\\
C:\\WINDOWS\\System32
C:/windows/system32
X:/foo/bar
X:\\foo\\bar
\\\\host\\windows
//host/windows
/var/tmp
/var/opt/../lib/puppet
).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' },
{},
'',
'*/Users//nope',
'\\Users/hc/wksp/stdlib',
'C:noslashes',
'\\var\\tmp',
'puppet:///foo/bar.log'
].each do |value|
describe value.inspect do
it { is_expected.not_to allow_value(value) }
end
end
end
end
end
end
9 changes: 9 additions & 0 deletions types/filesource.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Validate the source parameter on file types
type Stdlib::Filesource = Variant[
Stdlib::Absolutepath,
Stdlib::HTTPUrl,
Pattern[
/^file:\/\/\/([^\/\0]+(\/)?)+$/,
/^puppet:\/\/\/modules\/([^\/\0]+(\/)?)+$/,
],
]

0 comments on commit cb97581

Please sign in to comment.