Skip to content

Fix having wildcards (%) in hostnames of grants #366

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

Merged
merged 2 commits into from
Nov 19, 2013
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
2 changes: 1 addition & 1 deletion lib/puppet/provider/mysql_grant/mysql.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def self.instances
# Match the munges we do in the type.
munged_grant = grant.delete("'").delete("`")
# Matching: GRANT (SELECT, UPDATE) PRIVILEGES ON (*.*) TO ('root'@'127.0.0.1') (WITH GRANT OPTION)
if match = munged_grant.match(/^GRANT\s(.*)\sON\s(.*)\sTO\s(\w+@\w+)(\s.*)$/)
if match = munged_grant.match(/^GRANT\s(.*)\sON\s(.*)\sTO\s(.*@.*?)(\s.*)$/)
privileges, table, grantuser, rest = match.captures
# Once we split privileges up on the , we need to make sure we
# shortern ALL PRIVILEGES to just all.
Expand Down
38 changes: 38 additions & 0 deletions spec/system/types/mysql_grant_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -130,4 +130,42 @@ class { 'mysql::server': }
end
end

# Test combinations of user@host to ensure all cases work.
describe 'hostname with wildcards' do
it 'should apply' do
pp = <<-EOS
mysql_grant { '[email protected].%/test.*':
ensure => 'present',
table => 'test.*',
user => '[email protected].%',
privileges => 'ALL',
}
EOS

puppet_apply(pp)
end

it 'finds hostname with wildcards' do
shell("mysql -NBe \"SHOW GRANTS FOR test@'192.168.%'\"") do |r|
r.stdout.should =~ /GRANT ALL PRIVILEGES ON `test`.* TO 'test'@'192.168.%'/
r.stderr.should be_empty
r.exit_code.should be_zero
end
end

it 'should not do any changes on second run' do
pp = <<-EOS
mysql_grant { '[email protected].%/test.*':
ensure => 'present',
table => 'test.*',
user => '[email protected].%',
privileges => 'ALL',
}
EOS

puppet_apply(pp) do |r|
r.exit_code.should be_zero
end
end
end
end