843c3b12ca0f78f328bde1bdd20db4a55d4ecad5
[mirror/dsa-puppet.git] / 3rdparty / modules / certregen / spec / classes / client_spec.rb
1 require 'spec_helper'
2
3 RSpec.shared_examples "managing the CRL on the client" do |setting|
4   describe "when manage_crl is false" do
5     let(:params) {{'manage_crl' => false}}
6
7     it "doesn't manage the hostcrl on the client" do
8       should_not contain_file(client_hostcrl)
9     end
10   end
11
12   describe "when manage_crl is true" do
13     let(:params) {{'manage_crl' => true}}
14
15     it "manages the hostcrl on the client from the server '#{setting}' setting" do
16       should contain_file(client_hostcrl).with(
17         'ensure'  => 'present',
18         'content' => Puppet.settings.setting(setting).open(&:read),
19         'mode'    => '0644',
20       )
21     end
22   end
23 end
24
25 RSpec.describe 'certregen::client' do
26   include_context "Initialize CA"
27
28   let(:client_localcacert) { tmpfilename('ca.pem') }
29   let(:client_hostcrl) { tmpfilename('crl.pem') }
30
31   let(:facts) do
32     {
33       'localcacert' => client_localcacert,
34       'hostcrl'     => client_hostcrl,
35       'pe_build'    => '2016.4.0',
36     }
37   end
38
39   before do
40     Puppet.settings.setting(:localcacert).open('w') { |f| f.write("local CA cert") }
41     Puppet.settings.setting(:hostcrl).open('w') { |f| f.write("local CRL") }
42   end
43
44   describe 'when the compile master has CA ssl files' do
45     before do
46       Puppet.settings.setting(:cacert).open('w') { |f| f.write("CA cert") }
47       Puppet.settings.setting(:cacrl).open('w') { |f| f.write("CA CRL") }
48     end
49
50     describe "managing the localcacert on the client" do
51       it do
52         should contain_file(client_localcacert).with(
53           'ensure'  => 'present',
54           'content' => Puppet.settings.setting(:cacert).open(&:read),
55           'mode'    => '0644',
56         )
57       end
58     end
59
60     it_behaves_like "managing the CRL on the client", :cacrl
61   end
62
63   describe "when the compile master only has agent SSL files" do
64     before do
65       FileUtils.rm(Puppet[:cacert])
66       FileUtils.rm(Puppet[:cacrl])
67     end
68
69     describe "managing the localcacert on the client" do
70       it 'manages the client CA cert from the `localcacert` setting' do
71         should contain_file(client_localcacert).with(
72           'ensure'  => 'present',
73           'content' => Puppet.settings.setting(:localcacert).open(&:read),
74           'mode'    => '0644',
75         )
76       end
77     end
78
79     it_behaves_like "managing the CRL on the client", :hostcrl
80   end
81 end