From 95f1d6677770256f9103322eeaa5311bedf46d73 Mon Sep 17 00:00:00 2001 From: Cocker Koch Date: Tue, 29 Jun 2021 23:08:55 +0200 Subject: [PATCH] Accept Datatype Sensitive for $content - just as for systemd::dropin_file, accept Datatype Sensitive for $content - Rspec-Test for sensitive Content --- manifests/unit_file.pp | 2 +- spec/defines/unit_file_spec.rb | 26 +++++++++++++++++++++----- 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/manifests/unit_file.pp b/manifests/unit_file.pp index 09076004..eb5363fd 100644 --- a/manifests/unit_file.pp +++ b/manifests/unit_file.pp @@ -52,7 +52,7 @@ define systemd::unit_file ( Enum['present', 'absent', 'file'] $ensure = 'present', Stdlib::Absolutepath $path = '/etc/systemd/system', - Optional[String] $content = undef, + Optional[Variant[String, Sensitive[String]]] $content = undef, Optional[String] $source = undef, Optional[Stdlib::Absolutepath] $target = undef, String $owner = 'root', diff --git a/spec/defines/unit_file_spec.rb b/spec/defines/unit_file_spec.rb index abd6bdd4..60971097 100644 --- a/spec/defines/unit_file_spec.rb +++ b/spec/defines/unit_file_spec.rb @@ -10,11 +10,27 @@ it { is_expected.to compile.with_all_deps } - it do - is_expected.to create_file("/etc/systemd/system/#{title}"). - with_ensure('file'). - with_content(%r{#{params[:content]}}). - with_mode('0444') + context 'with non-sensitive Content' do + let(:params) { { content: 'non-sensitive Content' } } + + it do + is_expected.to create_file("/etc/systemd/system/#{title}"). + with_ensure('file'). + with_content(params[:content]). + with_mode('0444') + end + end + + context 'with sensitive Content' do + let(:params) { { content: sensitive('sensitive Content') } } + + it do + resource = catalogue.resource("File[/etc/systemd/system/#{title}]") + expect(resource[:content]).to eq(params[:content].unwrap) + + is_expected.to contain_file("/etc/systemd/system/#{title}"). + with({ content: sensitive('sensitive Content') }) + end end context 'with a bad unit type' do