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

Fix defaults: behaviour #19

Merged
merged 1 commit into from
Sep 23, 2015
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
16 changes: 2 additions & 14 deletions lib/puppet/type/acl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -211,20 +211,8 @@ def insync?(is)
defaultto :false
end

def self.pick_default_perms(perms)
non_default = perms.reject { |perm| perm =~ /^d/ }
default = perms.reject { |perm| perm !~ /^d/ }.map {
|perm| perm.split(':')[1..-1].join(':')
}
Set.new((non_default + default).map { |perm|
key = perm.split(':')[0..1].join(':')
matching_default = default.reject { |tmp_perm| tmp_perm !~ /^#{key}:/ }
if (matching_default.length > 0)
matching_default
else
perm
end
}).to_a.flatten
def self.pick_default_perms(acl)
return acl.reject { |a| a.split(':', -1).length == 4 }
end

def newchild(path)
Expand Down
18 changes: 15 additions & 3 deletions spec/unit/puppet/type/acl_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -129,16 +129,28 @@
end
end

context 'when converting default parameters' do
context 'when removing default parameters' do
basic_perms = ['user:foo:rwx', 'group:foo:rwx']
advanced_perms = ['user:foo:rwx', 'group:foo:rwx', 'default:user:foo:---']
advanced_perms_results = ['user:foo:---', 'group:foo:rwx']
advanced_perms_results = ['user:foo:rwx', 'group:foo:rwx']
mysql_perms = [
"user:mysql:rwx",
"d:user:mysql:rw",
"mask::rwx",
]
mysql_perms_results = [
"user:mysql:rwx",
"mask::rwx",
]
it 'should not do anything with no defaults' do
expect(acl_type.pick_default_perms(basic_perms)).to match_array(basic_perms)
end
it 'should override defaults' do
it 'should remove defaults' do
expect(acl_type.pick_default_perms(advanced_perms)).to match_array(advanced_perms_results)
end
it 'should remove defaults with d:' do
expect(acl_type.pick_default_perms(mysql_perms)).to match_array(mysql_perms_results)
end
end

end