|
3 | 3 | require 'spec_helper'
|
4 | 4 | require 'facter'
|
5 | 5 |
|
| 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 | + |
6 | 73 | describe Facter.fact(:openssl_version) do
|
7 | 74 | on_supported_os.each do |os, facts|
|
8 | 75 | context "on #{os}" do
|
|
16 | 83 | context 'with value' do
|
17 | 84 | before do
|
18 | 85 | 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]) |
20 | 87 | end
|
21 | 88 |
|
22 | 89 | 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]) |
24 | 91 | }
|
25 | 92 | end
|
26 | 93 |
|
|
36 | 103 | }
|
37 | 104 | end
|
38 | 105 | end
|
| 106 | + end |
| 107 | + end |
39 | 108 |
|
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 |
117 |
| - |
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 |
| 109 | + filler_facts = on_supported_os['redhat-9-x86_64'] |
| 110 | + ['legacy', 'redhat-8-legacy'].each do |special_case| |
| 111 | + context "on #{special_case}" do |
| 112 | + let(:facts) { filler_facts } |
124 | 113 |
|
125 |
| - it { |
126 |
| - expect(Facter.value(:openssl_version)).to eq('1.1.1w') |
127 |
| - } |
128 |
| - end |
| 114 | + before do |
| 115 | + Facter.clear |
129 | 116 | end
|
130 | 117 |
|
131 |
| - describe 'openssl_version debian12' do |
| 118 | + describe 'openssl_version' do |
132 | 119 | context 'with value' do
|
133 | 120 | before do
|
134 | 121 | 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)') |
| 122 | + allow(Facter::Util::Resolution).to receive(:exec).with('openssl version 2>&1').and_return(fact_matrix[special_case][:return_string]) |
136 | 123 | end
|
137 | 124 |
|
138 | 125 | it {
|
139 |
| - expect(Facter.value(:openssl_version)).to eq('3.0.15') |
| 126 | + expect(Facter.value(:openssl_version)).to eq(fact_matrix[special_case][:version_string]) |
140 | 127 | }
|
141 | 128 | end
|
142 | 129 | end
|
|
0 commit comments