From 9c051da22b48632d0b14a8e4f2497b40d9c2545f Mon Sep 17 00:00:00 2001 From: Ryan Davis Date: Tue, 28 Jan 2020 12:11:58 -0800 Subject: [PATCH] Fix platform on apache_conf to include all unix. Now discovers the first available conf file from a list of known paths. Might have to expand based on various distros. Had to tweak the tests because the mock loader mocks EVERYTHING every time. :/ Signed-off-by: Ryan Davis --- lib/inspec/resources/apache_conf.rb | 17 +++++++++-------- test/unit/resources/apache_conf_test.rb | 7 +++++-- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/lib/inspec/resources/apache_conf.rb b/lib/inspec/resources/apache_conf.rb index 3fd4b9d8e..825aa7e9b 100644 --- a/lib/inspec/resources/apache_conf.rb +++ b/lib/inspec/resources/apache_conf.rb @@ -7,9 +7,9 @@ require "inspec/utils/file_reader" module Inspec::Resources class ApacheConf < Inspec.resource(1) name "apache_conf" - supports platform: "linux" - supports platform: "debian" - desc "Use the apache_conf InSpec audit resource to test the configuration settings for Apache. This file is typically located under /etc/apache2 on the Debian and Ubuntu platforms and under /etc/httpd on the Fedora, CentOS, Red Hat Enterprise Linux, and Arch Linux platforms. The configuration settings may vary significantly from platform to platform." + supports platform: "unix" + + desc "Use the apache_conf InSpec audit resource to test the configuration settings for Apache. The configuration settings may vary significantly from platform to platform." example <<~EXAMPLE describe apache_conf do its('setting_name') { should eq 'value' } @@ -145,12 +145,13 @@ module Inspec::Resources private + PATHS = ["/etc/apache2/apache2.conf", + "/etc/httpd/conf/httpd.conf"] + .map(&:freeze) + .freeze + def default_conf_path - if inspec.os.debian? - "/etc/apache2/apache2.conf" - else - "/etc/httpd/conf/httpd.conf" - end + @default ||= PATHS.find { |path| inspec.file(path).exist? } end end end diff --git a/test/unit/resources/apache_conf_test.rb b/test/unit/resources/apache_conf_test.rb index 4a06409d4..f5e5ef0d3 100644 --- a/test/unit/resources/apache_conf_test.rb +++ b/test/unit/resources/apache_conf_test.rb @@ -6,7 +6,8 @@ require "hashie" describe "Inspec::Resources::ApacheConf" do # debian style apache2 it "reads values in apache2.conf and from Include, IncludeOptional params" do - resource = MockLoader.new(:ubuntu1404).load_resource("apache_conf") + resource = MockLoader.new(:ubuntu1404).load_resource("apache_conf", + "/etc/apache2/apache2.conf") _(resource.params).must_be_kind_of Hash _(resource.content).must_be_kind_of String _(resource.params("ServerRoot")).must_equal ["/etc/apache2"] @@ -22,7 +23,9 @@ describe "Inspec::Resources::ApacheConf" do # non debian style httpd it "reads values in httpd.conf and from Include, IncludeOptional params" do - resource = MockLoader.new(:centos6).load_resource("apache_conf") + resource = MockLoader.new(:centos6).load_resource("apache_conf", + "/etc/httpd/conf/httpd.conf") + _(resource.params).must_be_kind_of Hash _(resource.content).must_be_kind_of String _(resource.params("ServerRoot")).must_equal ["/etc/httpd"]