newer pg module
[mirror/dsa-puppet.git] / 3rdparty / modules / postgresql / spec / unit / defines / server / pg_hba_rule_spec.rb
1 require 'spec_helper'
2
3 describe 'postgresql::server::pg_hba_rule', :type => :define do
4   let :facts do
5     {
6       :osfamily => 'Debian',
7       :operatingsystem => 'Debian',
8       :operatingsystemrelease => '6.0',
9       :kernel => 'Linux',
10       :concat_basedir => tmpfilename('pg_hba'),
11       :id => 'root',
12       :path => '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin',
13     }
14   end
15   let :title do
16     'test'
17   end
18   let :target do
19     tmpfilename('pg_hba_rule')
20   end
21
22   context 'test template 1' do
23     let :pre_condition do
24       <<-EOS
25         class { 'postgresql::server': }
26       EOS
27     end
28
29     let :params do
30       {
31         :type => 'host',
32         :database => 'all',
33         :user => 'all',
34         :address => '1.1.1.1/24',
35         :auth_method => 'md5',
36         :target => target,
37       }
38     end
39     it do
40       is_expected.to contain_concat__fragment('pg_hba_rule_test').with({
41         :content => /host\s+all\s+all\s+1\.1\.1\.1\/24\s+md5/
42       })
43     end
44   end
45
46   context 'test template 2' do
47     let :pre_condition do
48       <<-EOS
49         class { 'postgresql::server': }
50       EOS
51     end
52
53     let :params do
54       {
55         :type => 'local',
56         :database => 'all',
57         :user => 'all',
58         :auth_method => 'ident',
59         :target => target,
60       }
61     end
62     it do
63       is_expected.to contain_concat__fragment('pg_hba_rule_test').with({
64         :content => /local\s+all\s+all\s+ident/
65       })
66     end
67   end
68
69   context 'test template 3' do
70     let :pre_condition do
71       <<-EOS
72         class { 'postgresql::server': }
73       EOS
74     end
75
76     let :params do
77       {
78         :type => 'host',
79         :database => 'all',
80         :user => 'all',
81         :address => '0.0.0.0/0',
82         :auth_method => 'ldap',
83         :auth_option => 'foo=bar',
84         :target => target,
85       }
86     end
87     it do
88       is_expected.to contain_concat__fragment('pg_hba_rule_test').with({
89         :content => /host\s+all\s+all\s+0\.0\.0\.0\/0\s+ldap\s+foo=bar/
90       })
91     end
92   end
93
94   context 'validation' do
95     context 'validate supported auth_method' do
96       let :pre_condition do
97         <<-EOS
98           class { 'postgresql::globals':
99             version => '9.2',
100           }
101           class { 'postgresql::server': }
102         EOS
103       end
104
105       let :params do
106         {
107           :type => 'local',
108           :database => 'all',
109           :user => 'all',
110           :address => '0.0.0.0/0',
111           :auth_method => 'peer',
112           :target => target,
113         }
114       end
115
116       it do
117         is_expected.to contain_concat__fragment('pg_hba_rule_test').with(
118           {
119            :content => /local\s+all\s+all\s+0\.0\.0\.0\/0\s+peer/
120           }
121         )
122       end
123     end
124
125   end
126 end