Skip to content

Commit 2193f97

Browse files
committed
tests: DRY out openssl_version fact tests
1 parent 5d4977c commit 2193f97

File tree

1 file changed

+81
-93
lines changed

1 file changed

+81
-93
lines changed

spec/unit/openssl_version_spec.rb

Lines changed: 81 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,73 @@
33
require 'spec_helper'
44
require 'facter'
55

6+
fact_matrix = {
7+
'debian-11-x86_64' => {
8+
return_string: 'OpenSSL 1.1.1w 11 Sep 2023',
9+
version_string: '1.1.1w',
10+
},
11+
'debian-12-x86_64' => {
12+
return_string: 'OpenSSL 3.0.15 3 Sep 2024 (Library: OpenSSL 3.0.15 3 Sep 2024)',
13+
version_string: '3.0.15',
14+
},
15+
'ubuntu-20.04-x86_64' => {
16+
return_string: 'OpenSSL 1.1.1f 31 Mar 2020',
17+
version_string: '1.1.1f',
18+
},
19+
'ubuntu-22.04-x86_64' => {
20+
return_string: 'OpenSSL 3.0.2 15 Mar 2022 (Library: OpenSSL 3.0.2 15 Mar 2022)',
21+
version_string: '3.0.2',
22+
},
23+
'ubuntu-24.04-x86_64' => {
24+
return_string: 'OpenSSL 3.0.13 30 Jan 2024 (Library: OpenSSL 3.0.13 30 Jan 2024)',
25+
version_string: '3.0.13',
26+
},
27+
'redhat-8-legacy' => {
28+
return_string: 'OpenSSL 1.1.1c FIPS 28 May 2019',
29+
version_string: '1.1.1c',
30+
},
31+
'redhat-8-x86_64' => {
32+
return_string: 'OpenSSL 1.1.1k FIPS 25 Mar 2021',
33+
version_string: '1.1.1k',
34+
},
35+
'redhat-9-x86_64' => {
36+
return_string: 'OpenSSL 9.9.9zzz FIPS 1 Jan 2099',
37+
version_string: '9.9.9zzz',
38+
},
39+
'oraclelinux-8-x86_64' => {
40+
return_string: 'OpenSSL 1.1.1k FIPS 25 Mar 2021',
41+
version_string: '1.1.1k',
42+
},
43+
'oraclelinux-9-x86_64' => {
44+
return_string: 'OpenSSL 3.2.2 4 Jun 2024 (Library: OpenSSL 3.2.2 4 Jun 2024)',
45+
version_string: '3.2.2',
46+
},
47+
'rocky-8-x86_64' => {
48+
return_string: 'OpenSSL 1.1.1k FIPS 25 Mar 2021',
49+
version_string: '1.1.1k',
50+
},
51+
'rocky-9-x86_64' => {
52+
return_string: 'OpenSSL 3.2.2 4 Jun 2024 (Library: OpenSSL 3.2.2 4 Jun 2024)',
53+
version_string: '3.2.2',
54+
},
55+
'almalinux-8-x86_64' => {
56+
return_string: 'OpenSSL 1.1.1k FIPS 25 Mar 2021',
57+
version_string: '1.1.1k',
58+
},
59+
'almalinux-9-x86_64' => {
60+
return_string: 'OpenSSL 3.2.2 4 Jun 2024 (Library: OpenSSL 3.2.2 4 Jun 2024)',
61+
version_string: '3.2.2',
62+
},
63+
'centos-9-x86_64' => {
64+
return_string: 'OpenSSL 1.0.2g 1 Mar 2016',
65+
version_string: '1.0.2g',
66+
},
67+
'legacy' => {
68+
return_string: 'OpenSSL 0.9.8zg 14 July 2015',
69+
version_string: '0.9.8zg',
70+
},
71+
}
72+
673
describe Facter.fact(:openssl_version) do
774
on_supported_os.each do |os, facts|
875
context "on #{os}" do
@@ -12,15 +79,15 @@
1279
Facter.clear
1380
end
1481

15-
describe 'openssl_version' do
82+
describe "openssl_version" do
1683
context 'with value' do
1784
before do
1885
allow(Facter::Util::Resolution).to receive(:which).with('openssl').and_return(true)
19-
allow(Facter::Util::Resolution).to receive(:exec).with('openssl version 2>&1').and_return('OpenSSL 0.9.8zg 14 July 2015')
86+
allow(Facter::Util::Resolution).to receive(:exec).with('openssl version 2>&1').and_return(fact_matrix[os][:return_string])
2087
end
2188

2289
it {
23-
expect(Facter.value(:openssl_version)).to eq('0.9.8zg')
90+
expect(Facter.value(:openssl_version)).to eq(fact_matrix[os][:version_string])
2491
}
2592
end
2693

@@ -36,107 +103,28 @@
36103
}
37104
end
38105
end
106+
end
107+
end
39108

40-
describe 'openssl_version rhel' do
41-
context 'with value' do
42-
before do
43-
allow(Facter::Util::Resolution).to receive(:which).with('openssl').and_return(true)
44-
allow(Facter::Util::Resolution).to receive(:exec).with('openssl version 2>&1').and_return('OpenSSL 1.0.1e-fips 11 Feb 2013')
45-
end
46-
47-
it {
48-
expect(Facter.value(:openssl_version)).to eq('1.0.1e')
49-
}
50-
end
51-
end
52-
53-
describe 'openssl_version centos' do
54-
context 'with value' do
55-
before do
56-
allow(Facter::Util::Resolution).to receive(:which).with('openssl').and_return(true)
57-
allow(Facter::Util::Resolution).to receive(:exec).with('openssl version 2>&1').and_return('OpenSSL 1.0.2g 1 Mar 2016')
58-
end
59-
60-
it {
61-
expect(Facter.value(:openssl_version)).to eq('1.0.2g')
62-
}
63-
end
64-
end
65-
66-
describe 'openssl_version rhel8' do
67-
context 'with value' do
68-
before do
69-
allow(Facter::Util::Resolution).to receive(:which).with('openssl').and_return(true)
70-
allow(Facter::Util::Resolution).to receive(:exec).with('openssl version 2>&1').and_return('OpenSSL 1.1.1c FIPS 28 May 2019')
71-
end
72-
73-
it {
74-
expect(Facter.value(:openssl_version)).to eq('1.1.1c')
75-
}
76-
end
77-
end
78-
79-
describe 'openssl_version rhel8 latest' do
80-
context 'with value' do
81-
before do
82-
allow(Facter::Util::Resolution).to receive(:which).with('openssl').and_return(true)
83-
allow(Facter::Util::Resolution).to receive(:exec).with('openssl version 2>&1').and_return('OpenSSL 1.1.1k FIPS 25 Mar 2021')
84-
end
85-
86-
it {
87-
expect(Facter.value(:openssl_version)).to eq('1.1.1k')
88-
}
89-
end
90-
end
91-
92-
describe 'openssl_version oracle7' do
93-
context 'with value' do
94-
before do
95-
allow(Facter::Util::Resolution).to receive(:which).with('openssl').and_return(true)
96-
allow(Facter::Util::Resolution).to receive(:exec).with('openssl version 2>&1').and_return('OpenSSL 1.0.2k-fips 26 Jan 2017')
97-
end
98-
99-
it {
100-
expect(Facter.value(:openssl_version)).to eq('1.0.2k')
101-
}
102-
end
103-
end
104-
105-
describe 'openssl_version oracle8' do
106-
context 'with value' do
107-
before do
108-
allow(Facter::Util::Resolution).to receive(:which).with('openssl').and_return(true)
109-
allow(Facter::Util::Resolution).to receive(:exec).with('openssl version 2>&1').and_return('OpenSSL 1.1.1k FIPS 25 Mar 2021')
110-
end
111-
112-
it {
113-
expect(Facter.value(:openssl_version)).to eq('1.1.1k')
114-
}
115-
end
116-
end
117109

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

125-
it {
126-
expect(Facter.value(:openssl_version)).to eq('1.1.1w')
127-
}
128-
end
115+
before do
116+
Facter.clear
129117
end
130118

131-
describe 'openssl_version debian12' do
119+
describe "openssl_version" do
132120
context 'with value' do
133121
before do
134122
allow(Facter::Util::Resolution).to receive(:which).with('openssl').and_return(true)
135-
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)')
123+
allow(Facter::Util::Resolution).to receive(:exec).with('openssl version 2>&1').and_return(fact_matrix[special_case][:return_string])
136124
end
137125

138126
it {
139-
expect(Facter.value(:openssl_version)).to eq('3.0.15')
127+
expect(Facter.value(:openssl_version)).to eq(fact_matrix[special_case][:version_string])
140128
}
141129
end
142130
end

0 commit comments

Comments
 (0)