2015-10-07 11:13:37 +00:00
|
|
|
# author: Christoph Hartmann
|
|
|
|
# author: Dominik Richter
|
|
|
|
|
|
|
|
require 'helper'
|
2015-10-26 03:04:18 +00:00
|
|
|
require 'inspec/resource'
|
2015-10-07 11:13:37 +00:00
|
|
|
|
2018-03-29 15:57:15 +00:00
|
|
|
describe 'Inspec::Resources::PowershellScript' do
|
|
|
|
let(:base64_command) {
|
|
|
|
# Encoded version of `$ProgressPreference='SilentlyContinue';Get-Help`
|
|
|
|
'JABQAHIAbwBnAHIAZQBzAHMAUAByAGUAZgBlAHIAZQBuAGMAZQA9ACcAUwBpAGwA' \
|
|
|
|
'ZQBuAHQAbAB5AEMAbwBuAHQAaQBuAHUAZQAnADsARwBlAHQALQBIAGUAbABwAA=='
|
|
|
|
}
|
2015-10-07 11:13:37 +00:00
|
|
|
|
2018-03-29 15:57:15 +00:00
|
|
|
it 'properly generates command' do
|
|
|
|
resource = MockLoader.new(:windows).load_resource('powershell', 'Get-Help')
|
|
|
|
_(resource.command).must_equal 'Get-Help'
|
2015-10-07 11:13:37 +00:00
|
|
|
|
2018-03-29 15:57:15 +00:00
|
|
|
resource = MockLoader.new(:osx104).load_resource('powershell', 'Get-Help')
|
|
|
|
_(resource.command).must_equal("pwsh -encodedCommand '#{base64_command}'")
|
2016-03-18 14:47:00 +00:00
|
|
|
end
|
|
|
|
|
2019-02-21 17:24:19 +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-02-21 17:24:19 +00:00
|
|
|
resource = MockLoader.new(:windows).load_resource('script', 'Get-Help')
|
|
|
|
_(resource.command).must_equal 'Get-Help'
|
|
|
|
end
|
2019-04-16 21:28:39 +00:00
|
|
|
expect_deprecation(:resource_script) do
|
2019-02-21 17:24:19 +00:00
|
|
|
resource = MockLoader.new(:osx104).load_resource('script', 'Get-Help')
|
|
|
|
_(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
|