Skip to content

Commit 29cef3f

Browse files
author
Branan Purvine-Riley
committed
Add initial spec for mysql grant provider
1 parent d0a5b1c commit 29cef3f

File tree

1 file changed

+74
-0
lines changed

1 file changed

+74
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
require 'puppet'
2+
require 'mocha'
3+
RSpec.configure do |config|
4+
config.mock_with :mocha
5+
end
6+
provider_class = Puppet::Type.type(:database_grant).provider(:mysql)
7+
describe provider_class do
8+
before :each do
9+
@resource = Puppet::Type::Database_grant.new(
10+
{ :privileges => 'all"', :provider => 'mysql', :name => 'user@host'}
11+
)
12+
@provider = provider_class.new(@resource)
13+
end
14+
it 'should query privilegess from the database' do
15+
provider_class.expects(:mysql) .with('mysql', '-Be', 'describe user').returns <<-EOT
16+
Field Type Null Key Default Extra
17+
Host char(60) NO PRI
18+
User char(16) NO PRI
19+
Password char(41) NO
20+
Select_priv enum('N','Y') NO N
21+
Insert_priv enum('N','Y') NO N
22+
Update_priv enum('N','Y') NO N
23+
EOT
24+
provider_class.expects(:mysql).with('mysql', '-Be', 'describe db').returns <<-EOT
25+
Field Type Null Key Default Extra
26+
Host char(60) NO PRI
27+
Db char(64) NO PRI
28+
User char(16) NO PRI
29+
Select_priv enum('N','Y') NO N
30+
Insert_priv enum('N','Y') NO N
31+
Update_priv enum('N','Y') NO N
32+
EOT
33+
provider_class.user_privs.should == [ :Select_priv, :Insert_priv, :Update_priv ]
34+
provider_class.db_privs.should == [ :Select_priv, :Insert_priv, :Update_priv ]
35+
end
36+
37+
it 'should query set priviliges' do
38+
provider_class.expects(:mysql).with('mysql', '-Be', 'select * from user where user="user" and host="host"').returns <<-EOT
39+
Host User Password Select_priv Insert_priv Update_priv
40+
host user Y N Y
41+
EOT
42+
@provider.privileges.should == [ :Select_priv, :Update_priv ]
43+
end
44+
45+
it 'should recognize when all priviliges are set' do
46+
provider_class.expects(:mysql).with('mysql', '-Be', 'select * from user where user="user" and host="host"').returns <<-EOT
47+
Host User Password Select_priv Insert_priv Update_priv
48+
host user Y Y Y
49+
EOT
50+
@provider.all_privs_set?.should == true
51+
end
52+
53+
it 'should recognize when all privileges are not set' do
54+
provider_class.expects(:mysql).with('mysql', '-Be', 'select * from user where user="user" and host="host"').returns <<-EOT
55+
Host User Password Select_priv Insert_priv Update_priv
56+
host user Y N Y
57+
EOT
58+
@provider.all_privs_set?.should == false
59+
end
60+
61+
it 'should be able to set all privileges' do
62+
provider_class.expects(:mysql).with('mysql', '-NBe', 'SELECT "1" FROM user WHERE user = \'user\' AND host = \'host\'').returns "1\n"
63+
provider_class.expects(:mysql).with('mysql', '-Be', "update user set Select_priv = 'Y', Insert_priv = 'Y', Update_priv = 'Y' where user=\"user\" and host=\"host\"")
64+
provider_class.expects(:mysqladmin).with("flush-privileges")
65+
@provider.privileges=([:all])
66+
end
67+
68+
it 'should be able to set partial privileges' do
69+
provider_class.expects(:mysql).with('mysql', '-NBe', 'SELECT "1" FROM user WHERE user = \'user\' AND host = \'host\'').returns "1\n"
70+
provider_class.expects(:mysql).with('mysql', '-Be', "update user set Select_priv = 'Y', Insert_priv = 'N', Update_priv = 'Y' where user=\"user\" and host=\"host\"")
71+
provider_class.expects(:mysqladmin).with("flush-privileges")
72+
@provider.privileges=([:Select_priv, :Update_priv])
73+
end
74+
end

0 commit comments

Comments
 (0)