From a808de8f7fce731b94aad53ba36335af01576e73 Mon Sep 17 00:00:00 2001 From: Bernd Zeimetz Date: Tue, 14 Jan 2025 15:40:19 +0100 Subject: [PATCH] More rspec fixes --- lib/puppet/provider/dehydrated_csr/openssl.rb | 20 ++++++++-------- lib/puppet/provider/dehydrated_pfx/openssl.rb | 8 +------ spec/classes/setup/dehydrated_host_spec.rb | 24 +++++++++++-------- 3 files changed, 25 insertions(+), 27 deletions(-) diff --git a/lib/puppet/provider/dehydrated_csr/openssl.rb b/lib/puppet/provider/dehydrated_csr/openssl.rb index 5dc0a27..1e81113 100644 --- a/lib/puppet/provider/dehydrated_csr/openssl.rb +++ b/lib/puppet/provider/dehydrated_csr/openssl.rb @@ -17,16 +17,16 @@ def self.private_key(resource) end end - def self._parse_san_value(v) - case v.tag + def self._parse_san_value(san_value) + case san_value.tag when 2 - v.value + san_value.value when 7 - case v.value.size + case san_value.value.size when 4 - v.value.unpack('C*').join('.') + san_value.value.unpack('C*').join('.') when 16 - v.value.unpack('n*').map { |o| '%X' % o }.join(':') + san_value.value.unpack('n*').map { |o| format('%X', o) }.join(':') end end end @@ -39,16 +39,16 @@ def self.check_sans(resource) end csr_alt_names = if ext_req - san_value = ext_req.value.map do |ext_req_v| + san_values = ext_req.value.map do |ext_req_v| san = ext_req_v.find do |v| v.value[0].value == 'subjectAltName' end san.value[1] if san end - if san_value - san_value = OpenSSL::ASN1.decode(san_value[0].value) + if san_values + san_values = OpenSSL::ASN1.decode(san_values[0].value) - san_value.map do |v| + san_values.map do |v| _parse_san_value(v) end else diff --git a/lib/puppet/provider/dehydrated_pfx/openssl.rb b/lib/puppet/provider/dehydrated_pfx/openssl.rb index 5b8335d..b4216d1 100644 --- a/lib/puppet/provider/dehydrated_pfx/openssl.rb +++ b/lib/puppet/provider/dehydrated_pfx/openssl.rb @@ -41,13 +41,7 @@ def exists? pfx_ca_serials == ca_serials && pfx.certificate.serial.to_s == cert.serial.to_s && key.to_pem == pfx.key.to_pem - rescue OpenSSL::PKCS12::PKCS12Error - false - rescue OpenSSL::X509::CertificateError - false - rescue OpenSSL::PKey::ECError - false - rescue OpenSSL::PKey::RSAError + rescue OpenSSL::PKCS12::PKCS12Error, OpenSSL::X509::CertificateError, OpenSSL::PKey::ECError, OpenSSL::PKey::RSAError false end else diff --git a/spec/classes/setup/dehydrated_host_spec.rb b/spec/classes/setup/dehydrated_host_spec.rb index d718f3b..2dc576a 100644 --- a/spec/classes/setup/dehydrated_host_spec.rb +++ b/spec/classes/setup/dehydrated_host_spec.rb @@ -2,22 +2,26 @@ require 'spec_helper' -# buggy rubocop -# rubocop:disable RSpec/EmptyExampleGroup describe 'dehydrated::setup::dehydrated_host' do + let(:pre_condition) do + <<~PUPPET + function puppetdb_query(String[1] $data) { + return [ + ] + } + function assert_private() { + } + class { 'dehydrated' : dehydrated_host => $facts['networking']['fqdn'] } + PUPPET + end + on_supported_os.each do |os, os_facts| next if os_facts[:kernel] == 'windows' - let :pre_condition do - if %r{windows.*}.match?(os) - 'class { "dehydrated" : dehydrated_host => "some.other.host.example.com" }' - else - 'class { "dehydrated" : dehydrated_host => $facts["networking"]["fqdn"] }' - end - end - context "on #{os}" do let(:facts) { os_facts } + + it { is_expected.to compile.with_all_deps } end end end