wuiet.d.o no longer needs access to projectb on bmdb1
[mirror/dsa-puppet.git] / 3rdparty / modules / postgresql / spec / acceptance / postgresql_psql_spec.rb
1 require 'spec_helper_acceptance'
2
3 describe 'postgresql_psql', :unless => UNSUPPORTED_PLATFORMS.include?(fact('osfamily')) do
4
5   it 'should always run SQL' do
6     pp = <<-EOS
7       class { 'postgresql::server': } ->
8       postgresql_psql { 'foobar':
9         db        => 'postgres',
10         psql_user => 'postgres',
11         command   => 'select 1',
12       }
13     EOS
14
15     apply_manifest(pp, :catch_failures => true)
16     apply_manifest(pp, :expect_changes => true)
17   end
18
19   it 'should run some SQL when the unless query returns no rows' do
20     pp = <<-EOS
21       class { 'postgresql::server': } ->
22       postgresql_psql { 'foobar':
23         db        => 'postgres',
24         psql_user => 'postgres',
25         command   => 'select 1',
26         unless    => 'select 1 where 1=2',
27       }
28     EOS
29
30     apply_manifest(pp, :catch_failures => true)
31     apply_manifest(pp, :expect_changes  => true)
32   end
33
34   it 'should not run SQL when the unless query returns rows' do
35     pp = <<-EOS
36       class { 'postgresql::server': } ->
37       postgresql_psql { 'foobar':
38         db        => 'postgres',
39         psql_user => 'postgres',
40         command   => 'select * from pg_database limit 1',
41         unless    => 'select 1 where 1=1',
42       }
43     EOS
44
45     apply_manifest(pp, :catch_failures => true)
46     apply_manifest(pp, :catch_changes => true)
47   end
48
49   it 'should not run SQL when refreshed and the unless query returns rows' do
50     pp = <<-EOS
51       class { 'postgresql::server': } ->
52       notify { 'trigger': } ~>
53       postgresql_psql { 'foobar':
54         db        => 'postgres',
55         psql_user => 'postgres',
56         command   => 'invalid sql statement',
57         unless    => 'select 1 where 1=1',
58       }
59     EOS
60
61     apply_manifest(pp, :catch_failures => true)
62     apply_manifest(pp, :expect_changes => true)
63   end
64
65   context 'with refreshonly' do
66     it 'should not run SQL when the unless query returns no rows' do
67       pp = <<-EOS
68         class { 'postgresql::server': } ->
69         postgresql_psql { 'foobar':
70           db          => 'postgres',
71           psql_user   => 'postgres',
72           command     => 'select 1',
73           unless      => 'select 1 where 1=2',
74           refreshonly => true,
75         }
76       EOS
77
78       apply_manifest(pp, :catch_failures => true)
79       apply_manifest(pp, :catch_changes  => true)
80     end
81
82     it 'should run SQL when refreshed and the unless query returns no rows' do
83       pp = <<-EOS.unindent
84         class { 'postgresql::server': } ->
85         notify { 'trigger': } ~>
86         postgresql_psql { 'foobar':
87           db          => 'postgres',
88           psql_user   => 'postgres',
89           command     => 'select 1',
90           unless      => 'select 1 where 1=2',
91           refreshonly => true,
92         }
93       EOS
94
95       apply_manifest(pp, :catch_failures => true)
96       apply_manifest(pp, :expect_changes => true)
97     end
98
99     it 'should not run SQL when refreshed and the unless query returns rows' do
100       pp = <<-EOS.unindent
101         class { 'postgresql::server': } ->
102         notify { 'trigger': } ~>
103         postgresql_psql { 'foobar':
104           db          => 'postgres',
105           psql_user   => 'postgres',
106           command     => 'invalid sql query',
107           unless      => 'select 1 where 1=1',
108           refreshonly => true,
109         }
110       EOS
111
112       apply_manifest(pp, :catch_failures => true)
113       apply_manifest(pp, :expect_changes => true)
114     end
115   end
116
117   it 'should not run some SQL when the onlyif query returns no rows' do
118     pp = <<-EOS
119       class { 'postgresql::server': } ->
120       postgresql_psql { 'foobar':
121         db        => 'postgres',
122         psql_user => 'postgres',
123         command   => 'select 1',
124         onlyif    => 'select 1 where 1=2',
125       }
126     EOS
127
128     apply_manifest(pp, :catch_failures => true)
129     apply_manifest(pp, :catch_changes  => true)
130   end
131
132   it 'should run SQL when the onlyif query returns rows' do
133     pp = <<-EOS
134       class { 'postgresql::server': } ->
135       postgresql_psql { 'foobar':
136         db        => 'postgres',
137         psql_user => 'postgres',
138         command   => 'select * from pg_database limit 1',
139         onlyif    => 'select 1 where 1=1',
140       }
141     EOS
142
143     apply_manifest(pp, :catch_failures => true)
144     apply_manifest(pp, :expect_changes => true)
145   end
146
147   context 'with secure password passing by environment' do
148     it 'should run SQL that contanins password passed by environment' do
149       select = "select \\'$PASS_TO_EMBED\\'"
150       pp = <<-EOS.unindent
151         class { 'postgresql::server': } ->
152         postgresql_psql { 'password embedded by environment: #{select}':
153           db          => 'postgres',
154           psql_user   => 'postgres',
155           command     => '#{select}',
156           environment => [
157             'PASS_TO_EMBED=pa$swD',
158           ],
159         }
160       EOS
161       apply_manifest(pp, :catch_failures => true)
162       apply_manifest(pp, :expect_changes => false)
163     end
164     it 'should run SQL that contanins password passed by environment in check' do
165       select = "select 1 where \\'$PASS_TO_EMBED\\'=\\'passwD\\'"
166       pp = <<-EOS.unindent
167         class { 'postgresql::server': } ->
168         postgresql_psql { 'password embedded by environment in check: #{select}':
169           db          => 'postgres',
170           psql_user   => 'postgres',
171           command     => 'invalid sql query',
172           unless      => '#{select}',
173           environment => [
174             'PASS_TO_EMBED=passwD',
175           ],
176         }
177       EOS
178
179       apply_manifest(pp, :catch_failures => true)
180       apply_manifest(pp, :expect_changes => false)
181     end
182   end
183 end