2014-01-22 01:45:58 +01:00
|
|
|
require 'spec_helper_acceptance'
|
2013-08-27 22:43:47 +02:00
|
|
|
|
2014-02-27 21:48:10 +01:00
|
|
|
describe 'postgresql::server::role:', :unless => UNSUPPORTED_PLATFORMS.include?(fact('osfamily')) do
|
2013-08-27 22:43:47 +02:00
|
|
|
after :all do
|
|
|
|
# Cleanup after tests have ran
|
2014-01-22 01:45:58 +01:00
|
|
|
apply_manifest("class { 'postgresql::server': ensure => absent }", :catch_failures => true)
|
2013-08-27 22:43:47 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'should idempotently create a user who can log in' do
|
2013-09-18 23:25:51 +02:00
|
|
|
pp = <<-EOS.unindent
|
2013-08-27 22:43:47 +02:00
|
|
|
$user = "postgresql_test_user"
|
|
|
|
$password = "postgresql_test_password"
|
|
|
|
|
|
|
|
class { 'postgresql::server': }
|
|
|
|
|
|
|
|
# Since we are not testing pg_hba or any of that, make a local user for ident auth
|
|
|
|
user { $user:
|
|
|
|
ensure => present,
|
|
|
|
}
|
|
|
|
|
|
|
|
postgresql::server::role { $user:
|
|
|
|
password_hash => postgresql_password($user, $password),
|
|
|
|
}
|
|
|
|
EOS
|
|
|
|
|
2014-01-22 01:45:58 +01:00
|
|
|
apply_manifest(pp, :catch_failures => true)
|
2013-08-27 22:43:47 +02:00
|
|
|
|
|
|
|
# Check that the user can log in
|
|
|
|
psql('--command="select datname from pg_database" postgres', 'postgresql_test_user') do |r|
|
2014-01-22 01:45:58 +01:00
|
|
|
expect(r.stdout).to match(/template1/)
|
|
|
|
expect(r.stderr).to eq('')
|
2013-08-27 22:43:47 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should idempotently alter a user who can log in' do
|
2013-09-18 23:25:51 +02:00
|
|
|
pp = <<-EOS.unindent
|
2013-08-27 22:43:47 +02:00
|
|
|
$user = "postgresql_test_user"
|
|
|
|
$password = "postgresql_test_password2"
|
|
|
|
|
|
|
|
class { 'postgresql::server': }
|
|
|
|
|
|
|
|
# Since we are not testing pg_hba or any of that, make a local user for ident auth
|
|
|
|
user { $user:
|
|
|
|
ensure => present,
|
|
|
|
}
|
|
|
|
|
|
|
|
postgresql::server::role { $user:
|
|
|
|
password_hash => postgresql_password($user, $password),
|
|
|
|
}
|
|
|
|
EOS
|
|
|
|
|
2014-01-22 01:45:58 +01:00
|
|
|
apply_manifest(pp, :catch_failures => true)
|
|
|
|
apply_manifest(pp, :catch_changes => true)
|
2013-08-27 22:43:47 +02:00
|
|
|
|
|
|
|
# Check that the user can log in
|
|
|
|
psql('--command="select datname from pg_database" postgres', 'postgresql_test_user') do |r|
|
2014-01-22 01:45:58 +01:00
|
|
|
expect(r.stdout).to match(/template1/)
|
|
|
|
expect(r.stderr).to eq('')
|
2013-08-27 22:43:47 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should idempotently create a user with a cleartext password' do
|
2013-09-18 23:25:51 +02:00
|
|
|
pp = <<-EOS.unindent
|
2013-08-27 22:43:47 +02:00
|
|
|
$user = "postgresql_test_user2"
|
|
|
|
$password = "postgresql_test_password2"
|
|
|
|
|
|
|
|
class { 'postgresql::server': }
|
|
|
|
|
|
|
|
# Since we are not testing pg_hba or any of that, make a local user for ident auth
|
|
|
|
user { $user:
|
|
|
|
ensure => present,
|
|
|
|
}
|
|
|
|
|
|
|
|
postgresql::server::role { $user:
|
|
|
|
password_hash => $password,
|
|
|
|
}
|
|
|
|
EOS
|
|
|
|
|
2014-01-22 01:45:58 +01:00
|
|
|
apply_manifest(pp, :catch_failures => true)
|
|
|
|
apply_manifest(pp, :catch_changes => true)
|
2013-08-27 22:43:47 +02:00
|
|
|
|
|
|
|
# Check that the user can log in
|
|
|
|
psql('--command="select datname from pg_database" postgres', 'postgresql_test_user2') do |r|
|
2014-01-22 01:45:58 +01:00
|
|
|
expect(r.stdout).to match(/template1/)
|
|
|
|
expect(r.stderr).to eq('')
|
2013-08-27 22:43:47 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|