diff --git a/lib/inspec/resources/powershell.rb b/lib/inspec/resources/powershell.rb index 17bb5973c..a462f99ff 100644 --- a/lib/inspec/resources/powershell.rb +++ b/lib/inspec/resources/powershell.rb @@ -49,6 +49,10 @@ module Inspec::Resources def to_s "Powershell" end + + def resource_id + "Powershell" + end end PowershellScript = Powershell diff --git a/lib/inspec/resources/rabbitmq_config.rb b/lib/inspec/resources/rabbitmq_config.rb index d13a2eec3..315216302 100644 --- a/lib/inspec/resources/rabbitmq_config.rb +++ b/lib/inspec/resources/rabbitmq_config.rb @@ -32,6 +32,10 @@ module Inspec::Resources "rabbitmq_config #{@conf_path}" end + def resource_id + @conf_path + end + private def read_content diff --git a/lib/inspec/resources/registry_key.rb b/lib/inspec/resources/registry_key.rb index 18abfc910..9e15016dc 100644 --- a/lib/inspec/resources/registry_key.rb +++ b/lib/inspec/resources/registry_key.rb @@ -140,6 +140,10 @@ module Inspec::Resources "Registry Key #{@options[:name]}" end + def resource_id + @options[:path] + end + private def prep_prop(property) diff --git a/lib/inspec/resources/security_identifier.rb b/lib/inspec/resources/security_identifier.rb index ebd697bae..c434901d9 100644 --- a/lib/inspec/resources/security_identifier.rb +++ b/lib/inspec/resources/security_identifier.rb @@ -51,6 +51,10 @@ module Inspec::Resources "Security Identifier" end + def resource_id + @name + end + private def fetch_sids diff --git a/lib/inspec/resources/security_policy.rb b/lib/inspec/resources/security_policy.rb index 2bf7832dd..ebaf089bb 100644 --- a/lib/inspec/resources/security_policy.rb +++ b/lib/inspec/resources/security_policy.rb @@ -112,6 +112,10 @@ module Inspec::Resources "Security Policy" end + def resource_id + "Security Policy" + end + private def read_content diff --git a/lib/inspec/resources/service.rb b/lib/inspec/resources/service.rb index 4ac371918..8c12bd12e 100644 --- a/lib/inspec/resources/service.rb +++ b/lib/inspec/resources/service.rb @@ -305,6 +305,10 @@ module Inspec::Resources "Service #{@service_name}" end + def resource_id + @service_name + end + private :info end diff --git a/test/unit/resources/powershell_test.rb b/test/unit/resources/powershell_test.rb index b15a82a28..20ab08366 100644 --- a/test/unit/resources/powershell_test.rb +++ b/test/unit/resources/powershell_test.rb @@ -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 diff --git a/test/unit/resources/rabbitmq_conf_test.rb b/test/unit/resources/rabbitmq_conf_test.rb index c37ee3bca..9c3edaf0f 100644 --- a/test/unit/resources/rabbitmq_conf_test.rb +++ b/test/unit/resources/rabbitmq_conf_test.rb @@ -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 diff --git a/test/unit/resources/registry_key_test.rb b/test/unit/resources/registry_key_test.rb index 608a547de..96a9f1b71 100644 --- a/test/unit/resources/registry_key_test.rb +++ b/test/unit/resources/registry_key_test.rb @@ -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 diff --git a/test/unit/resources/security_identifier_test.rb b/test/unit/resources/security_identifier_test.rb index 51db7c97c..ab96b2cf2 100644 --- a/test/unit/resources/security_identifier_test.rb +++ b/test/unit/resources/security_identifier_test.rb @@ -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 diff --git a/test/unit/resources/security_policy_test.rb b/test/unit/resources/security_policy_test.rb index 9e1df2530..748172c7f 100644 --- a/test/unit/resources/security_policy_test.rb +++ b/test/unit/resources/security_policy_test.rb @@ -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