Skip to content

Commit

Permalink
More rspec fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
bzed committed Jan 14, 2025
1 parent 98a88eb commit a808de8
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 27 deletions.
20 changes: 10 additions & 10 deletions lib/puppet/provider/dehydrated_csr/openssl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
8 changes: 1 addition & 7 deletions lib/puppet/provider/dehydrated_pfx/openssl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
24 changes: 14 additions & 10 deletions spec/classes/setup/dehydrated_host_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit a808de8

Please sign in to comment.