|
38 | 38 | it { should be_grouped_into 'root' } |
39 | 39 | end |
40 | 40 |
|
41 | | - describe command("keytool -list -keystore /etc/pki/keystore -storepass:file /etc/pki/keystore_password-file") do |
| 41 | + describe command("keytool -list -keystore /etc/pki/keystore -storepass testpassword") do |
42 | 42 | its(:exit_status) { should eq 0 } |
43 | 43 | its(:stdout) { should match(/^Keystore type: PKCS12$/i) } |
44 | 44 | its(:stdout) { should match(/^Your keystore contains 0 entries$/) } |
45 | 45 | end |
| 46 | + |
| 47 | + describe 'changing password' do |
| 48 | + describe 'apply puppet' do |
| 49 | + let(:manifest) do |
| 50 | + <<-PUPPET |
| 51 | + $keystore_password_file = '/etc/pki/keystore_password-file' |
| 52 | +
|
| 53 | + package { 'java-11-openjdk-headless': |
| 54 | + ensure => installed, |
| 55 | + } |
| 56 | +
|
| 57 | + file { $keystore_password_file: |
| 58 | + ensure => file, |
| 59 | + content => 'other-password', |
| 60 | + owner => 'root', |
| 61 | + group => 'root', |
| 62 | + mode => '0440', |
| 63 | + show_diff => false, |
| 64 | + } |
| 65 | +
|
| 66 | + keystore { "/etc/pki/keystore": |
| 67 | + ensure => present, |
| 68 | + password_file => $keystore_password_file, |
| 69 | + owner => 'root', |
| 70 | + group => 'root', |
| 71 | + mode => '0640', |
| 72 | + } |
| 73 | + PUPPET |
| 74 | + end |
| 75 | + |
| 76 | + it 'applies changes with no errors' do |
| 77 | + apply_manifest_on(default, manifest, expect_changes: true) |
| 78 | + end |
| 79 | + |
| 80 | + it 'applies a second time without changes' do |
| 81 | + apply_manifest_on(default, manifest, catch_changes: true) |
| 82 | + end |
| 83 | + end |
| 84 | + |
| 85 | + describe command("keytool -list -keystore /etc/pki/keystore -storepass other-password") do |
| 86 | + its(:exit_status) { should eq 0 } |
| 87 | + its(:stdout) { should match(/^Keystore type: PKCS12$/i) } |
| 88 | + its(:stdout) { should match(/^Your keystore contains 0 entries$/) } |
| 89 | + end |
| 90 | + end |
| 91 | + |
| 92 | + describe 'noop' do |
| 93 | + describe 'change password file' do |
| 94 | + let(:manifest) do |
| 95 | + <<-PUPPET |
| 96 | + file { '/etc/pki/keystore_password-file': |
| 97 | + ensure => file, |
| 98 | + content => 'wrong-password', |
| 99 | + owner => 'root', |
| 100 | + group => 'root', |
| 101 | + mode => '0440', |
| 102 | + show_diff => false, |
| 103 | + } |
| 104 | + PUPPET |
| 105 | + end |
| 106 | + |
| 107 | + it 'applies changes with no errors' do |
| 108 | + apply_manifest_on(default, manifest, catch_failures: true) |
| 109 | + end |
| 110 | + end |
| 111 | + |
| 112 | + describe 'run in noop mode with wrong password' do |
| 113 | + let(:manifest) do |
| 114 | + <<-PUPPET |
| 115 | + $keystore_password_file = '/etc/pki/keystore_password-file' |
| 116 | +
|
| 117 | + package { 'java-11-openjdk-headless': |
| 118 | + ensure => installed, |
| 119 | + } |
| 120 | +
|
| 121 | + file { $keystore_password_file: |
| 122 | + ensure => file, |
| 123 | + content => 'other-password', |
| 124 | + owner => 'root', |
| 125 | + group => 'root', |
| 126 | + mode => '0440', |
| 127 | + show_diff => false, |
| 128 | + } |
| 129 | +
|
| 130 | + keystore { "/etc/pki/keystore": |
| 131 | + ensure => present, |
| 132 | + password_file => $keystore_password_file, |
| 133 | + owner => 'root', |
| 134 | + group => 'root', |
| 135 | + mode => '0640', |
| 136 | + } |
| 137 | + PUPPET |
| 138 | + end |
| 139 | + |
| 140 | + it 'applies changes with no errors' do |
| 141 | + apply_manifest_on(default, manifest, noop: true) |
| 142 | + end |
| 143 | + end |
| 144 | + |
| 145 | + describe file('/etc/pki/keystore') do |
| 146 | + it { is_expected.to be_file } |
| 147 | + end |
| 148 | + |
| 149 | + # Should still be readable with the old password |
| 150 | + describe command("keytool -list -keystore /etc/pki/keystore -storepass other-password") do |
| 151 | + its(:exit_status) { should eq 0 } |
| 152 | + its(:stdout) { should match(/^Keystore type: PKCS12$/i) } |
| 153 | + its(:stdout) { should match(/^Your keystore contains 0 entries$/) } |
| 154 | + end |
| 155 | + end |
46 | 156 | end |
47 | 157 | end |
0 commit comments