Skip to content

Commit d884e2f

Browse files
author
Ashley Penney
committed
Merge pull request #522 from cmurphy/fix_mysql_grant_MODULES-1040
Require title of mysql_grant resource to match form user/table
2 parents b3ecc7b + 07b661d commit d884e2f

File tree

3 files changed

+23
-1
lines changed

3 files changed

+23
-1
lines changed

lib/puppet/type/mysql_grant.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ def initialize(*args)
2424
fail('privileges parameter is required.') if self[:ensure] == :present and self[:privileges].nil?
2525
fail('table parameter is required.') if self[:ensure] == :present and self[:table].nil?
2626
fail('user parameter is required.') if self[:ensure] == :present and self[:user].nil?
27+
fail('name must match user and table parameters') if self[:name] != "#{self[:user]}/#{self[:table]}"
2728
end
2829

2930
newparam(:name, :namevar => true) do

spec/acceptance/types/mysql_grant_spec.rb

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,21 @@ class { 'mysql::server': }
7070
end
7171
end
7272

73+
describe 'adding privileges with invalid name' do
74+
it 'should fail' do
75+
pp = <<-EOS
76+
mysql_grant { 'test':
77+
ensure => 'present',
78+
table => 'test.*',
79+
user => 'test2@tester',
80+
privileges => ['SELECT', 'UPDATE'],
81+
}
82+
EOS
83+
84+
expect(apply_manifest(pp, :expect_failures => true).stderr).to match(/name must match user and table parameters/)
85+
end
86+
end
87+
7388
describe 'adding option' do
7489
it 'should work without errors' do
7590
pp = <<-EOS

spec/unit/puppet/type/mysql_grant_spec.rb

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,10 @@
4141
}.to raise_error(Puppet::Error, 'Title or name must be provided')
4242
end
4343

44-
end
44+
it 'should require the name to match the user and table' do
45+
expect {
46+
Puppet::Type.type(:mysql_grant).new(:name => 'foo', :privileges => ['ALL', 'PROXY'], :table => ['*.*','@'], :user => 'foo@localhost')
47+
}.to raise_error /name must match user and table parameters/
48+
end
49+
50+
end

0 commit comments

Comments
 (0)