Skip to content

Commit

Permalink
tests: DRY out openssl_version fact tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sboyd-m committed Feb 10, 2025
1 parent 5d4977c commit 99bd40e
Showing 1 changed file with 80 additions and 93 deletions.
173 changes: 80 additions & 93 deletions spec/unit/openssl_version_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,73 @@
require 'spec_helper'
require 'facter'

fact_matrix = {
'debian-11-x86_64' => {
return_string: 'OpenSSL 1.1.1w 11 Sep 2023',
version_string: '1.1.1w',
},
'debian-12-x86_64' => {
return_string: 'OpenSSL 3.0.15 3 Sep 2024 (Library: OpenSSL 3.0.15 3 Sep 2024)',
version_string: '3.0.15',
},
'ubuntu-20.04-x86_64' => {
return_string: 'OpenSSL 1.1.1f 31 Mar 2020',
version_string: '1.1.1f',
},
'ubuntu-22.04-x86_64' => {
return_string: 'OpenSSL 3.0.2 15 Mar 2022 (Library: OpenSSL 3.0.2 15 Mar 2022)',
version_string: '3.0.2',
},
'ubuntu-24.04-x86_64' => {
return_string: 'OpenSSL 3.0.13 30 Jan 2024 (Library: OpenSSL 3.0.13 30 Jan 2024)',
version_string: '3.0.13',
},
'redhat-8-legacy' => {
return_string: 'OpenSSL 1.1.1c FIPS 28 May 2019',
version_string: '1.1.1c',
},
'redhat-8-x86_64' => {
return_string: 'OpenSSL 1.1.1k FIPS 25 Mar 2021',
version_string: '1.1.1k',
},
'redhat-9-x86_64' => {
return_string: 'OpenSSL 9.9.9zzz FIPS 1 Jan 2099',
version_string: '9.9.9zzz',
},
'oraclelinux-8-x86_64' => {
return_string: 'OpenSSL 1.1.1k FIPS 25 Mar 2021',
version_string: '1.1.1k',
},
'oraclelinux-9-x86_64' => {
return_string: 'OpenSSL 3.2.2 4 Jun 2024 (Library: OpenSSL 3.2.2 4 Jun 2024)',
version_string: '3.2.2',
},
'rocky-8-x86_64' => {
return_string: 'OpenSSL 1.1.1k FIPS 25 Mar 2021',
version_string: '1.1.1k',
},
'rocky-9-x86_64' => {
return_string: 'OpenSSL 3.2.2 4 Jun 2024 (Library: OpenSSL 3.2.2 4 Jun 2024)',
version_string: '3.2.2',
},
'almalinux-8-x86_64' => {
return_string: 'OpenSSL 1.1.1k FIPS 25 Mar 2021',
version_string: '1.1.1k',
},
'almalinux-9-x86_64' => {
return_string: 'OpenSSL 3.2.2 4 Jun 2024 (Library: OpenSSL 3.2.2 4 Jun 2024)',
version_string: '3.2.2',
},
'centos-9-x86_64' => {
return_string: 'OpenSSL 1.0.2g 1 Mar 2016',
version_string: '1.0.2g',
},
'legacy' => {
return_string: 'OpenSSL 0.9.8zg 14 July 2015',
version_string: '0.9.8zg',
},
}

describe Facter.fact(:openssl_version) do
on_supported_os.each do |os, facts|
context "on #{os}" do
Expand All @@ -16,11 +83,11 @@
context 'with value' do
before do
allow(Facter::Util::Resolution).to receive(:which).with('openssl').and_return(true)
allow(Facter::Util::Resolution).to receive(:exec).with('openssl version 2>&1').and_return('OpenSSL 0.9.8zg 14 July 2015')
allow(Facter::Util::Resolution).to receive(:exec).with('openssl version 2>&1').and_return(fact_matrix[os][:return_string])
end

it {
expect(Facter.value(:openssl_version)).to eq('0.9.8zg')
expect(Facter.value(:openssl_version)).to eq(fact_matrix[os][:version_string])
}
end

Expand All @@ -36,107 +103,27 @@
}
end
end
end
end

describe 'openssl_version rhel' do
context 'with value' do
before do
allow(Facter::Util::Resolution).to receive(:which).with('openssl').and_return(true)
allow(Facter::Util::Resolution).to receive(:exec).with('openssl version 2>&1').and_return('OpenSSL 1.0.1e-fips 11 Feb 2013')
end

it {
expect(Facter.value(:openssl_version)).to eq('1.0.1e')
}
end
end

describe 'openssl_version centos' do
context 'with value' do
before do
allow(Facter::Util::Resolution).to receive(:which).with('openssl').and_return(true)
allow(Facter::Util::Resolution).to receive(:exec).with('openssl version 2>&1').and_return('OpenSSL 1.0.2g 1 Mar 2016')
end

it {
expect(Facter.value(:openssl_version)).to eq('1.0.2g')
}
end
end

describe 'openssl_version rhel8' do
context 'with value' do
before do
allow(Facter::Util::Resolution).to receive(:which).with('openssl').and_return(true)
allow(Facter::Util::Resolution).to receive(:exec).with('openssl version 2>&1').and_return('OpenSSL 1.1.1c FIPS 28 May 2019')
end

it {
expect(Facter.value(:openssl_version)).to eq('1.1.1c')
}
end
end

describe 'openssl_version rhel8 latest' do
context 'with value' do
before do
allow(Facter::Util::Resolution).to receive(:which).with('openssl').and_return(true)
allow(Facter::Util::Resolution).to receive(:exec).with('openssl version 2>&1').and_return('OpenSSL 1.1.1k FIPS 25 Mar 2021')
end

it {
expect(Facter.value(:openssl_version)).to eq('1.1.1k')
}
end
end

describe 'openssl_version oracle7' do
context 'with value' do
before do
allow(Facter::Util::Resolution).to receive(:which).with('openssl').and_return(true)
allow(Facter::Util::Resolution).to receive(:exec).with('openssl version 2>&1').and_return('OpenSSL 1.0.2k-fips 26 Jan 2017')
end

it {
expect(Facter.value(:openssl_version)).to eq('1.0.2k')
}
end
end

describe 'openssl_version oracle8' do
context 'with value' do
before do
allow(Facter::Util::Resolution).to receive(:which).with('openssl').and_return(true)
allow(Facter::Util::Resolution).to receive(:exec).with('openssl version 2>&1').and_return('OpenSSL 1.1.1k FIPS 25 Mar 2021')
end

it {
expect(Facter.value(:openssl_version)).to eq('1.1.1k')
}
end
end

describe 'openssl_version debian11' do
context 'with value' do
before do
allow(Facter::Util::Resolution).to receive(:which).with('openssl').and_return(true)
allow(Facter::Util::Resolution).to receive(:exec).with('openssl version 2>&1').and_return('OpenSSL 1.1.1w 11 Sep 2023')
end
filler_facts = on_supported_os['redhat-9-x86_64']
['legacy', 'redhat-8-legacy'].each do |special_case|
context "on #{special_case}" do
let(:facts) { filler_facts }

it {
expect(Facter.value(:openssl_version)).to eq('1.1.1w')
}
end
before do
Facter.clear
end

describe 'openssl_version debian12' do
describe 'openssl_version' do
context 'with value' do
before do
allow(Facter::Util::Resolution).to receive(:which).with('openssl').and_return(true)
allow(Facter::Util::Resolution).to receive(:exec).with('openssl version 2>&1').and_return('OpenSSL 3.0.15 3 Sep 2024 (Library: OpenSSL 3.0.15 3 Sep 2024)')
allow(Facter::Util::Resolution).to receive(:exec).with('openssl version 2>&1').and_return(fact_matrix[special_case][:return_string])
end

it {
expect(Facter.value(:openssl_version)).to eq('3.0.15')
expect(Facter.value(:openssl_version)).to eq(fact_matrix[special_case][:version_string])
}
end
end
Expand Down

0 comments on commit 99bd40e

Please sign in to comment.