From 853afe2244e07489e43c50d0e2eb5c0e64670f69 Mon Sep 17 00:00:00 2001 From: Sonu Saha Date: Thu, 31 Mar 2022 15:07:06 +0530 Subject: [PATCH] CFINSPEC-80: Improve grep to match sentence starting with alias followed by : Signed-off-by: Sonu Saha --- lib/inspec/resources/mail_alias.rb | 2 +- test/helpers/mock_loader.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/inspec/resources/mail_alias.rb b/lib/inspec/resources/mail_alias.rb index 5e12f08ae..3b361cdf2 100644 --- a/lib/inspec/resources/mail_alias.rb +++ b/lib/inspec/resources/mail_alias.rb @@ -34,7 +34,7 @@ module Inspec::Resources # aliased_to matcher checks if the given alias_value is set to the initialized alias_key def aliased_to?(alias_value) # /etc/aliases if the file where the alias and its value(s) are stored - cmd = inspec.command("cat /etc/aliases | grep #{@alias_key}") + cmd = inspec.command("cat /etc/aliases | grep '^#{@alias_key}:'") raise Inspec::Exceptions::ResourceFailed, "#{@alias_key} is not a valid key in the aliases" if cmd.exit_status.to_i != 0 # in general aliases file contains : separated values like alias_key : alias_value1, alias_value2 diff --git a/test/helpers/mock_loader.rb b/test/helpers/mock_loader.rb index e8d860b59..b404436fc 100644 --- a/test/helpers/mock_loader.rb +++ b/test/helpers/mock_loader.rb @@ -384,7 +384,7 @@ class MockLoader "cgget -n -r memory.stat carrotking" => cmd.call("cgget-n-r-stat"), %{sh -c 'type "cgget"'} => empty.call, # mail_alias - "cat /etc/aliases | grep daemon" => cmd.call("mail-alias"), + "cat /etc/aliases | grep '^daemon:'" => cmd.call("mail-alias"), # apache_conf "sh -c 'find /etc/apache2/ports.conf -type f -maxdepth 1'" => cmd.call("find-apache2-ports-conf"), "sh -c 'find /etc/httpd/conf.d/*.conf -type f -maxdepth 1'" => cmd.call("find-httpd-ssl-conf"),