CFINSPEC-262 Adds resource_id to aide_conf, apache_conf, apt, audit_policy, auditd_conf, bash, bond, bridge, cassandradb_conf, cassandradb_session resources and unit test for the same

Signed-off-by: Vasu1105 <vasundhara.jagdale@chef.io>
This commit is contained in:
Vasu1105 2022-06-02 13:36:58 +05:30
parent f2943b7bc8
commit 1c66679e46
22 changed files with 69 additions and 1 deletions

View file

@ -48,6 +48,10 @@ module Inspec::Resources
filter.install_filter_methods_on_resource(self, :params)
def resource_id
@conf_path
end
def to_s
"AIDE Config"
end

View file

@ -40,6 +40,10 @@ module Inspec::Resources
end
end
def resource_id
@conf_path
end
def to_s
"Apache Environment"
end

View file

@ -124,6 +124,10 @@ module Inspec::Resources
@params["ServerRoot"] || @params["serverroot"]
end
def resource_id
@conf_path
end
def to_s
"Apache Config #{conf_path}"
end

View file

@ -39,10 +39,11 @@ module Inspec::Resources
EXAMPLE
def initialize(ppa_name)
@ppa_name = ppa_name
@deb_url = nil
# check if the os is ubuntu or debian
if inspec.os.debian?
@deb_url = determine_ppa_url(ppa_name)
@deb_url = determine_ppa_url(@ppa_name)
else
# this resource is only supported on ubuntu and debian
skip_resource "The `apt` resource is not supported on your OS yet."
@ -61,6 +62,10 @@ module Inspec::Resources
actives.size == 1 && actives[0] = true
end
def resource_id
@deb_url || @ppa_name || ""
end
def to_s
"Apt Repository #{@deb_url}"
end

View file

@ -57,6 +57,11 @@ module Inspec::Resources
values
end
# Since this resource does not have any unique identifier for resource, sending the Auditpol command as UUID.
def resource_id
"Auditpol"
end
def to_s
"Audit Policy"
end

View file

@ -27,6 +27,10 @@ module Inspec::Resources
read_params[name.to_s]
end
def resource_id
@conf_path
end
def to_s
"Audit Daemon Config"
end

View file

@ -28,6 +28,10 @@ module Inspec::Resources
super(CommandWrapper.wrap(command, options))
end
def resource_id
@raw_command
end
def to_s
"Bash command #{@raw_command}"
end

View file

@ -63,6 +63,10 @@ module Inspec::Resources
params["Bonding Mode"].first
end
def resource_id
@path
end
def to_s
"Bond #{@bond}"
end

View file

@ -45,6 +45,10 @@ module Inspec::Resources
bridge_info.nil? ? nil : bridge_info[:interfaces]
end
def resource_id
@bridge_name
end
def to_s
"Bridge #{@bridge_name}"
end

View file

@ -31,6 +31,11 @@ module Inspec::Resources
super(@conf_path)
end
# if system unables to determine the cassandra conf path the @conf_path can be nil so in that case sending "" string as resource_id
def resource_id
@conf_path || ""
end
private
def parse(content)

View file

@ -44,6 +44,10 @@ module Inspec::Resources
end
end
def resource_id
"cassandradb_session:User:#{@user}:Host:#{host}"
end
def to_s
"Cassandra DB Session"
end

View file

@ -5,6 +5,9 @@ require "inspec/resources/aide_conf"
describe "Inspec::Resources::AideConf" do
describe "AideConf Parameters" do
resource = load_resource("aide_conf")
it "Verify resource_id" do
_(resource.resource_id).must_equal "/etc/aide.conf"
end
it "Verify aide_conf all_have_rule property - true case" do
_(resource.all_have_rule("p")).must_equal true
end

View file

@ -10,6 +10,7 @@ describe "Inspec::Resources::ApacheConf" do
"/etc/apache2/apache2.conf")
_(resource.params).must_be_kind_of Hash
_(resource.content).must_be_kind_of String
_(resource.resource_id).must_equal "/etc/apache2/apache2.conf"
_(resource.params("ServerRoot")).must_equal ["/etc/apache2"]
_(resource.params("ServerAlias")).must_equal ["inspec.test www.inspec.test io.inspec.test"]
_(resource.params("Listen").sort).must_equal %w{443 80}
@ -25,6 +26,7 @@ describe "Inspec::Resources::ApacheConf" do
resource = MockLoader.new(:ubuntu).load_resource("apache_conf", "/etc/test-serverroot/apache2/apache2.conf")
_(resource.params).must_be_kind_of Hash
_(resource.content).must_be_kind_of String
_(resource.resource_id).must_equal "/etc/test-serverroot/apache2/apache2.conf"
_(resource.params("ServerAlias")).must_equal ["inspec.test www.inspec.test io.inspec.test"]
assert_nil(resource.params("ServerRoot"))
assert_nil(resource.params("Listen"))

View file

@ -6,12 +6,14 @@ describe "Inspec::Resources::AptRepo" do
it "check apt on ubuntu" do
resource = MockLoader.new(:ubuntu).load_resource("apt", "http://archive.ubuntu.com/ubuntu/")
_(resource.resource_id).must_equal "http://archive.ubuntu.com/ubuntu/"
_(resource.exists?).must_equal true
_(resource.enabled?).must_equal true
end
it "check apt on ubuntu with ppa" do
resource = MockLoader.new(:ubuntu).load_resource("apt", "ubuntu-wine/ppa")
_(resource.resource_id).must_equal "http://ppa.launchpad.net/ubuntu-wine/ppa/ubuntu"
_(resource.exists?).must_equal true
_(resource.enabled?).must_equal true
end
@ -48,6 +50,7 @@ describe "Inspec::Resources::AptRepo" do
it "check apt on unknown os" do
resource = MockLoader.new(:undefined).load_resource("apt", "ubuntu-wine/ppa")
_(resource.resource_id).must_equal "ubuntu-wine/ppa"
_(resource.exists?).must_equal false
_(resource.enabled?).must_equal false
end

View file

@ -5,6 +5,7 @@ require "inspec/resources/audit_policy"
describe "Inspec::Resources::AuditPolicy" do
it "check audit policy parsing" do
resource = MockLoader.new(:windows).load_resource("audit_policy")
_(resource.resource_id).must_equal "Auditpol"
_(resource.send("User Account Management")).must_equal "Success"
end
end

View file

@ -5,6 +5,7 @@ require "inspec/resources/auditd_conf"
describe "Inspec::Resources::AuditDaemonConf" do
it "check audit daemon config parsing" do
resource = MockLoader.new(:windows).load_resource("auditd_conf")
_(resource.resource_id).must_equal "/etc/audit/auditd.conf"
_(resource.space_left_action).must_equal "SYSLOG"
_(resource.action_mail_acct).must_equal "root"
_(resource.tcp_listen_queue).must_equal "5"

View file

@ -7,6 +7,7 @@ describe "Inspec::Resources::Bash" do
let(:resource) { load_resource("bash", '$("' + x + '")') }
it "prints as a bash command" do
_(resource.resource_id).must_equal "$(\"#{x}\")"
_(resource.to_s).must_equal 'Bash command $("' + x + '")'
end
@ -16,6 +17,7 @@ describe "Inspec::Resources::Bash" do
it "can specify an executable path" do
resource = load_resource("bash", '$("' + x + '")', path: "/bin/bash")
_(resource.resource_id).must_equal "$(\"#{x}\")"
_(resource.command).must_equal "/bin/bash -c \\$\\(\\\"#{x}\\\"\\)"
end

View file

@ -7,6 +7,7 @@ describe "Inspec::Resources::Bond" do
it "check linux bond on ubuntu" do
resource = MockLoader.new(:ubuntu).load_resource("bond", "bond0")
# bond must be available
_(resource.resource_id).must_equal "/proc/net/bonding/bond0"
_(resource.exist?).must_equal true
# get bonding mode
_(resource.mode).must_equal "IEEE 802.3ad Dynamic link aggregation"

View file

@ -6,6 +6,7 @@ describe "Inspec::Resources::Bridge" do
it "check linux bridge on ubuntu" do
resource = MockLoader.new(:ubuntu).load_resource("bridge", "br0")
_(resource.resource_id).must_equal "br0"
_(resource.exists?).must_equal true
# check network interfaced attached to bridge
@ -32,6 +33,7 @@ describe "Inspec::Resources::Bridge" do
it "check windows bridge" do
resource = MockLoader.new(:windows).load_resource("bridge", "Network Bridge")
_(resource.resource_id).must_equal "Network Bridge"
_(resource.exists?).must_equal true
# get associated interfaces is not supported on windows
@ -40,6 +42,7 @@ describe "Inspec::Resources::Bridge" do
it "check bridge on unsupported os" do
resource = MockLoader.new(:undefined).load_resource("bridge", "br0")
_(resource.resource_id).must_equal "br0"
_(resource.exists?).must_equal false
# check network interfaced attached to bridge

View file

@ -5,6 +5,7 @@ require "inspec/resources/cassandradb_conf"
describe "Inspec::Resources::CassandradbConf" do
it "verify configurations of cassandra DB in linux when conf path is passed" do
resource = MockLoader.new(:centos7).load_resource("cassandradb_conf", "/etc/cassandra/cassandra.yaml")
_(resource.resource_id).must_equal "/etc/cassandra/cassandra.yaml"
_(resource.params["listen_address"]).must_equal "localhost"
_(resource.params["native_transport_port"]).must_equal 9042
_(resource.params["audit_logging_options"]["enabled"]).must_equal false

View file

@ -24,6 +24,7 @@ describe "Inspec::Resources::CassandradbSession" do
end
end
_(resource.resource_id).must_equal "cassandradb_session:User:USER:Host:localhost"
_(resource.resource_failed?).must_equal false
query = resource.query("SELECT cluster_name FROM system.local")
_(query.output).must_match(/Test Cluster/)

View file

@ -6,12 +6,14 @@ describe Inspec::Resources::PpaRepository do
it "checks on ubuntu as name/ppa" do
resource = MockLoader.new(:ubuntu).load_resource("ppa", "ubuntu-wine/ppa")
_(resource.resource_id).must_equal "http://ppa.launchpad.net/ubuntu-wine/ppa/ubuntu"
_(resource.exists?).must_equal true
_(resource.enabled?).must_equal true
end
it "checks on ubuntu as ppa:name/ppa" do
resource = MockLoader.new(:ubuntu).load_resource("ppa", "ppa:ubuntu-wine/ppa")
_(resource.resource_id).must_equal "http://ppa.launchpad.net/ubuntu-wine/ppa/ubuntu"
_(resource.exists?).must_equal true
_(resource.enabled?).must_equal true
end
@ -36,6 +38,7 @@ describe Inspec::Resources::PpaRepository do
it "checks on unknown os" do
resource = MockLoader.new(:undefined).load_resource("ppa", "ubuntu-wine/ppa")
_(resource.resource_id).must_equal "ubuntu-wine/ppa"
_(resource.exists?).must_equal false
_(resource.enabled?).must_equal false
end