From 1e94e3503eb2d80949522652e90bedb40e917634 Mon Sep 17 00:00:00 2001 From: Lance Albertson Date: Tue, 3 Sep 2019 15:22:32 -0700 Subject: [PATCH] Fix for postfix_conf when using a non-standard config location Pass the first argument of the opts array instead of the whole array which confuses the SimpleConfig parser. Also added a test which verifies this fixes the issue. In addition, change the base_name to something that matches other resource base names. Signed-off-by: Lance Albertson --- lib/inspec/resources/postfix_conf.rb | 4 ++-- test/helpers/mock_loader.rb | 1 + test/unit/mock/files/other.cf | 4 ++++ test/unit/resources/postfix_conf_test.rb | 7 +++++++ 4 files changed, 14 insertions(+), 2 deletions(-) create mode 100644 test/unit/mock/files/other.cf diff --git a/lib/inspec/resources/postfix_conf.rb b/lib/inspec/resources/postfix_conf.rb index e1c625921..6c1f4f25d 100644 --- a/lib/inspec/resources/postfix_conf.rb +++ b/lib/inspec/resources/postfix_conf.rb @@ -11,7 +11,7 @@ module Inspec::Resources def initialize(*opts) @params = {} if opts.length == 1 - @raw_content = load_raw_content(opts) + @raw_content = load_raw_content(opts[0]) else @raw_content = load_raw_content("/etc/postfix/main.cf") end @@ -25,7 +25,7 @@ module Inspec::Resources private def resource_base_name - "POSTFIX_CONF" + "Postfix Config" end end end diff --git a/test/helpers/mock_loader.rb b/test/helpers/mock_loader.rb index 629191c25..b973dbcfc 100644 --- a/test/helpers/mock_loader.rb +++ b/test/helpers/mock_loader.rb @@ -160,6 +160,7 @@ class MockLoader "C:/fakepath/fakefile" => emptyfile.call, "/etc/cron.d/crondotd" => mockfile.call("crondotd"), "/etc/postfix/main.cf" => mockfile.call("main.cf"), + "/etc/postfix/other.cf" => mockfile.call("other.cf"), } # create all mock commands diff --git a/test/unit/mock/files/other.cf b/test/unit/mock/files/other.cf new file mode 100644 index 000000000..cb90915b3 --- /dev/null +++ b/test/unit/mock/files/other.cf @@ -0,0 +1,4 @@ +# Test other configuration for Postfix + +test_parameter_other = value +other_test_param_other = $value diff --git a/test/unit/resources/postfix_conf_test.rb b/test/unit/resources/postfix_conf_test.rb index 15ceadfc4..c77882870 100644 --- a/test/unit/resources/postfix_conf_test.rb +++ b/test/unit/resources/postfix_conf_test.rb @@ -10,4 +10,11 @@ describe "Inspec::Resources::Postfix_Conf" do _(resource.params).must_equal result _(resource.value(%w{test_parameter})).must_equal "value" end + + it "Test default parsing of other.cf on Centos 7" do + resource = MockLoader.new(:centos7).load_resource("postfix_conf", "/etc/postfix/other.cf") + result = { "test_parameter_other" => "value", "other_test_param_other" => "$value" } + _(resource.params).must_equal result + _(resource.value(%w{test_parameter_other})).must_equal "value" + end end