Skip to content
This repository has been archived by the owner on Dec 2, 2020. It is now read-only.

Commit

Permalink
Merge pull request #40 from simpsora/broken_grant_check
Browse files Browse the repository at this point in the history
Fix grants to work with wildcard hosts
  • Loading branch information
dgoodlad committed Jul 30, 2014
2 parents 961dfb9 + 6ee4778 commit 9f462c6
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
2 changes: 1 addition & 1 deletion manifests/user/grant.pp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
-e \"grant ${grants} on ${database}.* to '${username}'@'${host}'; \
flush privileges;\"",
require => Exec['wait-for-mysql'],
unless => "mysql -uroot -p13306 -e 'SHOW GRANTS FOR ${username}@${host};' \
unless => "mysql -uroot -p13306 -e 'SHOW GRANTS FOR ${username}@'${host}';' \
--password='' | grep -w '${database}' | grep -w '${grants}'"
}
} elsif $ensure == 'absent' {
Expand Down
21 changes: 21 additions & 0 deletions spec/defines/user_grant_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
let(:title) { 'name' }
let(:user) { 'user' }
let(:database) { 'database' }
let(:host) { '%' }
let(:grants) { 'ALL' }

context "when ensure is present" do
let(:params) do
Expand All @@ -26,6 +28,25 @@
end
end

context "when setting the host" do
let(:params) do
{ :username => user,
:database => database,
:host => host }
end

it "properly quotes the host" do
should contain_exec("granting #{user} access to #{database}").
with(
:command => "mysql -uroot -p13306 --password='' \
-e \"grant ALL on #{database}.* to '#{user}'@'#{host}'; \
flush privileges;\"",
:unless => "mysql -uroot -p13306 -e 'SHOW GRANTS FOR #{user}@'#{host}';' \
--password='' | grep -w '#{database}' | grep -w '#{grants}'"
)
end
end


context "when ensure is absent" do
let(:params) do
Expand Down

0 comments on commit 9f462c6

Please sign in to comment.