2019-06-11 22:24:35 +00:00
|
|
|
require "helper"
|
|
|
|
require "inspec/resource"
|
|
|
|
require "inspec/resources/registry_key"
|
2015-09-05 20:36:12 +00:00
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
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')
|
2015-09-22 16:33:05 +00:00
|
|
|
_(resource.Start).must_equal 2
|
|
|
|
end
|
2015-09-05 20:36:12 +00:00
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
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')
|
2015-09-22 16:33:05 +00:00
|
|
|
_(resource_without_name.Start).must_equal 2
|
2015-09-05 20:36:12 +00:00
|
|
|
end
|
2017-04-07 14:09:51 +00:00
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
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')
|
2017-09-19 16:26:53 +00:00
|
|
|
_(resource.send(:[], "key.with.period")).must_equal 12345
|
|
|
|
end
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
it "generates a proper path from options" do
|
2017-04-07 14:09:51 +00:00
|
|
|
resource = MockLoader.new(:windows).load_resource(
|
2019-06-11 22:24:35 +00:00
|
|
|
"registry_key",
|
|
|
|
"Test 1",
|
|
|
|
{ hive: "my_hive", key: '\\my_prefixed_key' }
|
2017-04-07 14:09:51 +00:00
|
|
|
)
|
|
|
|
_(resource.send(:generate_registry_key_path_from_options)).must_equal 'my_hive\\my_prefixed_key'
|
|
|
|
end
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
it "generates a proper path from options when the key has no leading slash" do
|
2017-04-07 14:09:51 +00:00
|
|
|
resource = MockLoader.new(:windows).load_resource(
|
2019-06-11 22:24:35 +00:00
|
|
|
"registry_key",
|
|
|
|
"Test 1",
|
|
|
|
{ hive: "my_hive", key: "key_with_no_slash" }
|
2017-04-07 14:09:51 +00:00
|
|
|
)
|
|
|
|
_(resource.send(:generate_registry_key_path_from_options)).must_equal 'my_hive\\key_with_no_slash'
|
|
|
|
end
|
|
|
|
|
2015-09-05 20:36:12 +00:00
|
|
|
end
|