Skip to content

(MODULES-4604) move name validation in mysql_grant type #961

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 1 commit into from
Jun 27, 2017
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
4 changes: 3 additions & 1 deletion lib/puppet/type/mysql_grant.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ def initialize(*args)
fail('PROXY must be the only privilege specified.') if Array(self[:privileges]).count > 1 and Array(self[:privileges]).include?('PROXY')
fail('table parameter is required.') if self[:ensure] == :present and self[:table].nil?
fail('user parameter is required.') if self[:ensure] == :present and self[:user].nil?
fail('name must match user and table parameters') if self[:name] != "#{self[:user]}/#{self[:table]}"
if self[:user] and self[:table]
fail('name must match user@host/table format') if self[:name] != "#{self[:user]}/#{self[:table]}"
end
end

newparam(:name, :namevar => true) do
Expand Down
19 changes: 0 additions & 19 deletions spec/acceptance/types/mysql_grant_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -109,25 +109,6 @@ class { 'mysql::server':
end
end

describe 'adding privileges with invalid name' do
it 'should fail' do
pp = <<-EOS
mysql_user { 'test2@tester':
ensure => present,
}
mysql_grant { 'test':
ensure => 'present',
table => 'test.*',
user => 'test2@tester',
privileges => ['SELECT', 'UPDATE'],
require => Mysql_user['test2@tester'],
}
EOS

expect(apply_manifest(pp, :expect_failures => true).stderr).to match(/name must match user and table parameters/)
end
end

describe 'adding option' do
it 'should work without errors' do
pp = <<-EOS
Expand Down
5 changes: 4 additions & 1 deletion spec/unit/puppet/type/mysql_grant_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,12 @@
end

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

describe 'it should munge privileges' do
Expand Down