|
1 | 1 | require 'puppet'
|
2 | 2 | require 'mocha'
|
| 3 | +require 'spec_helper' |
3 | 4 | RSpec.configure do |config|
|
4 | 5 | config.mock_with :mocha
|
5 | 6 | end
|
6 | 7 | provider_class = Puppet::Type.type(:database_grant).provider(:mysql)
|
7 | 8 | describe provider_class do
|
| 9 | + let(:root_home) { '/some/root/home' } |
| 10 | + |
8 | 11 | before :each do
|
9 | 12 | @resource = Puppet::Type::Database_grant.new(
|
10 | 13 | { :privileges => 'all', :provider => 'mysql', :name => 'user@host'}
|
11 | 14 | )
|
12 | 15 | @provider = provider_class.new(@resource)
|
| 16 | + Facter.stubs(:value).with(:root_home).returns(root_home) |
13 | 17 | end
|
| 18 | + |
14 | 19 | it 'should query privilegess from the database' do
|
15 |
| - provider_class.expects(:mysql) .with('mysql', '-Be', 'describe user').returns <<-EOT |
| 20 | + provider_class.expects(:mysql) .with("--defaults-file=#{root_home}/.my.cnf", 'mysql', '-Be', 'describe user').returns <<-EOT |
16 | 21 | Field Type Null Key Default Extra
|
17 | 22 | Host char(60) NO PRI
|
18 | 23 | User char(16) NO PRI
|
|
21 | 26 | Insert_priv enum('N','Y') NO N
|
22 | 27 | Update_priv enum('N','Y') NO N
|
23 | 28 | EOT
|
24 |
| - provider_class.expects(:mysql).with('mysql', '-Be', 'describe db').returns <<-EOT |
| 29 | + provider_class.expects(:mysql).with("--defaults-file=#{root_home}/.my.cnf", 'mysql', '-Be', 'describe db').returns <<-EOT |
25 | 30 | Field Type Null Key Default Extra
|
26 | 31 | Host char(60) NO PRI
|
27 | 32 | Db char(64) NO PRI
|
|
35 | 40 | end
|
36 | 41 |
|
37 | 42 | 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 |
| 43 | + provider_class.expects(:mysql).with("--defaults-file=#{root_home}/.my.cnf", 'mysql', '-Be', 'select * from mysql.user where user="user" and host="host"').returns <<-EOT |
39 | 44 | Host User Password Select_priv Insert_priv Update_priv
|
40 | 45 | host user Y N Y
|
41 | 46 | EOT
|
42 | 47 | @provider.privileges.should == [ 'Select_priv', 'Update_priv' ]
|
43 | 48 | end
|
44 | 49 |
|
45 | 50 | 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 |
| 51 | + provider_class.expects(:mysql).with("--defaults-file=#{root_home}/.my.cnf", 'mysql', '-Be', 'select * from mysql.user where user="user" and host="host"').returns <<-EOT |
47 | 52 | Host User Password Select_priv Insert_priv Update_priv
|
48 | 53 | host user Y Y Y
|
49 | 54 | EOT
|
50 | 55 | @provider.all_privs_set?.should == true
|
51 | 56 | end
|
52 | 57 |
|
53 | 58 | 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 |
| 59 | + provider_class.expects(:mysql).with("--defaults-file=#{root_home}/.my.cnf", 'mysql', '-Be', 'select * from mysql.user where user="user" and host="host"').returns <<-EOT |
55 | 60 | Host User Password Select_priv Insert_priv Update_priv
|
56 | 61 | host user Y N Y
|
57 | 62 | EOT
|
58 | 63 | @provider.all_privs_set?.should == false
|
59 | 64 | end
|
60 | 65 |
|
61 | 66 | 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") |
| 67 | + provider_class.expects(:mysql).with("--defaults-file=#{root_home}/.my.cnf", 'mysql', '-NBe', 'SELECT "1" FROM user WHERE user="user" AND host="host"').returns "1\n" |
| 68 | + provider_class.expects(:mysql).with("--defaults-file=#{root_home}/.my.cnf", 'mysql', '-Be', "update user set Select_priv = 'Y', Insert_priv = 'Y', Update_priv = 'Y' where user=\"user\" and host=\"host\"") |
| 69 | + provider_class.expects(:mysqladmin).with("--defaults-file=#{root_home}/.my.cnf", "flush-privileges") |
65 | 70 | @provider.privileges=(['all'])
|
66 | 71 | end
|
67 | 72 |
|
68 | 73 | 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") |
| 74 | + provider_class.expects(:mysql).with("--defaults-file=#{root_home}/.my.cnf", 'mysql', '-NBe', 'SELECT "1" FROM user WHERE user="user" AND host="host"').returns "1\n" |
| 75 | + provider_class.expects(:mysql).with("--defaults-file=#{root_home}/.my.cnf", 'mysql', '-Be', "update user set Select_priv = 'Y', Insert_priv = 'N', Update_priv = 'Y' where user=\"user\" and host=\"host\"") |
| 76 | + provider_class.expects(:mysqladmin).with("--defaults-file=#{root_home}/.my.cnf", "flush-privileges") |
72 | 77 | @provider.privileges=(['Select_priv', 'Update_priv'])
|
73 | 78 | end
|
74 | 79 |
|
75 | 80 | it 'should be case insensitive' do
|
76 |
| - provider_class.expects(:mysql).with('mysql', '-NBe', 'SELECT "1" FROM user WHERE user = \'user\' AND host = \'host\'').returns "1\n" |
77 |
| - 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\"") |
78 |
| - provider_class.expects(:mysqladmin).with('flush-privileges') |
| 81 | + provider_class.expects(:mysql).with("--defaults-file=#{root_home}/.my.cnf", 'mysql', '-NBe', 'SELECT "1" FROM user WHERE user="user" AND host="host"').returns "1\n" |
| 82 | + provider_class.expects(:mysql).with("--defaults-file=#{root_home}/.my.cnf", 'mysql', '-Be', "update user set Select_priv = 'Y', Insert_priv = 'Y', Update_priv = 'Y' where user=\"user\" and host=\"host\"") |
| 83 | + provider_class.expects(:mysqladmin).with("--defaults-file=#{root_home}/.my.cnf", 'flush-privileges') |
79 | 84 | @provider.privileges=(['SELECT_PRIV', 'insert_priv', 'UpDaTe_pRiV'])
|
80 | 85 | end
|
81 | 86 | end
|
0 commit comments