|
10 | 10 |
|
11 | 11 | # Check that the default privileges were revoked
|
12 | 12 | let(:check_command) do
|
13 |
| - "SELECT * FROM pg_default_acl a JOIN pg_namespace b ON a.defaclnamespace = b.oid WHERE '#{user}=arwdDxt' = ANY (defaclacl) AND nspname = 'public' and defaclobjtype = 'r';" |
| 13 | + "SELECT * FROM pg_default_acl a LEFT JOIN pg_namespace b ON a.defaclnamespace = b.oid WHERE '#{user}=arwdDxt' = ANY (defaclacl) AND nspname = 'public' and defaclobjtype = 'r';" |
14 | 14 | end
|
15 | 15 |
|
16 | 16 | let(:pp_one) do
|
@@ -167,6 +167,67 @@ class { 'postgresql::server': }
|
167 | 167 | MANIFEST
|
168 | 168 | end
|
169 | 169 |
|
| 170 | + let(:all_schemas_check_command) do |
| 171 | + "SELECT * FROM pg_default_acl a WHERE '#{user}=arwdDxt' = ANY (defaclacl) AND defaclnamespace = 0 and defaclobjtype = 'r';" |
| 172 | + end |
| 173 | + |
| 174 | + let(:pp_unset_schema) do |
| 175 | + <<-MANIFEST.unindent |
| 176 | + $db = #{db} |
| 177 | + $user = #{user} |
| 178 | + $group = #{group} |
| 179 | + $password = #{password} |
| 180 | +
|
| 181 | + class { 'postgresql::server': } |
| 182 | +
|
| 183 | + postgresql::server::role { $user: |
| 184 | + password_hash => postgresql::postgresql_password($user, $password), |
| 185 | + } |
| 186 | +
|
| 187 | + postgresql::server::database { $db: |
| 188 | + require => Postgresql::Server::Role[$user], |
| 189 | + } |
| 190 | +
|
| 191 | + # Set default privileges on tables |
| 192 | + postgresql::server::default_privileges { "alter default privileges grant all on tables to ${user}": |
| 193 | + db => $db, |
| 194 | + role => $user, |
| 195 | + privilege => 'ALL', |
| 196 | + object_type => 'TABLES', |
| 197 | + schema => '', |
| 198 | + require => Postgresql::Server::Database[$db], |
| 199 | + } |
| 200 | + MANIFEST |
| 201 | + end |
| 202 | + let(:pp_unset_schema_revoke) do |
| 203 | + <<-MANIFEST |
| 204 | + $db = #{db} |
| 205 | + $user = #{user} |
| 206 | + $group = #{group} |
| 207 | + $password = #{password} |
| 208 | +
|
| 209 | + class { 'postgresql::server': } |
| 210 | +
|
| 211 | + postgresql::server::role { $user: |
| 212 | + password_hash => postgresql::postgresql_password($user, $password), |
| 213 | + } |
| 214 | + postgresql::server::database { $db: |
| 215 | + require => Postgresql::Server::Role[$user], |
| 216 | + } |
| 217 | +
|
| 218 | + # Removes default privileges on tables |
| 219 | + postgresql::server::default_privileges { "alter default privileges revoke all on tables for ${user}": |
| 220 | + db => $db, |
| 221 | + role => $user, |
| 222 | + privilege => 'ALL', |
| 223 | + object_type => 'TABLES', |
| 224 | + schema => '', |
| 225 | + ensure => 'absent', |
| 226 | + require => Postgresql::Server::Database[$db], |
| 227 | + } |
| 228 | + MANIFEST |
| 229 | + end |
| 230 | + |
170 | 231 | it 'grants default privileges to an user' do
|
171 | 232 | if Gem::Version.new(postgresql_version) >= Gem::Version.new('9.6')
|
172 | 233 | idempotent_apply(pp_one)
|
@@ -212,4 +273,27 @@ class { 'postgresql::server': }
|
212 | 273 | end
|
213 | 274 | end
|
214 | 275 | end
|
| 276 | + |
| 277 | + it 'grants default privileges on all schemas to a user' do |
| 278 | + if Gem::Version.new(postgresql_version) >= Gem::Version.new('9.6') |
| 279 | + idempotent_apply(pp_unset_schema) |
| 280 | + |
| 281 | + psql("--command=\"SET client_min_messages = 'error';#{all_schemas_check_command}\" --db=#{db}") do |r| |
| 282 | + expect(r.stdout).to match(%r{\(1 row\)}) |
| 283 | + expect(r.stderr).to eq('') |
| 284 | + end |
| 285 | + end |
| 286 | + end |
| 287 | + |
| 288 | + it 'revokes default privileges on all schemas for a user' do |
| 289 | + if Gem::Version.new(postgresql_version) >= Gem::Version.new('9.6') |
| 290 | + apply_manifest(pp_unset_schema, catch_failures: true) |
| 291 | + apply_manifest(pp_unset_schema_revoke, expect_changes: true) |
| 292 | + |
| 293 | + psql("--command=\"SET client_min_messages = 'error';#{all_schemas_check_command}\" --db=#{db}") do |r| |
| 294 | + expect(r.stdout).to match(%r{\(0 rows\)}) |
| 295 | + expect(r.stderr).to eq('') |
| 296 | + end |
| 297 | + end |
| 298 | + end |
215 | 299 | end
|
0 commit comments