From 44180f78bf6b3d8c37a41c4d6d6cf1c2b9538aca Mon Sep 17 00:00:00 2001 From: Blerim Sheqa Date: Tue, 28 Feb 2017 13:33:29 +0100 Subject: [PATCH] Update specs for icinga2::pki::ca --- spec/classes/ca_spec.rb | 125 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 123 insertions(+), 2 deletions(-) diff --git a/spec/classes/ca_spec.rb b/spec/classes/ca_spec.rb index 0c2d91b7f..7dc73d4a7 100644 --- a/spec/classes/ca_spec.rb +++ b/spec/classes/ca_spec.rb @@ -2,7 +2,7 @@ describe('icinga2::pki::ca', :type => :class) do let(:pre_condition) { [ - "class { 'icinga2': }" + "class { 'icinga2': features => [], constants => {'NodeName' => 'host.example.org'} }" ] } before(:all) do @@ -17,6 +17,10 @@ context "#{os} with defaults (no params)" do it { is_expected.to contain_exec('create-icinga2-ca') } + + it { is_expected.to contain_file('/etc/icinga2/pki/host.example.org.key') } + it { is_expected.to contain_file('/etc/icinga2/pki/host.example.org.crt') } + it { is_expected.to contain_file('/etc/icinga2/pki/ca.crt') } end @@ -26,6 +30,61 @@ it { is_expected.to contain_file(@ca_cert).with_content(/foo/) } it { is_expected.to contain_file(@ca_key).with_content(/bar/) } end + + context "#{os} with ssl_key_path = /foo/bar" do + let(:params) { {:ssl_key_path => '/foo/bar'} } + + it { is_expected.to contain_file('/foo/bar') } + end + + + context "#{os} with ssl_key_path = foo/bar (not a valid absolute path)" do + let(:params) { {:ssl_key_path => 'foo/bar'} } + + it { is_expected.to raise_error(Puppet::Error, /"foo\/bar" is not an absolute path/) } + end + + + context "#{os} with ssl_cert_path = /foo/bar" do + let(:params) { {:ssl_cert_path => '/foo/bar'} } + + it { is_expected.to contain_file('/foo/bar') } + end + + + context "#{os} with ssl_cert_path = foo/bar (not a valid absolute path)" do + let(:params) { {:ssl_cert_path => 'foo/bar'} } + + it { is_expected.to raise_error(Puppet::Error, /"foo\/bar" is not an absolute path/) } + end + + + context "#{os} with ssl_csr_path = /foo/bar" do + let(:params) { {:ssl_csr_path => '/foo/bar'} } + + it { is_expected.to contain_file('/foo/bar') } + end + + + context "#{os} with ssl_csr_path = foo/bar (not a valid absolute path)" do + let(:params) { {:ssl_csr_path => 'foo/bar'} } + + it { is_expected.to raise_error(Puppet::Error, /"foo\/bar" is not an absolute path/) } + end + + + context "#{os} with ssl_cacert_path = /foo/bar" do + let(:params) { {:ssl_cacert_path => '/foo/bar'} } + + it { is_expected.to contain_file('/foo/bar') } + end + + + context "#{os} with ssl_cacert_path = foo/bar (not a valid absolute path)" do + let(:params) { {:ssl_cacert_path => 'foo/bar'} } + + it { is_expected.to raise_error(Puppet::Error, /"foo\/bar" is not an absolute path/) } + end end end @@ -48,7 +107,7 @@ C:\ProgramData\chocolatey\bin;', } } let(:pre_condition) { [ - "class { 'icinga2': }" + "class { 'icinga2': features => [], constants => {'NodeName' => 'host.example.org'} }" ] } before(:all) do @@ -56,8 +115,13 @@ @ca_key = "C:/ProgramData/icinga2/var/lib/icinga2/ca/ca.key" end + context "Windows 2012 R2 with defaults (no params)" do it { is_expected.to contain_exec('create-icinga2-ca') } + + it { is_expected.to contain_file('C:/ProgramData/icinga2/etc/icinga2/pki/host.example.org.key') } + it { is_expected.to contain_file('C:/ProgramData/icinga2/etc/icinga2/pki/host.example.org.crt') } + it { is_expected.to contain_file('C:/ProgramData/icinga2/etc/icinga2/pki/ca.crt') } end @@ -67,6 +131,63 @@ it { is_expected.to contain_file(@ca_cert).with_content(/foo/) } it { is_expected.to contain_file(@ca_key).with_content(/bar/) } end + + context "Windows 2012 R2 with ssl_key_path = /foo/bar" do + let(:params) { {:ssl_key_path => 'C:/ProgramData/icinga2/foo/bar'} } + + it { is_expected.to contain_file('C:/ProgramData/icinga2/foo/bar') } + end + + + context "Windows 2012 R2 with ssl_key_path = foo/bar (not a valid absolute path)" do + let(:params) { {:ssl_key_path => 'foo/bar'} } + + it { is_expected.to raise_error(Puppet::Error, /"foo\/bar" is not an absolute path/) } + end + + + context "Windows 2012 R2 with ssl_cert_path = C:/ProgramData/icinga2/foo/bar" do + let(:params) { {:ssl_cert_path => 'C:/ProgramData/icinga2/foo/bar'} } + + it { is_expected.to contain_file('C:/ProgramData/icinga2/foo/bar') } + end + + + context "Windows 2012 R2 with ssl_cert_path = foo/bar (not a valid absolute path)" do + let(:params) { {:ssl_cert_path => 'foo/bar'} } + + it { is_expected.to raise_error(Puppet::Error, /"foo\/bar" is not an absolute path/) } + end + + + context "Windows 2012 R2 with ssl_csr_path = C:/ProgramData/icinga2/foo/bar" do + let(:params) { {:ssl_csr_path => 'C:/ProgramData/icinga2/foo/bar'} } + + it { is_expected.to contain_file('C:/ProgramData/icinga2/foo/bar') } + end + + + context "Windows 2012 R2 with ssl_csr_path = foo/bar (not a valid absolute path)" do + let(:params) { {:ssl_csr_path => 'foo/bar'} } + + it { is_expected.to raise_error(Puppet::Error, /"foo\/bar" is not an absolute path/) } + end + + + context "Windows 2012 R2 with ssl_cacert_path = C:/ProgramData/icinga2/foo/bar" do + let(:params) { {:ssl_cacert_path => 'C:/ProgramData/icinga2/foo/bar'} } + + it { is_expected.to contain_file('C:/ProgramData/icinga2/foo/bar') } + end + + + context "Windows 2012 R2 with ssl_cacert_path = foo/bar (not a valid absolute path)" do + let(:params) { {:ssl_cacert_path => 'foo/bar'} } + + it { is_expected.to raise_error(Puppet::Error, /"foo\/bar" is not an absolute path/) } + end + + end