From fdbd89aab89e2aa987528b4b901b4f78278453a9 Mon Sep 17 00:00:00 2001 From: David Swan Date: Tue, 6 Mar 2018 14:30:59 +0000 Subject: [PATCH] grant_spec.rb fix --- README.md | 2 +- spec/acceptance/server/grant_spec.rb | 31 +++++++++++++++++----------- 2 files changed, 20 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index d27dc52a80..d83137aebf 100644 --- a/README.md +++ b/README.md @@ -1154,7 +1154,7 @@ Manages grant-based access privileges for users, wrapping the `postgresql::serve ##### `ensure` -Specifies whether to grant or revoke the privilege. Default is to grant the privilege. +Specifies whether to grant or revoke the privilege. Revoke or 'absent' works only in PostgreSQL version 9.1.24 or later. Valid values: 'present', 'absent'. * 'present' to grant the privilege diff --git a/spec/acceptance/server/grant_spec.rb b/spec/acceptance/server/grant_spec.rb index e4a3231775..c53d5ff685 100644 --- a/spec/acceptance/server/grant_spec.rb +++ b/spec/acceptance/server/grant_spec.rb @@ -500,18 +500,25 @@ class { 'postgresql::server': } describe 'REVOKE ... ON DATABASE...' do it 'do not fail on revoke connect from non-existant user' do begin - apply_manifest(pp_setup, catch_failures: true) - pp = pp_setup + <<-EOS.unindent - postgresql::server::grant { 'revoke connect on db from norole': - ensure => absent, - privilege => 'CONNECT', - object_type => 'DATABASE', - db => '#{db}', - role => '#{user}_does_not_exist', - } - EOS - apply_manifest(pp, catch_changes: true) - apply_manifest(pp, catch_failures: true) + # Test fail's on postgresql versions earlier than 9.1.24 + # postgres version + result = shell('psql --version') + version = result.stdout.match(%r{\s(\d\.\d)})[1] + + if version >= '9.1.24' + apply_manifest(pp_setup, catch_failures: true) + pp = pp_setup + <<-EOS.unindent + postgresql::server::grant { 'revoke connect on db from norole': + ensure => absent, + privilege => 'CONNECT', + object_type => 'DATABASE', + db => '#{db}', + role => '#{user}_does_not_exist', + } + EOS + apply_manifest(pp, catch_changes: true) + apply_manifest(pp, catch_failures: true) + end end end end