mirror of
https://github.com/inspec/inspec
synced 2024-11-22 20:53:11 +00:00
CFINSPEC-80: Define aliased_to matcher and add unit test
Signed-off-by: Sonu Saha <sonu.saha@progress.com>
This commit is contained in:
parent
f1f0ecb631
commit
65f4766bec
4 changed files with 19 additions and 15 deletions
|
@ -32,16 +32,11 @@ module Inspec::Resources
|
|||
"mail_alias #{resource_id}"
|
||||
end
|
||||
|
||||
def is_aliased_to?(alias_value)
|
||||
# positive or negative expectations specific to this resource instance
|
||||
true
|
||||
end
|
||||
def aliased_to?(alias_value)
|
||||
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
|
||||
|
||||
private
|
||||
|
||||
# Methods to help the resource's public methods
|
||||
def helper_method
|
||||
# Add anything you need here
|
||||
alias_value == cmd.stdout.split(":").map(&:strip)[1]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
1
test/fixtures/cmd/mail-alias
vendored
Normal file
1
test/fixtures/cmd/mail-alias
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
daemon: root
|
|
@ -383,6 +383,8 @@ class MockLoader
|
|||
"cgget -n -r cpuset.cpus carrotking" => cmd.call("cgget-n-r"),
|
||||
"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"),
|
||||
# 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"),
|
||||
|
|
|
@ -3,18 +3,24 @@ require "#{Inspec.src_root}/test/helper"
|
|||
require_relative "../../../lib/inspec/resources/mail_alias"
|
||||
|
||||
describe Inspec::Resources::Mailalias do
|
||||
it "check mail alias on ubuntu" do
|
||||
it "check mail_alias on ubuntu" do
|
||||
resource = MockLoader.new(:ubuntu).load_resource("mail_alias", "daemon")
|
||||
_(resource.is_aliased_to?("root")).must_equal true
|
||||
_(resource.aliased_to?("root")).must_equal true
|
||||
end
|
||||
|
||||
it "check mail alias on macos" do
|
||||
it "check mail_alias on macos" do
|
||||
resource = MockLoader.new(:macos10_10).load_resource("mail_alias", "daemon")
|
||||
_(resource.is_aliased_to?("root")).must_equal true
|
||||
_(resource.aliased_to?("root")).must_equal true
|
||||
end
|
||||
|
||||
it "check mail alias on freebsd" do
|
||||
it "check mail_alias on freebsd" do
|
||||
resource = MockLoader.new(:freebsd11).load_resource("mail_alias", "daemon")
|
||||
_(resource.is_aliased_to?("root")).must_equal true
|
||||
_(resource.aliased_to?("root")).must_equal true
|
||||
end
|
||||
|
||||
it "check mail_alias on ubuntu with a key that is not included as an alias" do
|
||||
resource = MockLoader.new(:ubuntu).load_resource("mail_alias", "cheesecake")
|
||||
ex = _ { resource.aliased_to?("root") }.must_raise(Inspec::Exceptions::ResourceFailed)
|
||||
_(ex.message).must_include "cheesecake is not a valid key in the aliases"
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue