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