Skip to content

Require title of mysql_grant resource to match form user/table #522

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 5, 2014
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
1 change: 1 addition & 0 deletions lib/puppet/type/mysql_grant.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ def initialize(*args)
fail('privileges parameter is required.') if self[:ensure] == :present and self[:privileges].nil?
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]}"
end

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

describe 'adding privileges with invalid name' do
it 'should fail' do
pp = <<-EOS
mysql_grant { 'test':
ensure => 'present',
table => 'test.*',
user => 'test2@tester',
privileges => ['SELECT', 'UPDATE'],
}
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
8 changes: 7 additions & 1 deletion spec/unit/puppet/type/mysql_grant_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,10 @@
}.to raise_error(Puppet::Error, 'Title or name must be provided')
end

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

end