mirror of
https://github.com/inspec/inspec
synced 2024-11-11 07:34:15 +00:00
2c4f041e9d
This adds `powershell` resource support for non-Windows OSs via `pwsh` and Base64 encoded commands. Signed-off-by: Jerry Aldrich <jerryaldrichiii@gmail.com>
31 lines
1.2 KiB
Ruby
31 lines
1.2 KiB
Ruby
# encoding: utf-8
|
|
# author: Christoph Hartmann
|
|
# author: Dominik Richter
|
|
|
|
require 'helper'
|
|
require 'inspec/resource'
|
|
|
|
describe 'Inspec::Resources::PowershellScript' do
|
|
let(:base64_command) {
|
|
# Encoded version of `$ProgressPreference='SilentlyContinue';Get-Help`
|
|
'JABQAHIAbwBnAHIAZQBzAHMAUAByAGUAZgBlAHIAZQBuAGMAZQA9ACcAUwBpAGwA' \
|
|
'ZQBuAHQAbAB5AEMAbwBuAHQAaQBuAHUAZQAnADsARwBlAHQALQBIAGUAbABwAA=='
|
|
}
|
|
|
|
it 'properly generates command' do
|
|
resource = MockLoader.new(:windows).load_resource('powershell', 'Get-Help')
|
|
_(resource.command).must_equal 'Get-Help'
|
|
|
|
resource = MockLoader.new(:osx104).load_resource('powershell', 'Get-Help')
|
|
_(resource.command).must_equal("pwsh -encodedCommand '#{base64_command}'")
|
|
end
|
|
|
|
it 'properly generates command if deprecated `script` is used on Windows' do
|
|
Inspec::Resources::LegacyPowershellScript.any_instance.stubs(:deprecated)
|
|
resource = MockLoader.new(:windows).load_resource('script', 'Get-Help')
|
|
_(resource.command).must_equal 'Get-Help'
|
|
|
|
resource = MockLoader.new(:osx104).load_resource('script', 'Get-Help')
|
|
_(resource.command).must_equal("pwsh -encodedCommand '#{base64_command}'")
|
|
end
|
|
end
|