CFINSPEC-80: Improve grep to match sentence starting with alias followed by :

Signed-off-by: Sonu Saha <sonu.saha@progress.com>
This commit is contained in:
Sonu Saha 2022-03-31 15:07:06 +05:30
parent af7ed7bc15
commit 853afe2244
2 changed files with 2 additions and 2 deletions

View file

@ -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

View file

@ -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"),