|
2 | 2 |
|
3 | 3 | require 'spec_helper_acceptance' |
4 | 4 |
|
5 | | -describe 'postgresql::server::db' do |
6 | | - before(:all) do |
7 | | - LitmusHelper.instance.run_shell("cd /tmp; su 'postgres' -c 'pg_ctl stop -D /var/lib/pgsql/data/ -m fast'", acceptable_exit_codes: [0, 1]) unless os[:family].match?(%r{debian|ubuntu}) |
8 | | - end |
9 | | - |
10 | | - it 'creates a database with a deferred password' do |
11 | | - tmpdir = run_shell('mktemp').stdout |
12 | | - pp = <<-MANIFEST |
13 | | - class { 'postgresql::server': |
14 | | - postgres_password => 'space password', |
15 | | - } |
16 | | - postgresql::server::tablespace { 'postgresql-test-db': |
17 | | - location => '#{tmpdir}', |
18 | | - } -> |
19 | | - postgresql::server::db { 'postgresql-test-db': |
20 | | - comment => 'testcomment', |
21 | | - user => 'test-user', |
22 | | - password => Deferred('unwrap', ['test1']) |
23 | | - tablespace => 'postgresql-test-db', |
| 5 | +describe 'postgresql::server::db:' do |
| 6 | + let(:user) { 'user_test' } |
| 7 | + let(:password) { 'deferred_password_test' } |
| 8 | + let(:database) { 'test_database' } |
| 9 | + |
| 10 | + let(:pp_one) do |
| 11 | + <<-MANIFEST.unindent |
| 12 | + $user = #{user} |
| 13 | + $password = #{password} |
| 14 | + $database = #{database} |
| 15 | +
|
| 16 | + include postgresql::server |
| 17 | + postgresql::server::db { $database: |
| 18 | + user => $user, |
| 19 | + password => Deferred('unwrap', [$password]), |
24 | 20 | } |
25 | 21 | MANIFEST |
| 22 | + end |
26 | 23 |
|
27 | | - idempotent_apply(pp) |
28 | | - |
29 | | - # Verify that the postgres password works |
30 | | - run_shell("echo 'localhost:*:*:postgres:'space password'' > /root/.pgpass") |
31 | | - run_shell('chmod 600 /root/.pgpass') |
32 | | - run_shell("psql -U postgres -h localhost --command='\\l'") |
33 | | - |
34 | | - result = psql('--command="select datname from pg_database" "postgresql-test-db"') |
35 | | - expect(result.stdout).to match(%r{postgresql-test-db}) |
36 | | - expect(result.stderr).to eq('') |
37 | | - |
38 | | - result = psql('--command="SELECT 1 FROM pg_roles WHERE rolname=\'test-user\'"') |
39 | | - expect(result.stdout).to match(%r{\(1 row\)}) |
40 | | - |
41 | | - result = psql("--dbname postgresql-test-db --command=\"SELECT pg_catalog.shobj_description(d.oid, 'pg_database') FROM pg_catalog.pg_database d WHERE datname = 'postgresql-test-db' AND pg_catalog.shobj_description(d.oid, 'pg_database') = 'testcomment'\"") # rubocop:disable Layout/LineLength |
42 | | - expect(result.stdout).to match(%r{\(1 row\)}) |
43 | | - ensure |
44 | | - psql('--command=\'drop database "postgresql-test-db"\'') |
| 24 | + it 'creates a database with with the password in the deferred function' do |
| 25 | + if run_shell('puppet --version').stdout[0].to_i < 7 |
| 26 | + skip # Deferred function fixes only in puppet 7, see https://tickets.puppetlabs.com/browse/PUP-11518 |
| 27 | + end |
| 28 | + apply_manifest(pp_one) |
| 29 | + psql_cmd = "PGPASSWORD=#{password} PGUSER=#{user} PGDATABASE=#{database} psql -h 127.0.0.1 -d postgres -c '\\q'" |
| 30 | + run_shell("cd /tmp; su #{shellescape('postgres')} -c #{shellescape(psql_cmd)}", |
| 31 | + acceptable_exit_codes: [0]) |
45 | 32 | end |
46 | 33 | end |
0 commit comments