diff --git a/lib/puppet/type/mysql_grant.rb b/lib/puppet/type/mysql_grant.rb index abaa33208..cc765bcb5 100644 --- a/lib/puppet/type/mysql_grant.rb +++ b/lib/puppet/type/mysql_grant.rb @@ -39,9 +39,12 @@ def initialize(*args) raise(_('mysql_grant: `privileges` `parameter`: PROXY can only be specified by itself.')) if Array(self[:privileges]).size > 1 && Array(self[:privileges]).include?('PROXY') raise(_('mysql_grant: `table` `parameter` is required.')) if self[:ensure] == :present && self[:table].nil? raise(_('mysql_grant: `user` `parameter` is required.')) if self[:ensure] == :present && self[:user].nil? - if self[:user] && self[:table] + if self[:user] && self[:table] && self[:tag].nil? raise(_('mysql_grant: `name` `parameter` must match user@host/table format.')) if self[:name] != "#{self[:user]}/#{self[:table]}" end + if self[:user] && self[:table] && self[:tag] + raise(_('mysql_grant: `name` `parameter` must match tag:user@host/table format.')) if self[:name] != "#{self[:user]}/#{self[:table]}" && self[:name] != "#{self[:tag][0]}:#{self[:user]}/#{self[:table]}" + end end newparam(:name, namevar: true) do diff --git a/spec/unit/puppet/type/mysql_grant_spec.rb b/spec/unit/puppet/type/mysql_grant_spec.rb index c90d66081..85a5f1cec 100644 --- a/spec/unit/puppet/type/mysql_grant_spec.rb +++ b/spec/unit/puppet/type/mysql_grant_spec.rb @@ -76,6 +76,23 @@ }.to raise_error %r{mysql_grant: `name` `parameter` must match user@host\/table format} end + it 'requires the name to match the user and table with tag #general' do + expect { + Puppet::Type.type(:mysql_grant).new(name: 'foo@localhost/*.*', privileges: ['ALL'], table: ['*.*'], user: 'foo@localhost', tag: 'bar') + }.not_to raise_error + end + + it 'requires the name to match the user and table with tag, also in name #general' do + expect { + Puppet::Type.type(:mysql_grant).new(name: 'bar:foo@localhost/*.*', privileges: ['ALL'], table: ['*.*'], user: 'foo@localhost', tag: 'bar') + }.not_to raise_error + end + it 'requires the name to match the user and table with tag #specific' do + expect { + Puppet::Type.type(:mysql_grant).new(name: 'foo', privileges: ['ALL'], table: ['*.*'], user: 'foo@localhost', tag: 'bar') + }.to raise_error %r{mysql_grant: `name` `parameter` must match tag:user@host\/table format} + end + describe 'it should munge privileges' do it 'to just ALL' do user = Puppet::Type.type(:mysql_grant).new(