Skip to content
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

add Stdlib::Filesource #841

Merged
merged 5 commits into from
Mar 2, 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
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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should also test puppet://someserver/modules/foo/bar.log

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@binford2k thanks for the pointer i didn't see that varient in the docs. Have updeated the type pattern and spec tests

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',
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@binford2k This is actually valid though? https://puppet.com/docs/puppet/5.5/file_serving.html#whats-a-mount-point-in-a-puppet-uri
We're using this type in puppet-zabbix and a user has complained the regex is rejecting valid puppet fileserver mount points. voxpupuli/puppet-zabbix#580

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that should be valid.

'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]+(\/)?)+$/,
],
]