mirror of
https://github.com/inspec/inspec
synced 2024-11-23 13:13:22 +00:00
f2d64938b7
* windows_feature resource: Add DISM support This modifies the `windows_feature` resource to fallback to DISM when the `Get-WindowsFeature` command is not available. * Allow specifying `:dism` or `:powershell` * Replace stacktrace with smaller error message * Add notes/todo about raise behavior * Remove duplicated platform check Signed-off-by: Jerry Aldrich <jerryaldrichiii@gmail.com>
67 lines
2.1 KiB
Ruby
67 lines
2.1 KiB
Ruby
# encoding: utf-8
|
|
# author: Christoph Hartmann
|
|
# author: Dominik Richter
|
|
|
|
require 'helper'
|
|
require 'inspec/resource'
|
|
|
|
describe 'Inspec::Resources::WindowsFeature' do
|
|
it 'can retrieve feature info using PowerShell' do
|
|
resource = MockLoader.new(:windows).load_resource(
|
|
'windows_feature',
|
|
'DHCP',
|
|
:powershell,
|
|
)
|
|
params = {
|
|
name: 'DHCP',
|
|
description: 'Dynamic Host Configuration Protocol (DHCP) Server enables you to centrally configure, manage, and provide temporary IP addresses and related information for client computers.',
|
|
installed: false,
|
|
method: :powershell,
|
|
}
|
|
_(resource.info).must_equal params
|
|
_(resource.installed?).must_equal false
|
|
end
|
|
|
|
it 'can retrieve feature info using DISM' do
|
|
resource = MockLoader.new(:windows).load_resource(
|
|
'windows_feature',
|
|
'IIS-WebServer',
|
|
:dism,
|
|
)
|
|
params = {
|
|
name: 'IIS-WebServer',
|
|
description: 'Installs the IIS 10.0 World Wide Web Services. Provides support for HTML web sites and optional support for ASP.NET, Classic ASP, and web server extensions.',
|
|
installed: true,
|
|
method: :dism,
|
|
}
|
|
_(resource.info).must_equal params
|
|
_(resource.installed?).must_equal true
|
|
end
|
|
|
|
it 'uses DISM when Get-WindowsFeature does not exist' do
|
|
resource = MockLoader.new(:windows)
|
|
.load_resource('windows_feature', 'IIS-WebServer')
|
|
params = {
|
|
name: 'IIS-WebServer',
|
|
description: 'Installs the IIS 10.0 World Wide Web Services. Provides support for HTML web sites and optional support for ASP.NET, Classic ASP, and web server extensions.',
|
|
installed: true,
|
|
method: :dism,
|
|
}
|
|
_(resource.info).must_equal params
|
|
_(resource.installed?).must_equal true
|
|
end
|
|
|
|
it 'fails the resource if PowerShell method is used but command not found' do
|
|
resource = MockLoader.new(:windows).load_resource(
|
|
'windows_feature',
|
|
'IIS-WebServer',
|
|
:powershell,
|
|
)
|
|
|
|
e = proc {
|
|
resource.info
|
|
}.must_raise(Inspec::Exceptions::ResourceFailed)
|
|
|
|
e.message.must_match(/Could not find `Get-WindowsFeature`/)
|
|
end
|
|
end
|