newer pg module
[mirror/dsa-puppet.git] / 3rdparty / modules / postgresql / spec / unit / defines / server / role_spec.rb
1 require 'spec_helper'
2
3 describe 'postgresql::server::role', :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('contrib'),
11       :id => 'root',
12       :path => '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin',
13     }
14   end
15
16   let :title do
17     'test'
18   end
19
20   let :params do
21     {
22       :password_hash => 'new-pa$s',
23     }
24   end
25
26   let :pre_condition do
27    "class {'postgresql::server':}"
28   end
29
30   it { is_expected.to contain_postgresql__server__role('test') }
31   it 'should have create role for "test" user with password as ****' do
32     is_expected.to contain_postgresql_psql('CREATE ROLE test ENCRYPTED PASSWORD ****').with({
33       'command'     => "CREATE ROLE \"test\" ENCRYPTED PASSWORD '$NEWPGPASSWD' LOGIN NOCREATEROLE NOCREATEDB NOSUPERUSER  CONNECTION LIMIT -1",
34       'environment' => "NEWPGPASSWD=new-pa$s",
35       'unless'      => "SELECT 1 FROM pg_roles WHERE rolname = 'test'",
36       'port'        => "5432",
37     })
38   end
39   it 'should have alter role for "test" user with password as ****' do
40     is_expected.to contain_postgresql_psql('ALTER ROLE test ENCRYPTED PASSWORD ****').with({
41       'command'     => "ALTER ROLE \"test\" ENCRYPTED PASSWORD '$NEWPGPASSWD'",
42       'environment' => "NEWPGPASSWD=new-pa$s",
43       'unless'      => "SELECT 1 FROM pg_shadow WHERE usename = 'test' AND passwd = 'md5b6f7fcbbabb4befde4588a26c1cfd2fa'",
44       'port'        => "5432",
45     })
46   end
47
48   context "with specific db connection settings - default port" do
49     let :params do
50       {
51         :password_hash => 'new-pa$s',
52         :connect_settings => { 'PGHOST'     => 'postgres-db-server',
53                                'DBVERSION'  => '9.1',
54                                'PGUSER'     => 'login-user',
55                                'PGPASSWORD' => 'login-pass' },
56       }
57     end
58
59     let :pre_condition do
60      "class {'postgresql::server':}"
61     end
62
63     it { is_expected.to contain_postgresql__server__role('test') }
64     it 'should have create role for "test" user with password as ****' do
65       is_expected.to contain_postgresql_psql('CREATE ROLE test ENCRYPTED PASSWORD ****').with({
66         'command'     => "CREATE ROLE \"test\" ENCRYPTED PASSWORD '$NEWPGPASSWD' LOGIN NOCREATEROLE NOCREATEDB NOSUPERUSER  CONNECTION LIMIT -1",
67         'environment' => "NEWPGPASSWD=new-pa$s",
68         'unless'      => "SELECT 1 FROM pg_roles WHERE rolname = 'test'",
69         'port'        => "5432",
70
71         'connect_settings' => { 'PGHOST'     => 'postgres-db-server',
72                                 'DBVERSION'  => '9.1',
73                                 'PGUSER'     => 'login-user',
74                                 'PGPASSWORD' => 'login-pass' },
75       })
76     end
77     it 'should have alter role for "test" user with password as ****' do
78       is_expected.to contain_postgresql_psql('ALTER ROLE test ENCRYPTED PASSWORD ****').with({
79         'command'     => "ALTER ROLE \"test\" ENCRYPTED PASSWORD '$NEWPGPASSWD'",
80         'environment' => "NEWPGPASSWD=new-pa$s",
81         'unless'      => "SELECT 1 FROM pg_shadow WHERE usename = 'test' AND passwd = 'md5b6f7fcbbabb4befde4588a26c1cfd2fa'",
82         'port'        => "5432",
83
84         'connect_settings' => { 'PGHOST'     => 'postgres-db-server',
85                                 'DBVERSION'  => '9.1',
86                                 'PGUSER'     => 'login-user',
87                                 'PGPASSWORD' => 'login-pass' },
88       })
89     end
90   end
91
92   context "with specific db connection settings - including port" do
93     let :params do
94       {
95         :password_hash => 'new-pa$s',
96         :connect_settings => { 'PGHOST'     => 'postgres-db-server',
97                                'DBVERSION'  => '9.1',
98                                'PGPORT'     => '1234',
99                                'PGUSER'     => 'login-user',
100                                'PGPASSWORD' => 'login-pass' },
101       }
102     end
103
104     let :pre_condition do
105      "class {'postgresql::server':}"
106     end
107
108     it { is_expected.to contain_postgresql__server__role('test') }
109     it 'should have create role for "test" user with password as ****' do
110       is_expected.to contain_postgresql_psql('CREATE ROLE test ENCRYPTED PASSWORD ****').with({
111         'command'     => "CREATE ROLE \"test\" ENCRYPTED PASSWORD '$NEWPGPASSWD' LOGIN NOCREATEROLE NOCREATEDB NOSUPERUSER  CONNECTION LIMIT -1",
112         'environment' => "NEWPGPASSWD=new-pa$s",
113         'unless'      => "SELECT 1 FROM pg_roles WHERE rolname = 'test'",
114         'connect_settings' => { 'PGHOST'     => 'postgres-db-server',
115                                 'DBVERSION'  => '9.1',
116                                 'PGPORT'     => '1234',
117                                 'PGUSER'     => 'login-user',
118                                 'PGPASSWORD' => 'login-pass' },
119       })
120     end
121     it 'should have alter role for "test" user with password as ****' do
122       is_expected.to contain_postgresql_psql('ALTER ROLE test ENCRYPTED PASSWORD ****').with({
123         'command'     => "ALTER ROLE \"test\" ENCRYPTED PASSWORD '$NEWPGPASSWD'",
124         'environment' => "NEWPGPASSWD=new-pa$s",
125         'unless'      => "SELECT 1 FROM pg_shadow WHERE usename = 'test' AND passwd = 'md5b6f7fcbbabb4befde4588a26c1cfd2fa'",
126         'connect_settings' => { 'PGHOST'     => 'postgres-db-server',
127                                 'DBVERSION'  => '9.1',
128                                 'PGPORT'     => '1234',
129                                 'PGUSER'     => 'login-user',
130                                 'PGPASSWORD' => 'login-pass' },
131       })
132     end
133   end
134
135   context 'with update_password set to false' do
136     let :params do
137       {
138           :password_hash => 'new-pa$s',
139           :update_password => false,
140       }
141     end
142
143     let :pre_condition do
144       "class {'postgresql::server':}"
145     end
146
147     it 'should not have alter role for "test" user with password as **** if update_password is false' do
148       is_expected.not_to contain_postgresql_psql('ALTER ROLE test ENCRYPTED PASSWORD ****')
149     end
150   end
151
152 end