Skip to content

Commit

Permalink
Merge pull request #841 from b4ldr/type_filesource
Browse files Browse the repository at this point in the history
add Stdlib::Filesource
  • Loading branch information
david22swan authored Mar 2, 2018
2 parents 19e280d + f852ba3 commit 598e0a3
Show file tree
Hide file tree
Showing 3 changed files with 101 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
```

#### `Stdlib::Fqdn`
Expand Down
59 changes: 59 additions & 0 deletions spec/type_aliases/filesource_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
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
puppet://pm.example.com/modules/foo/bar.log
puppet://192.0.2.1/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',
'puppet:///pm.example.com/modules/foo/bar.log',
'puppet://[email protected]/modules/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:\/\/(([\w-]+\.?)+)?\/modules\/([^\/\0]+(\/)?)+$/,
],
]

0 comments on commit 598e0a3

Please sign in to comment.