From 5739a20b70c33583ee9743f5417eacb08dacf082 Mon Sep 17 00:00:00 2001 From: Philipp Dallig Date: Thu, 31 Mar 2016 11:31:06 +0200 Subject: [PATCH 1/2] Fix in custom fact "apache_version" for OracleLinux. The custom fact defined by lib/facter/apache_version.rb runs "apachectl -v" and applies the following regular expression: ^Server version: Apache\/([\w\.]+) \(([\w ]+)\) On OracleLinux 7.2, running apachectl -v produces the following output: Server version: Apache/2.4.6 () Server built: Nov 21 2015 05:34:59 The regex fails to match the output because it does not allow for nothing inside the parentheses. The following modified regex matches properly: ^Server version: Apache\/([\w\.]+) \(([\w ]*)\) --- lib/facter/apache_version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/facter/apache_version.rb b/lib/facter/apache_version.rb index b84d776150..2790627307 100644 --- a/lib/facter/apache_version.rb +++ b/lib/facter/apache_version.rb @@ -2,7 +2,7 @@ setcode do if Facter::Util::Resolution.which('apachectl') apache_version = Facter::Util::Resolution.exec('apachectl -v 2>&1') - %r{^Server version: Apache\/([\w\.]+) \(([\w ]+)\)}.match(apache_version)[1] + %r{^Server version: Apache\/([\w\.]+) \(([\w ]*)\)}.match(apache_version)[1] end end end From b97be96e49582943bd64cebd3038f8e8a683d7ee Mon Sep 17 00:00:00 2001 From: Philipp Dallig Date: Mon, 4 Apr 2016 12:12:48 +0200 Subject: [PATCH 2/2] Add spec test for apache_version with an empty OS --- spec/unit/apache_version_spec.rb | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/spec/unit/apache_version_spec.rb b/spec/unit/apache_version_spec.rb index 30f6ef9914..c62339da41 100644 --- a/spec/unit/apache_version_spec.rb +++ b/spec/unit/apache_version_spec.rb @@ -17,4 +17,17 @@ end end end + + describe 'apache_version with empty OS' do + context 'with value' do + before :each do + Facter::Util::Resolution.stubs(:which).with('apachectl').returns(true) + Facter::Util::Resolution.stubs(:exec).with('apachectl -v 2>&1').returns('Server version: Apache/2.4.6 () + Server built: Nov 21 2015 05:34:59') + end + it do + expect(Facter.fact(:apache_version).value).to eq('2.4.6') + end + end + end end