2019-06-11 22:24:35 +00:00
|
|
|
require "helper"
|
|
|
|
require "inspec/resource"
|
|
|
|
require "inspec/resources/powershell"
|
2015-10-07 11:13:37 +00:00
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
describe "Inspec::Resources::Powershell" do
|
|
|
|
let(:base64_command) do
|
2018-03-29 15:57:15 +00:00
|
|
|
# Encoded version of `$ProgressPreference='SilentlyContinue';Get-Help`
|
2019-06-11 22:24:35 +00:00
|
|
|
"JABQAHIAbwBnAHIAZQBzAHMAUAByAGUAZgBlAHIAZQBuAGMAZQA9ACcAUwBpAGwA" \
|
|
|
|
"ZQBuAHQAbAB5AEMAbwBuAHQAaQBuAHUAZQAnADsARwBlAHQALQBIAGUAbABwAA=="
|
|
|
|
end
|
2015-10-07 11:13:37 +00:00
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
it "properly generates command" do
|
|
|
|
resource = MockLoader.new(:windows).load_resource("powershell", "Get-Help")
|
|
|
|
_(resource.command).must_equal "Get-Help"
|
2022-06-03 11:37:43 +00:00
|
|
|
_(resource.resource_id).must_equal "Powershell"
|
2015-10-07 11:13:37 +00:00
|
|
|
|
2020-07-01 22:35:23 +00:00
|
|
|
resource = MockLoader.new(:macos10_10).load_resource("powershell", "Get-Help")
|
2018-03-29 15:57:15 +00:00
|
|
|
_(resource.command).must_equal("pwsh -encodedCommand '#{base64_command}'")
|
2022-06-03 11:37:43 +00:00
|
|
|
_(resource.resource_id).must_equal "Powershell"
|
2016-03-18 14:47:00 +00:00
|
|
|
end
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
it "properly generates command if deprecated `script` is used" do
|
2019-04-16 21:28:39 +00:00
|
|
|
expect_deprecation(:resource_script) do
|
2019-06-11 22:24:35 +00:00
|
|
|
resource = MockLoader.new(:windows).load_resource("script", "Get-Help")
|
|
|
|
_(resource.command).must_equal "Get-Help"
|
2019-02-21 17:24:19 +00:00
|
|
|
end
|
2019-04-16 21:28:39 +00:00
|
|
|
expect_deprecation(:resource_script) do
|
2020-07-01 22:35:23 +00:00
|
|
|
resource = MockLoader.new(:macos10_10).load_resource("script", "Get-Help")
|
2019-02-21 17:24:19 +00:00
|
|
|
_(resource.command).must_equal("pwsh -encodedCommand '#{base64_command}'")
|
|
|
|
end
|
2017-05-30 16:36:15 +00:00
|
|
|
end
|
2015-10-07 11:13:37 +00:00
|
|
|
end
|