Skip to content

Commit d47d30d

Browse files
author
George Hansper
committed
check that role exists for REVOKE role ON DATABASE db
1 parent 92f4842 commit d47d30d

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

manifests/server/grant.pp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,10 @@
9090
'^ALL$','^ALL PRIVILEGES$' ])
9191
$unless_function = 'has_database_privilege'
9292
$on_db = $psql_db
93-
$onlyif_function = undef
93+
$onlyif_function = $ensure ? {
94+
default => undef,
95+
'absent' => 'role_exists',
96+
}
9497
}
9598
'SCHEMA': {
9699
$unless_privilege = $_privilege ? {
@@ -339,6 +342,7 @@
339342
$_onlyif = $onlyif_function ? {
340343
'table_exists' => "SELECT true FROM pg_tables WHERE tablename = '${_togrant_object}'",
341344
'language_exists' => "SELECT true from pg_language WHERE lanname = '${_togrant_object}'",
345+
'role_exists' => "SELECT 1 FROM pg_roles WHERE rolname = '${role}'",
342346
default => undef,
343347
}
344348

spec/acceptance/server/grant_spec.rb

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -496,5 +496,26 @@ class { 'postgresql::server': }
496496
end
497497
end
498498
end
499+
context 'database' do
500+
describe 'REVOKE ... ON DATABASE...' do
501+
it 'should not fail on revoke connect from non-existant user' do
502+
begin
503+
apply_manifest(pp_setup, :catch_failures => true)
504+
pp = pp_setup + <<-EOS.unindent
505+
postgresql::server::grant { 'revoke connect on db from norole':
506+
ensure => absent,
507+
privilege => 'CONNECT',
508+
object_type => 'DATABASE',
509+
db => '#{db}',
510+
role => '#{user}_does_not_exist',
511+
}
512+
EOS
513+
apply_manifest(pp, :catch_changes => true)
514+
apply_manifest(pp, :catch_failures => true)
515+
516+
end
517+
end
518+
end
519+
end
499520
#####################
500521
end

0 commit comments

Comments
 (0)