mirror of
https://github.com/inspec/inspec
synced 2024-11-22 12:43:07 +00:00
Merge pull request #6126 from inspec/vasundhara/group_2_resource_id
Adds resource_id to group 2 resources
This commit is contained in:
commit
6385ea9f74
16 changed files with 83 additions and 6 deletions
|
@ -45,6 +45,10 @@ module Inspec::Resources
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def resource_id
|
||||||
|
@package_name || "chocolatey_package"
|
||||||
|
end
|
||||||
|
|
||||||
def to_s
|
def to_s
|
||||||
"Chocolatey package #{package_name}"
|
"Chocolatey package #{package_name}"
|
||||||
end
|
end
|
||||||
|
|
|
@ -34,6 +34,10 @@ module Inspec::Resources
|
||||||
param
|
param
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def resource_id
|
||||||
|
@conf_path || "chrony_conf"
|
||||||
|
end
|
||||||
|
|
||||||
def to_s
|
def to_s
|
||||||
"chrony.conf"
|
"chrony.conf"
|
||||||
end
|
end
|
||||||
|
|
|
@ -93,6 +93,11 @@ module Inspec::Resources
|
||||||
res.exit_status.to_i == 0
|
res.exit_status.to_i == 0
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# to_s method outputs the command which we are using here as UUID to identify resource and also it take cares of Redact output
|
||||||
|
def resource_id
|
||||||
|
to_s || "command"
|
||||||
|
end
|
||||||
|
|
||||||
def to_s
|
def to_s
|
||||||
output = "Command: `#{@command}`"
|
output = "Command: `#{@command}`"
|
||||||
# Redact output if the `redact_regex` option is passed
|
# Redact output if the `redact_regex` option is passed
|
||||||
|
|
|
@ -51,6 +51,10 @@ module Inspec::Resources
|
||||||
info[:version]
|
info[:version]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def resource_id
|
||||||
|
@package_name || "cpan"
|
||||||
|
end
|
||||||
|
|
||||||
def to_s
|
def to_s
|
||||||
"Perl Module #{@package_name}"
|
"Perl Module #{@package_name}"
|
||||||
end
|
end
|
||||||
|
|
|
@ -57,6 +57,10 @@ module Inspec::Resources
|
||||||
info[:version]
|
info[:version]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def resource_id
|
||||||
|
@package_name || "cran"
|
||||||
|
end
|
||||||
|
|
||||||
def to_s
|
def to_s
|
||||||
"R Module #{@package_name}"
|
"R Module #{@package_name}"
|
||||||
end
|
end
|
||||||
|
|
|
@ -38,6 +38,11 @@ module Inspec::Resources
|
||||||
@params.include?(rule)
|
@params.include?(rule)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def resource_id
|
||||||
|
user = @user || "current user"
|
||||||
|
"cron #{user}"
|
||||||
|
end
|
||||||
|
|
||||||
def to_s
|
def to_s
|
||||||
if is_user_crontab?
|
if is_user_crontab?
|
||||||
"cron for user #{@user}"
|
"cron for user #{@user}"
|
||||||
|
|
|
@ -19,7 +19,8 @@ module Inspec::Resources
|
||||||
|
|
||||||
def initialize(path, headers = true)
|
def initialize(path, headers = true)
|
||||||
@headers = headers
|
@headers = headers
|
||||||
super(path)
|
@path = path
|
||||||
|
super(@path)
|
||||||
end
|
end
|
||||||
|
|
||||||
# override the parse method from JsonConfig
|
# override the parse method from JsonConfig
|
||||||
|
@ -68,6 +69,10 @@ module Inspec::Resources
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def resource_id
|
||||||
|
@path || "csv"
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
# used by JsonConfig to build up a full to_s method
|
# used by JsonConfig to build up a full to_s method
|
||||||
|
|
|
@ -76,6 +76,10 @@ module Inspec::Resources
|
||||||
@dh_params.params_ok?
|
@dh_params.params_ok?
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def resource_id
|
||||||
|
@dh_params_path || "dh_params"
|
||||||
|
end
|
||||||
|
|
||||||
def to_s
|
def to_s
|
||||||
"dh_params #{@dh_params_path}"
|
"dh_params #{@dh_params_path}"
|
||||||
end
|
end
|
||||||
|
|
|
@ -6,6 +6,7 @@ describe "Inspec::Resources::ChocoPkg" do
|
||||||
it "can parse output from `choco` when package is installed" do
|
it "can parse output from `choco` when package is installed" do
|
||||||
pkg = { name: "git", installed: false, version: nil, type: "chocolatey" }
|
pkg = { name: "git", installed: false, version: nil, type: "chocolatey" }
|
||||||
resource = MockLoader.new(:windows).load_resource("chocolatey_package", "git")
|
resource = MockLoader.new(:windows).load_resource("chocolatey_package", "git")
|
||||||
|
_(resource.resource_id).must_equal "git"
|
||||||
_(resource.installed?).must_equal pkg[:installed]
|
_(resource.installed?).must_equal pkg[:installed]
|
||||||
_(resource.version).must_be_nil
|
_(resource.version).must_be_nil
|
||||||
_(resource.info).must_equal pkg
|
_(resource.info).must_equal pkg
|
||||||
|
@ -18,4 +19,9 @@ describe "Inspec::Resources::ChocoPkg" do
|
||||||
_(resource.version).must_equal pkg[:version]
|
_(resource.version).must_equal pkg[:version]
|
||||||
_(resource.info).must_equal pkg
|
_(resource.info).must_equal pkg
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "gets the resource_id for the current resource" do
|
||||||
|
resource = MockLoader.new(:windows).load_resource("chocolatey_package", "nssm")
|
||||||
|
_(resource.resource_id).must_equal "nssm"
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -15,4 +15,9 @@ describe "Inspec::Resources::ChronyConf" do
|
||||||
}
|
}
|
||||||
assert_nil resource.allow
|
assert_nil resource.allow
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "gets resource_id for the current resource" do
|
||||||
|
resource = load_resource("chrony_conf")
|
||||||
|
_(resource.resource_id).must_equal "/etc/chrony.conf"
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -14,10 +14,12 @@ describe Inspec::Resources::Cmd do
|
||||||
end
|
end
|
||||||
|
|
||||||
it "runs a valid mocked command" do
|
it "runs a valid mocked command" do
|
||||||
_(resource("env").result).wont_be_nil
|
resource = load_resource("command", "env")
|
||||||
_(resource("env").stdout).must_include "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin\n"
|
_(resource.resource_id).must_equal "Command: `env`"
|
||||||
_(resource("env").stderr).must_equal ""
|
_(resource.result).wont_be_nil
|
||||||
_(resource("env").exit_status).must_equal 0
|
_(resource.stdout).must_include "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin\n"
|
||||||
|
_(resource.stderr).must_equal ""
|
||||||
|
_(resource.exit_status).must_equal 0
|
||||||
end
|
end
|
||||||
|
|
||||||
it "exist? returns false on nil os name" do
|
it "exist? returns false on nil os name" do
|
||||||
|
@ -42,8 +44,10 @@ describe Inspec::Resources::Cmd do
|
||||||
|
|
||||||
it "redacts output if `redact_regex` is passed with capture groups" do
|
it "redacts output if `redact_regex` is passed with capture groups" do
|
||||||
cmd = "command_with_password -p supersecret -d no_redact"
|
cmd = "command_with_password -p supersecret -d no_redact"
|
||||||
|
resource = load_resource("command", cmd, redact_regex: /(-p ).*( -d)/)
|
||||||
expected_to_s = "Command: `command_with_password -p REDACTED -d no_redact`"
|
expected_to_s = "Command: `command_with_password -p REDACTED -d no_redact`"
|
||||||
_(resource(cmd, redact_regex: /(-p ).*( -d)/).to_s).must_equal(expected_to_s)
|
_(resource.resource_id).must_equal(expected_to_s)
|
||||||
|
_(resource.to_s).must_equal(expected_to_s)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "redacts output if `redact_regex` is passed without a capture group" do
|
it "redacts output if `redact_regex` is passed without a capture group" do
|
||||||
|
|
|
@ -18,4 +18,8 @@ describe "Inspec::Resources::Cpan" do
|
||||||
_(resource.info[:type]).must_equal "cpan"
|
_(resource.info[:type]).must_equal "cpan"
|
||||||
_(resource.info).must_equal pkg
|
_(resource.info).must_equal pkg
|
||||||
end
|
end
|
||||||
|
it "gets the resource_id for the current resource" do
|
||||||
|
resource = load_resource("cpan", "DBD::Pg")
|
||||||
|
_(resource.resource_id).must_equal "DBD::Pg"
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -16,4 +16,8 @@ describe "Inspec::Resources::Cran" do
|
||||||
_(resource.info[:name]).must_equal "DoesNotExist"
|
_(resource.info[:name]).must_equal "DoesNotExist"
|
||||||
_(resource.info[:type]).must_equal "cran"
|
_(resource.info[:type]).must_equal "cran"
|
||||||
end
|
end
|
||||||
|
it "gets resource_id for the current resource" do
|
||||||
|
resource = load_resource("cran", "DBI")
|
||||||
|
_(resource.resource_id).must_equal "DBI"
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -36,4 +36,15 @@ describe "Inspec::Resources::Cron" do
|
||||||
_(resource.resource_exception_message).must_include "Error while executing crontab -l -u testuser command:"
|
_(resource.resource_exception_message).must_include "Error while executing crontab -l -u testuser command:"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe "resource_id" do
|
||||||
|
it "generates the resource_id for the current resouce if user is not specified" do
|
||||||
|
_(cron.resource_id).must_equal "cron current user"
|
||||||
|
end
|
||||||
|
|
||||||
|
it "generates the resource_id for the current resouce if user is specified" do
|
||||||
|
resource = load_resource("cron", { user: "testuser" })
|
||||||
|
_(resource.resource_id).must_equal "cron testuser"
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -9,6 +9,10 @@ describe "Inspec::Resources::CSV" do
|
||||||
{}
|
{}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "gets the resource_id for the current resource" do
|
||||||
|
_(resource.resource_id).must_equal "example.csv"
|
||||||
|
end
|
||||||
|
|
||||||
it "captures an array of params" do
|
it "captures an array of params" do
|
||||||
_(resource.params).must_be_kind_of Array
|
_(resource.params).must_be_kind_of Array
|
||||||
end
|
end
|
||||||
|
|
|
@ -71,6 +71,10 @@ describe "Inspec::Resources::DhParams" do
|
||||||
EOF
|
EOF
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "gets the resource_id for the current resource" do
|
||||||
|
_(resource_dh_params.resource_id).must_equal "dh_params.dh_pem"
|
||||||
|
end
|
||||||
|
|
||||||
it "parses the generator used for the Diffie-Hellman operation" do
|
it "parses the generator used for the Diffie-Hellman operation" do
|
||||||
_(resource_dh_params.send("generator")).must_equal 2
|
_(resource_dh_params.send("generator")).must_equal 2
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue