Skip to content

Commit

Permalink
openssl_version: Adjust regex to match more openssl version strings
Browse files Browse the repository at this point in the history
  • Loading branch information
sboyd-m committed Feb 10, 2025
1 parent a578e1f commit 5d4977c
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/facter/openssl_version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
setcode do
if Facter::Util::Resolution.which('openssl')
openssl_version = Facter::Util::Resolution.exec('openssl version 2>&1')
matches = %r{^OpenSSL ([\w.-]+)(\s+FIPS)?( +)([\d.]+)( +)([\w.]+)( +)([\d.]+)}.match(openssl_version)
matches = %r{^OpenSSL ([\w.]+)[ -]*(fips|FIPS)? +([\d.]+) +([\w.]+) +([\d.]+) *(\([\w:. ]+\))?}.match(openssl_version)
matches[1] if matches
end
end
Expand Down
54 changes: 53 additions & 1 deletion spec/unit/openssl_version_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
end

it {
expect(Facter.value(:openssl_version)).to eq('1.0.1e-fips')
expect(Facter.value(:openssl_version)).to eq('1.0.1e')
}
end
end
Expand Down Expand Up @@ -88,6 +88,58 @@
}
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

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

describe 'openssl_version debian12' 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)')
end

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

0 comments on commit 5d4977c

Please sign in to comment.