Skip to content

Commit 667250c

Browse files
committed
initial version of grant_spec added
1 parent 1773320 commit 667250c

File tree

1 file changed

+62
-0
lines changed

1 file changed

+62
-0
lines changed
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
require 'spec_helper_system'
2+
3+
describe 'postgresql::server::role_grant:' do
4+
after :all do
5+
# Cleanup after tests have ran
6+
puppet_apply("class { 'postgresql::server': ensure => absent }") do |r|
7+
r.exit_code.should_not == 1
8+
end
9+
end
10+
11+
it 'should grant access so a user can create in a database' do
12+
begin
13+
pp = <<-EOS.unindent
14+
$db = 'postgres'
15+
$parent_role = 'psql_grant_tester_parent'
16+
$child_role = 'psql_grant_tester_child'
17+
$password = 'psql_grant_pw'
18+
19+
class { 'postgresql::server': }
20+
21+
# Since we are not testing pg_hba or any of that, make a local user for ident auth
22+
user { $user:
23+
ensure => present,
24+
}
25+
26+
postgresql::server::role { $user:
27+
password_hash => postgresql_password($user, $password),
28+
}
29+
30+
postgresql::server::database { $db: }
31+
32+
postgresql::server::grant { 'grant create testparent':
33+
object_type => 'database',
34+
privilege => 'CREATE',
35+
db => $db,
36+
role => $parent_role,
37+
}
38+
39+
postgresql::server::role_grant { 'grant child_role to parent_role':
40+
role => $parent_role,
41+
user => $child_role,
42+
admin_option => true,
43+
}
44+
EOS
45+
46+
puppet_apply(pp) do |r|
47+
r.exit_code.should_not == 1
48+
r.refresh
49+
r.exit_code.should == 0
50+
end
51+
52+
# Check that the user can create a table in the database
53+
psql('--command="create table foo (foo int)" postgres', 'psql_grant_tester_child') do |r|
54+
r.stdout.should =~ /CREATE TABLE/
55+
r.stderr.should == ''
56+
r.exit_code.should == 0
57+
end
58+
ensure
59+
psql('--command="drop table foo" postgres', 'psql_grant_tester')
60+
end
61+
end
62+
end

0 commit comments

Comments
 (0)