Skip to content

Commit 96f86dc

Browse files
committed
Merge pull request #961 from eputnam/MODULES-4896
(MODULES-4604) move name validation in mysql_grant type
2 parents 99738fc + 842916c commit 96f86dc

File tree

3 files changed

+7
-21
lines changed

3 files changed

+7
-21
lines changed

lib/puppet/type/mysql_grant.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,9 @@ def initialize(*args)
3434
fail('PROXY must be the only privilege specified.') if Array(self[:privileges]).count > 1 and Array(self[:privileges]).include?('PROXY')
3535
fail('table parameter is required.') if self[:ensure] == :present and self[:table].nil?
3636
fail('user parameter is required.') if self[:ensure] == :present and self[:user].nil?
37-
fail('name must match user and table parameters') if self[:name] != "#{self[:user]}/#{self[:table]}"
37+
if self[:user] and self[:table]
38+
fail('name must match user@host/table format') if self[:name] != "#{self[:user]}/#{self[:table]}"
39+
end
3840
end
3941

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

spec/acceptance/types/mysql_grant_spec.rb

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -109,25 +109,6 @@ class { 'mysql::server':
109109
end
110110
end
111111

112-
describe 'adding privileges with invalid name' do
113-
it 'should fail' do
114-
pp = <<-EOS
115-
mysql_user { 'test2@tester':
116-
ensure => present,
117-
}
118-
mysql_grant { 'test':
119-
ensure => 'present',
120-
table => 'test.*',
121-
user => 'test2@tester',
122-
privileges => ['SELECT', 'UPDATE'],
123-
require => Mysql_user['test2@tester'],
124-
}
125-
EOS
126-
127-
expect(apply_manifest(pp, :expect_failures => true).stderr).to match(/name must match user and table parameters/)
128-
end
129-
end
130-
131112
describe 'adding option' do
132113
it 'should work without errors' do
133114
pp = <<-EOS

spec/unit/puppet/type/mysql_grant_spec.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,12 @@
6767
end
6868

6969
it 'should require the name to match the user and table' do
70+
expect {
71+
Puppet::Type.type(:mysql_grant).new(:name => 'foo@localhost/*.*', :privileges => ['ALL'], :table => ['*.*'], :user => 'foo@localhost')
72+
}.to_not raise_error
7073
expect {
7174
Puppet::Type.type(:mysql_grant).new(:name => 'foo', :privileges => ['ALL'], :table => ['*.*'], :user => 'foo@localhost')
72-
}.to raise_error /name must match user and table parameters/
75+
}.to raise_error /name must match user@host\/table format/
7376
end
7477

7578
describe 'it should munge privileges' do

0 commit comments

Comments
 (0)