Merge pull request #6115 from inspec/nm/add-resource-id-group-10

CFINSPEC 271 Group10 - Added resource_id in resources
This commit is contained in:
Clinton Wolfe 2022-06-08 16:11:42 -04:00 committed by GitHub
commit dd258e3926
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 41 additions and 0 deletions

View file

@ -49,6 +49,10 @@ module Inspec::Resources
def to_s
"Powershell"
end
def resource_id
"Powershell"
end
end
PowershellScript = Powershell

View file

@ -32,6 +32,10 @@ module Inspec::Resources
"rabbitmq_config #{@conf_path}"
end
def resource_id
@conf_path
end
private
def read_content

View file

@ -140,6 +140,10 @@ module Inspec::Resources
"Registry Key #{@options[:name]}"
end
def resource_id
@options[:path]
end
private
def prep_prop(property)

View file

@ -51,6 +51,10 @@ module Inspec::Resources
"Security Identifier"
end
def resource_id
@name
end
private
def fetch_sids

View file

@ -112,6 +112,10 @@ module Inspec::Resources
"Security Policy"
end
def resource_id
"Security Policy"
end
private
def read_content

View file

@ -305,6 +305,10 @@ module Inspec::Resources
"Service #{@service_name}"
end
def resource_id
@service_name
end
private :info
end

View file

@ -12,9 +12,11 @@ describe "Inspec::Resources::Powershell" do
it "properly generates command" do
resource = MockLoader.new(:windows).load_resource("powershell", "Get-Help")
_(resource.command).must_equal "Get-Help"
_(resource.resource_id).must_equal "Powershell"
resource = MockLoader.new(:macos10_10).load_resource("powershell", "Get-Help")
_(resource.command).must_equal("pwsh -encodedCommand '#{base64_command}'")
_(resource.resource_id).must_equal "Powershell"
end
it "properly generates command if deprecated `script` is used" do

View file

@ -9,6 +9,7 @@ describe "Inspec::Resources::RabbitmqConf" do
resource = load_resource("rabbitmq_config")
_(resource.params("rabbit", "ssl_listeners")).must_equal [5671]
_(resource.params("rabbit", "tcp_listeners")).must_equal({ "127.0.0.1" => 5672, "::1" => 5672 })
_(resource.resource_id).must_equal "/etc/rabbitmq/rabbitmq.config"
end
end
end

View file

@ -6,16 +6,19 @@ describe "Inspec::Resources::RegistryKey" do
it "read reg key with human readable name" do
resource = MockLoader.new(:windows).load_resource("registry_key", "Task Scheduler", 'HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\Schedule')
_(resource.Start).must_equal 2
_(resource.resource_id).must_equal "HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\services\\Schedule"
end
it "read reg key without human readable name" do
resource_without_name = MockLoader.new(:windows).load_resource("registry_key", 'HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\Schedule')
_(resource_without_name.Start).must_equal 2
_(resource_without_name.resource_id).must_equal "HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\services\\Schedule"
end
it "supports array syntax for keys with periods in them" do
resource = MockLoader.new(:windows).load_resource("registry_key", 'HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\Schedule')
_(resource.send(:[], "key.with.period")).must_equal 12345
_(resource.resource_id).must_equal "HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\services\\Schedule"
end
it "generates a proper path from options" do
@ -25,6 +28,7 @@ describe "Inspec::Resources::RegistryKey" do
{ hive: "my_hive", key: '\\my_prefixed_key' }
)
_(resource.send(:generate_registry_key_path_from_options)).must_equal 'my_hive\\my_prefixed_key'
_(resource.resource_id).must_equal "my_hive\\my_prefixed_key"
end
it "generates a proper path from options when the key has no leading slash" do
@ -34,6 +38,7 @@ describe "Inspec::Resources::RegistryKey" do
{ hive: "my_hive", key: "key_with_no_slash" }
)
_(resource.send(:generate_registry_key_path_from_options)).must_equal 'my_hive\\key_with_no_slash'
_(resource.resource_id).must_equal "my_hive\\key_with_no_slash"
end
it "returns user permissions values" do
@ -41,6 +46,7 @@ describe "Inspec::Resources::RegistryKey" do
resource.stubs(:exist?).returns(true)
resource.stubs(:user_permissions).returns({ "NT AUTHORITY\\SYSTEM" => "FullControl", "NT AUTHORITY\\Authenticated Users" => "ReadAndExecute", "BUILTIN\\Administrators" => "FullControl" })
_(resource.user_permissions).must_equal({ "NT AUTHORITY\\SYSTEM" => "FullControl", "NT AUTHORITY\\Authenticated Users" => "ReadAndExecute", "BUILTIN\\Administrators" => "FullControl" })
_(resource.resource_id).must_equal "HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\services\\Schedule"
end
it "returns true if file has inherit enabled on Windows." do
@ -48,5 +54,6 @@ describe "Inspec::Resources::RegistryKey" do
resource.stubs(:exist?).returns(true)
resource.stubs(:inherited?).returns(true)
_(resource.inherited?).must_equal true
_(resource.resource_id).must_equal "HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\services\\Schedule"
end
end

View file

@ -7,36 +7,42 @@ describe "Inspec::Resources::SecurityIdentifier" do
resource = load_resource("security_identifier", { user: "Alice" })
_(resource.exist?).must_equal true
_(resource.sid).must_equal "S-1-5-21-1601936709-1892662786-3840804712-315762"
_(resource.resource_id).must_equal "Alice"
end
it "returns nil for a non-existent user" do
resource = MockLoader.new(:windows).load_resource("security_identifier", { user: "Bob" })
_(resource.exist?).must_equal false
_(resource.sid).must_be_nil
_(resource.resource_id).must_equal "Bob"
end
it "returns a SID for an existing group" do
resource = load_resource("security_identifier", { group: "Guests" })
_(resource.exist?).must_equal true
_(resource.sid).must_equal "S-1-5-32-546"
_(resource.resource_id).must_equal "Guests"
end
it "returns nil for a non-existent group" do
resource = MockLoader.new(:windows).load_resource("security_identifier", { group: "DontExist" })
_(resource.exist?).must_equal false
_(resource.sid).must_be_nil
_(resource.resource_id).must_equal "DontExist"
end
it "returns a SID for an existing entity with type :unspecified" do
resource = load_resource("security_identifier", { unspecified: "Guests" })
_(resource.exist?).must_equal true
_(resource.sid).must_equal "S-1-5-32-546"
_(resource.resource_id).must_equal "Guests"
end
it "returns nil for a non-existent entity with type :unspecified" do
resource = MockLoader.new(:windows).load_resource("security_identifier", { unspecified: "DontExist" })
_(resource.exist?).must_equal false
_(resource.sid).must_be_nil
_(resource.resource_id).must_equal "DontExist"
end
it "raises ArgumentError for an unsupported type" do

View file

@ -12,6 +12,7 @@ describe "Inspec::Resources::SecurityPolicy" do
_(resource.SeUndockPrivilege).must_equal ["S-1-5-32-544"]
_(resource.SeRemoteInteractiveLogonRight).must_equal ["S-1-5-32-544", "S-1-5-32-555"]
_(resource.SeServiceLogonRight).must_equal %w{ DB2ADMNS db2admin }
_(resource.resource_id).must_equal "Security Policy"
end
it "parse empty policy file" do