summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJason Barnett <jason.w.barnett@gmail.com>2018-01-26 15:55:07 -0800
committerJason Barnett <jason.w.barnett@gmail.com>2018-01-26 15:56:55 -0800
commit1676c80eaa4df2e91e8252119cd528d63873196b (patch)
tree118b55d68bb68085de506a613dacff548d9c89ee
parentd4c645016baf361f823b5d8c940ff6ff750ac6a3 (diff)
downloadchef-1676c80eaa4df2e91e8252119cd528d63873196b.tar.gz
chefstyle -a
Developer's Certificate of Origin 1.1 By making a contribution to this project, I certify that: (a) The contribution was created in whole or in part by me and I have the right to submit it under the open source license indicated in the file; or (b) The contribution is based upon previous work that, to the best of my knowledge, is covered under an appropriate open source license and I have the right under that license to submit that work with modifications, whether created in whole or in part by me, under the same open source license (unless I am permitted to submit under a different license), as Indicated in the file; or (c) The contribution was provided directly to me by some other person who certified (a), (b) or (c) and I have not modified it. (d) I understand and agree that this project and the contribution are public and that a record of the contribution (including all personal information I submit with it, including my sign-off) is maintained indefinitely and may be redistributed consistent with this project or the open source license(s) involved. Signed-off-by: Jason Barnett <jason.w.barnett@gmail.com>
-rw-r--r--lib/chef/provider/service/windows.rb54
-rw-r--r--lib/chef/resource/windows_service.rb6
-rw-r--r--spec/unit/provider/service/windows_spec.rb116
-rw-r--r--spec/unit/resource/windows_service_spec.rb8
4 files changed, 92 insertions, 92 deletions
diff --git a/lib/chef/provider/service/windows.rb b/lib/chef/provider/service/windows.rb
index 603b9f7985..ea2b964023 100644
--- a/lib/chef/provider/service/windows.rb
+++ b/lib/chef/provider/service/windows.rb
@@ -280,7 +280,7 @@ class Chef::Provider::Service::Windows < Chef::Provider::Service
def current_delayed_start
if service = Win32::Service.services.find { |x| x.service_name == new_resource.service_name }
- service.delayed_start.zero? ? false : true
+ service.delayed_start == 0 ? false : true
else
nil
end
@@ -376,12 +376,12 @@ class Chef::Provider::Service::Windows < Chef::Provider::Service
config[:load_order_group] = new_resource.load_order_group if new_resource.load_order_group
config[:dependencies] = new_resource.dependencies if new_resource.dependencies
config[:service_start_name] = new_resource.run_as_user unless new_resource.run_as_user.empty?
- config[:password] = new_resource.run_as_password unless new_resource.run_as_user.empty? or new_resource.run_as_password.empty?
+ config[:password] = new_resource.run_as_password unless new_resource.run_as_user.empty? || new_resource.run_as_password.empty?
config[:description] = new_resource.description if new_resource.description
case action
when :create
- config[:desired_access] = new_resource.desired_access if new_resource.desired_access
+ config[:desired_access] = new_resource.desired_access if new_resource.desired_access
end
config
@@ -405,15 +405,15 @@ class Chef::Provider::Service::Windows < Chef::Provider::Service
# @return [Symbol]
def start_type_to_sym(start_type)
case start_type
- when 'auto start'
+ when "auto start"
:automatic
- when 'boot start'
+ when "boot start"
raise("Unsupported start type, #{start_type}. Submit bug request to fix.")
- when 'demand start'
+ when "demand start"
:manual
- when 'disabled'
+ when "disabled"
:disabled
- when 'system start'
+ when "system start"
raise("Unsupported start type, #{start_type}. Submit bug request to fix.")
else
raise("Unsupported start type, #{start_type}. Submit bug request to fix.")
@@ -422,25 +422,25 @@ class Chef::Provider::Service::Windows < Chef::Provider::Service
def get_service_type(service_type)
case service_type
- when 'file system driver'
+ when "file system driver"
SERVICE_FILE_SYSTEM_DRIVER
- when 'kernel driver'
+ when "kernel driver"
SERVICE_KERNEL_DRIVER
- when 'own process'
+ when "own process"
SERVICE_WIN32_OWN_PROCESS
- when 'share process'
+ when "share process"
SERVICE_WIN32_SHARE_PROCESS
- when 'recognizer driver'
+ when "recognizer driver"
SERVICE_RECOGNIZER_DRIVER
- when 'driver'
+ when "driver"
SERVICE_DRIVER
- when 'win32'
+ when "win32"
SERVICE_WIN32
- when 'all'
+ when "all"
SERVICE_TYPE_ALL
- when 'own process, interactive'
+ when "own process, interactive"
SERVICE_INTERACTIVE_PROCESS | SERVICE_WIN32_OWN_PROCESS
- when 'share process, interactive'
+ when "share process, interactive"
SERVICE_INTERACTIVE_PROCESS | SERVICE_WIN32_SHARE_PROCESS
else
raise("Unsupported service type, #{service_type}. Submit bug request to fix.")
@@ -450,15 +450,15 @@ class Chef::Provider::Service::Windows < Chef::Provider::Service
# @return [Integer]
def get_start_type(start_type)
case start_type
- when 'auto start'
+ when "auto start"
SERVICE_AUTO_START
- when 'boot start'
+ when "boot start"
SERVICE_BOOT_START
- when 'demand start'
+ when "demand start"
SERVICE_DEMAND_START
- when 'disabled'
+ when "disabled"
SERVICE_DISABLED
- when 'system start'
+ when "system start"
SERVICE_SYSTEM_START
else
raise("Unsupported start type, #{start_type}. Submit bug request to fix.")
@@ -467,13 +467,13 @@ class Chef::Provider::Service::Windows < Chef::Provider::Service
def get_error_control(error_control)
case error_control
- when 'critical'
+ when "critical"
SERVICE_ERROR_CRITICAL
- when 'ignore'
+ when "ignore"
SERVICE_ERROR_IGNORE
- when 'normal'
+ when "normal"
SERVICE_ERROR_NORMAL
- when 'severe'
+ when "severe"
SERVICE_ERROR_SEVERE
else
nil
diff --git a/lib/chef/resource/windows_service.rb b/lib/chef/resource/windows_service.rb
index a085252a4c..4e14b18c20 100644
--- a/lib/chef/resource/windows_service.rb
+++ b/lib/chef/resource/windows_service.rb
@@ -80,7 +80,7 @@ class Chef
# 0 == NO delayed start
property :delayed_start, [TrueClass, FalseClass], default: false, coerce: proc { |x|
if x.is_a?(Integer)
- x.zero? ? false : true
+ x == 0 ? false : true
else
x
end
@@ -110,8 +110,8 @@ class Chef
property :description, String
- property :run_as_user, String, default: 'LocalSystem'
- property :run_as_password, String, default: ''
+ property :run_as_user, String, default: "LocalSystem"
+ property :run_as_password, String, default: ""
end
end
end
diff --git a/spec/unit/provider/service/windows_spec.rb b/spec/unit/provider/service/windows_spec.rb
index 6c6a50c01d..8d87812ca6 100644
--- a/spec/unit/provider/service/windows_spec.rb
+++ b/spec/unit/provider/service/windows_spec.rb
@@ -33,39 +33,39 @@ describe Chef::Provider::Service::Windows, "load_current_resource" do
'C:\\opscode\\chef\\embedded\\bin\\ruby.exe C:\\opscode\\chef\\bin\\chef-windows-service'
end
let(:chef_service_config_info) do
- double('Struct::ServiceConfigInfo',
- service_type: 'own process',
- start_type: 'auto start',
- error_control: 'ignore',
+ double("Struct::ServiceConfigInfo",
+ service_type: "own process",
+ start_type: "auto start",
+ error_control: "ignore",
binary_path_name: chef_service_binary_path_name,
- load_order_group: '',
+ load_order_group: "",
tag_id: 0,
- dependencies: ['Winmgmt'],
- service_start_name: 'LocalSystem',
- display_name: 'Chef Client Service',
+ dependencies: ["Winmgmt"],
+ service_start_name: "LocalSystem",
+ display_name: "Chef Client Service"
)
end
# Actual response from Win32::Service.services
let(:chef_service_info) do
- double('Struct::ServiceInfo',
+ double("Struct::ServiceInfo",
service_name: chef_service_name,
- display_name: 'Chef Client Service',
- service_type: 'own process',
- current_state: 'running',
+ display_name: "Chef Client Service",
+ service_type: "own process",
+ current_state: "running",
controls_accepted: [],
win32_exit_code: 1077,
service_specific_exit_code: 0,
check_point: 0,
wait_hint: 0,
binary_path_name: chef_service_binary_path_name,
- start_type: 'auto start',
- error_control: 'ignore',
- load_order_group: '',
+ start_type: "auto start",
+ error_control: "ignore",
+ load_order_group: "",
tag_id: 0,
- start_name: 'LocalSystem',
- dependencies: ['Winmgmt'],
- description: 'Runs Chef Client on regular, configurable intervals.',
+ start_name: "LocalSystem",
+ dependencies: ["Winmgmt"],
+ description: "Runs Chef Client on regular, configurable intervals.",
interactive: false,
pid: 0,
service_flags: 0,
@@ -104,28 +104,28 @@ describe Chef::Provider::Service::Windows, "load_current_resource" do
allow(Win32::Service).to receive(:services).and_return([
# Add chef_service_info to our stubbed response so our tests that are expecting the service to exist work
chef_service_info,
- double('Struct::ServiceInfo', service_name: 'ACPI', display_name: 'Microsoft ACPI Driver', service_type: 'kernel driver', current_state: 'running', controls_accepted: ['stop'], win32_exit_code: 0, service_specific_exit_code: 0, check_point: 0, wait_hint: 0, binary_path_name: '\\SystemRoot\\System32\\drivers\\ACPI.sys', start_type: 'boot start', error_control: 'critical', load_order_group: 'Core', tag_id: 2, start_name: '', dependencies: [], description: '', interactive: false, pid: 0, service_flags: 0, reset_period: 0, reboot_message: nil, command: nil, num_actions: 0, actions: nil, delayed_start: 0),
- double('Struct::ServiceInfo', service_name: 'cdrom', display_name: 'CD-ROM Driver', service_type: 'kernel driver', current_state: 'running', controls_accepted: ['stop'], win32_exit_code: 0, service_specific_exit_code: 0, check_point: 0, wait_hint: 0, binary_path_name: '\\SystemRoot\\System32\\drivers\\cdrom.sys', start_type: 'system start', error_control: 'normal', load_order_group: 'SCSI CDROM Class', tag_id: 3, start_name: '', dependencies: [], description: '', interactive: false, pid: 0, service_flags: 0, reset_period: 0, reboot_message: nil, command: nil, num_actions: 0, actions: nil, delayed_start: 0),
- double('Struct::ServiceInfo', service_name: 'CryptSvc', display_name: 'Cryptographic Services', service_type: 'share process', current_state: 'running', controls_accepted: ['shutdown', 'stop', 'session change'], win32_exit_code: 0, service_specific_exit_code: 0, check_point: 0, wait_hint: 0, binary_path_name: 'C:\\Windows\\system32\\svchost.exe -k NetworkService', start_type: 'auto start', error_control: 'normal', load_order_group: '', tag_id: 0, start_name: 'NT Authority\\NetworkService', dependencies: ['RpcSs'], description: 'Provides three management services: Catalog Database Service, which confirms the signatures of Windows files and allows new programs to be installed; Protected Root Service, which adds and removes Trusted Root Certification Authority certificates from this computer; and Automatic Root Certificate Update Service, which retrieves root certificates from Windows Update and enable scenarios such as SSL. If this service is stopped, these management services will not function properly. If this service is disabled, any services that explicitly depend on it will fail to start.', interactive: false, pid: 932, service_flags: 0, reset_period: 86400, reboot_message: nil, command: nil, num_actions: 3, actions: { 1 => { action_type: 'restart', delay: 60000 }, 2 => { action_type: 'none', delay: 0 }, 3 => { action_type: 'none', delay: 0 } }, delayed_start: 0),
- double('Struct::ServiceInfo', service_name: 'DcomLaunch', display_name: 'DCOM Server Process Launcher', service_type: 'share process', current_state: 'running', controls_accepted: ['session change'], win32_exit_code: 0, service_specific_exit_code: 0, check_point: 0, wait_hint: 0, binary_path_name: 'C:\\Windows\\system32\\svchost.exe -k DcomLaunch', start_type: 'auto start', error_control: 'normal', load_order_group: 'COM Infrastructure', tag_id: 0, start_name: 'LocalSystem', dependencies: [], description: 'The DCOMLAUNCH service launches COM and DCOM servers in response to object activation requests. If this service is stopped or disabled, programs using COM or DCOM will not function properly. It is strongly recommended that you have the DCOMLAUNCH service running.', interactive: false, pid: 552, service_flags: 0, reset_period: 0, reboot_message: nil, command: nil, num_actions: 1, actions: { 1 => { action_type: 'reboot', delay: 60000 } }, delayed_start: 0),
- double('Struct::ServiceInfo', service_name: 'Dfsc', display_name: 'DFS Namespace Client Driver', service_type: 'file system driver', current_state: 'running', controls_accepted: ['stop'], win32_exit_code: 0, service_specific_exit_code: 0, check_point: 0, wait_hint: 0, binary_path_name: 'System32\\Drivers\\dfsc.sys', start_type: 'system start', error_control: 'normal', load_order_group: 'Network', tag_id: 0, start_name: '', dependencies: ['Mup'], description: 'Client driver for access to DFS Namespaces', interactive: false, pid: 0, service_flags: 0, reset_period: 0, reboot_message: nil, command: nil, num_actions: 0, actions: nil, delayed_start: 0),
- double('Struct::ServiceInfo', service_name: 'Dhcp', display_name: 'DHCP Client', service_type: 'share process', current_state: 'running', controls_accepted: %w(shutdown stop), win32_exit_code: 0, service_specific_exit_code: 0, check_point: 0, wait_hint: 0, binary_path_name: 'C:\\Windows\\system32\\svchost.exe -k LocalServiceNetworkRestricted', start_type: 'auto start', error_control: 'normal', load_order_group: 'TDI', tag_id: 0, start_name: 'NT Authority\\LocalService', dependencies: %w(NSI Tdx Afd), description: 'Registers and updates IP addresses and DNS records for this computer. If this service is stopped, this computer will not receive dynamic IP addresses and DNS updates. If this service is disabled, any services that explicitly depend on it will fail to start.', interactive: false, pid: 780, service_flags: 0, reset_period: 86400, reboot_message: nil, command: nil, num_actions: 3, actions: { 1 => { action_type: 'restart', delay: 120000 }, 2 => { action_type: 'restart', delay: 300000 }, 3 => { action_type: 'none', delay: 0 } }, delayed_start: 0),
- double('Struct::ServiceInfo', service_name: 'EventLog', display_name: 'Windows Event Log', service_type: 'share process', current_state: 'running', controls_accepted: %w(shutdown stop), win32_exit_code: 0, service_specific_exit_code: 0, check_point: 0, wait_hint: 0, binary_path_name: 'C:\\Windows\\System32\\svchost.exe -k LocalServiceNetworkRestricted', start_type: 'auto start', error_control: 'normal', load_order_group: 'Event Log', tag_id: 0, start_name: 'NT AUTHORITY\\LocalService', dependencies: [], description: 'This service manages events and event logs. It supports logging events, querying events, subscribing to events, archiving event logs, and managing event metadata. It can display events in both XML and plain text format. Stopping this service may compromise security and reliability of the system.', interactive: false, pid: 780, service_flags: 0, reset_period: 86400, reboot_message: nil, command: nil, num_actions: 3, actions: { 1 => { action_type: 'restart', delay: 60000 }, 2 => { action_type: 'restart', delay: 120000 }, 3 => { action_type: 'none', delay: 0 } }, delayed_start: 0),
- double('Struct::ServiceInfo', service_name: 'EventSystem', display_name: 'COM+ Event System', service_type: 'share process', current_state: 'running', controls_accepted: ['stop'], win32_exit_code: 0, service_specific_exit_code: 0, check_point: 0, wait_hint: 0, binary_path_name: 'C:\\Windows\\system32\\svchost.exe -k LocalService', start_type: 'auto start', error_control: 'normal', load_order_group: '', tag_id: 0, start_name: 'NT AUTHORITY\\LocalService', dependencies: ['rpcss'], description: 'Supports System Event Notification Service (SENS), which provides automatic distribution of events to subscribing Component Object Model (COM) components. If the service is stopped, SENS will close and will not be able to provide logon and logoff notifications. If this service is disabled, any services that explicitly depend on it will fail to start.', interactive: false, pid: 844, service_flags: 0, reset_period: 86400, reboot_message: nil, command: nil, num_actions: 3, actions: { 1 => { action_type: 'restart', delay: 1000 }, 2 => { action_type: 'restart', delay: 5000 }, 3 => { action_type: 'none', delay: 0 } }, delayed_start: 0),
- double('Struct::ServiceInfo', service_name: 'LanmanWorkstation', display_name: 'Workstation', service_type: 'share process', current_state: 'running', controls_accepted: ['pause continue', 'stop', 'power event'], win32_exit_code: 0, service_specific_exit_code: 0, check_point: 0, wait_hint: 0, binary_path_name: 'C:\\Windows\\System32\\svchost.exe -k NetworkService', start_type: 'auto start', error_control: 'normal', load_order_group: 'NetworkProvider', tag_id: 0, start_name: 'NT AUTHORITY\\NetworkService', dependencies: %w(Bowser MRxSmb20 NSI), description: 'Creates and maintains client network connections to remote servers using the SMB protocol. If this service is stopped, these connections will be unavailable. If this service is disabled, any services that explicitly depend on it will fail to start.', interactive: false, pid: 932, service_flags: 0, reset_period: 86400, reboot_message: nil, command: nil, num_actions: 3, actions: { 1 => { action_type: 'restart', delay: 60000 }, 2 => { action_type: 'restart', delay: 120000 }, 3 => { action_type: 'none', delay: 0 } }, delayed_start: 0),
- double('Struct::ServiceInfo', service_name: 'lmhosts', display_name: 'TCP/IP NetBIOS Helper', service_type: 'share process', current_state: 'running', controls_accepted: ['stop'], win32_exit_code: 0, service_specific_exit_code: 0, check_point: 0, wait_hint: 0, binary_path_name: 'C:\\Windows\\system32\\svchost.exe -k LocalServiceNetworkRestricted', start_type: 'auto start', error_control: 'normal', load_order_group: 'TDI', tag_id: 0, start_name: 'NT AUTHORITY\\LocalService', dependencies: %w(NetBT Afd), description: 'Provides support for the NetBIOS over TCP/IP (NetBT) service and NetBIOS name resolution for clients on the network, therefore enabling users to share files, print, and log on to the network. If this service is stopped, these functions might be unavailable. If this service is disabled, any services that explicitly depend on it will fail to start.', interactive: false, pid: 780, service_flags: 0, reset_period: 86400, reboot_message: nil, command: nil, num_actions: 3, actions: { 1 => { action_type: 'restart', delay: 100 }, 2 => { action_type: 'restart', delay: 100 }, 3 => { action_type: 'none', delay: 0 } }, delayed_start: 0),
- double('Struct::ServiceInfo', service_name: 'MpsSvc', display_name: 'Windows Firewall', service_type: 'share process', current_state: 'running', controls_accepted: ['stop'], win32_exit_code: 0, service_specific_exit_code: 0, check_point: 0, wait_hint: 0, binary_path_name: 'C:\\Windows\\system32\\svchost.exe -k LocalServiceNoNetwork', start_type: 'auto start', error_control: 'normal', load_order_group: 'NetworkProvider', tag_id: 0, start_name: 'NT Authority\\LocalService', dependencies: %w(mpsdrv bfe), description: 'Windows Firewall helps protect your computer by preventing unauthorized users from gaining access to your computer through the Internet or a network.', interactive: false, pid: 340, service_flags: 0, reset_period: 86400, reboot_message: nil, command: nil, num_actions: 3, actions: { 1 => { action_type: 'restart', delay: 120000 }, 2 => { action_type: 'restart', delay: 300000 }, 3 => { action_type: 'none', delay: 0 } }, delayed_start: 0),
- double('Struct::ServiceInfo', service_name: 'mrxsmb', display_name: 'SMB MiniRedirector Wrapper and Engine', service_type: 'file system driver', current_state: 'running', controls_accepted: ['stop'], win32_exit_code: 0, service_specific_exit_code: 0, check_point: 0, wait_hint: 0, binary_path_name: 'system32\\DRIVERS\\mrxsmb.sys', start_type: 'demand start', error_control: 'normal', load_order_group: 'Network', tag_id: 5, start_name: '', dependencies: ['rdbss'], description: 'Implements the framework for the SMB filesystem redirector', interactive: false, pid: 0, service_flags: 0, reset_period: 0, reboot_message: nil, command: nil, num_actions: 0, actions: nil, delayed_start: 0),
- double('Struct::ServiceInfo', service_name: 'Ntfs', display_name: 'Ntfs', service_type: 'file system driver', current_state: 'running', controls_accepted: ['stop'], win32_exit_code: 0, service_specific_exit_code: 0, check_point: 0, wait_hint: 0, binary_path_name: '', start_type: 'demand start', error_control: 'normal', load_order_group: 'Boot File System', tag_id: 0, start_name: '', dependencies: [], description: '', interactive: false, pid: 0, service_flags: 0, reset_period: 0, reboot_message: nil, command: nil, num_actions: 0, actions: nil, delayed_start: 0),
- double('Struct::ServiceInfo', service_name: 'Tcpip', display_name: 'TCP/IP Protocol Driver', service_type: 'kernel driver', current_state: 'running', controls_accepted: ['stop'], win32_exit_code: 0, service_specific_exit_code: 0, check_point: 0, wait_hint: 0, binary_path_name: '\\SystemRoot\\System32\\drivers\\tcpip.sys', start_type: 'boot start', error_control: 'normal', load_order_group: 'PNP_TDI', tag_id: 3, start_name: '', dependencies: [], description: 'TCP/IP Protocol Driver', interactive: false, pid: 0, service_flags: 0, reset_period: 0, reboot_message: nil, command: nil, num_actions: 0, actions: nil, delayed_start: 0),
- double('Struct::ServiceInfo', service_name: 'W32Time', display_name: 'Windows Time', service_type: 'share process', current_state: 'running', controls_accepted: ['netbind change', 'param change', 'shutdown', 'stop', 'hardware profile change', 'power event'], win32_exit_code: 0, service_specific_exit_code: 0, check_point: 0, wait_hint: 0, binary_path_name: 'C:\\Windows\\system32\\svchost.exe -k LocalService', start_type: 'demand start', error_control: 'normal', load_order_group: '', tag_id: 0, start_name: 'NT AUTHORITY\\LocalService', dependencies: [], description: 'Maintains date and time synchronization on all clients and servers in the network. If this service is stopped, date and time synchronization will be unavailable. If this service is disabled, any services that explicitly depend on it will fail to start.', interactive: false, pid: 844, service_flags: 0, reset_period: 86400, reboot_message: nil, command: nil, num_actions: 3, actions: { 1 => { action_type: 'restart', delay: 60000 }, 2 => { action_type: 'restart', delay: 120000 }, 3 => { action_type: 'none', delay: 0 } }, delayed_start: 0),
- double('Struct::ServiceInfo', service_name: 'Winmgmt', display_name: 'Windows Management Instrumentation', service_type: 'share process', current_state: 'running', controls_accepted: ['pause continue', 'shutdown', 'stop'], win32_exit_code: 0, service_specific_exit_code: 0, check_point: 0, wait_hint: 0, binary_path_name: 'C:\\Windows\\system32\\svchost.exe -k netsvcs', start_type: 'auto start', error_control: 'ignore', load_order_group: '', tag_id: 0, start_name: 'localSystem', dependencies: ['RPCSS'], description: 'Provides a common interface and object model to access management information about operating system, devices, applications and services. If this service is stopped, most Windows-based software will not function properly. If this service is disabled, any services that explicitly depend on it will fail to start.', interactive: false, pid: 812, service_flags: 0, reset_period: 86400, reboot_message: nil, command: nil, num_actions: 3, actions: { 1 => { action_type: 'restart', delay: 120000 }, 2 => { action_type: 'restart', delay: 300000 }, 3 => { action_type: 'none', delay: 0 } }, delayed_start: 0),
- double('Struct::ServiceInfo', service_name: 'WinRM', display_name: 'Windows Remote Management (WS-Management)', service_type: 'share process', current_state: 'running', controls_accepted: %w(shutdown stop), win32_exit_code: 0, service_specific_exit_code: 0, check_point: 0, wait_hint: 0, binary_path_name: 'C:\\Windows\\System32\\svchost.exe -k NetworkService', start_type: 'auto start', error_control: 'normal', load_order_group: '', tag_id: 0, start_name: 'NT AUTHORITY\\NetworkService', dependencies: %w(RPCSS HTTP), description: 'Windows Remote Management (WinRM) service implements the WS-Management protocol for remote management. WS-Management is a standard web services protocol used for remote software and hardware management. The WinRM service listens on the network for WS-Management requests and processes them. The WinRM Service needs to be configured with a listener using winrm.cmd command line tool or through Group Policy in order for it to listen over the network. The WinRM service provides access to WMI data and enables event collection. Event collection and subscription to events require that the service is running. WinRM messages use HTTP and HTTPS as transports. The WinRM service does not depend on IIS but is preconfigured to share a port with IIS on the same machine. The WinRM service reserves the /wsman URL prefix. To prevent conflicts with IIS, administrators should ensure that any websites hosted on IIS do not use the /wsman URL prefix.', interactive: false, pid: 932, service_flags: 0, reset_period: 86400, reboot_message: nil, command: nil, num_actions: 3, actions: { 1 => { action_type: 'restart', delay: 120000 }, 2 => { action_type: 'restart', delay: 300000 }, 3 => { action_type: 'none', delay: 0 } }, delayed_start: 0),
+ double("Struct::ServiceInfo", service_name: "ACPI", display_name: "Microsoft ACPI Driver", service_type: "kernel driver", current_state: "running", controls_accepted: ["stop"], win32_exit_code: 0, service_specific_exit_code: 0, check_point: 0, wait_hint: 0, binary_path_name: '\\SystemRoot\\System32\\drivers\\ACPI.sys', start_type: "boot start", error_control: "critical", load_order_group: "Core", tag_id: 2, start_name: "", dependencies: [], description: "", interactive: false, pid: 0, service_flags: 0, reset_period: 0, reboot_message: nil, command: nil, num_actions: 0, actions: nil, delayed_start: 0),
+ double("Struct::ServiceInfo", service_name: "cdrom", display_name: "CD-ROM Driver", service_type: "kernel driver", current_state: "running", controls_accepted: ["stop"], win32_exit_code: 0, service_specific_exit_code: 0, check_point: 0, wait_hint: 0, binary_path_name: '\\SystemRoot\\System32\\drivers\\cdrom.sys', start_type: "system start", error_control: "normal", load_order_group: "SCSI CDROM Class", tag_id: 3, start_name: "", dependencies: [], description: "", interactive: false, pid: 0, service_flags: 0, reset_period: 0, reboot_message: nil, command: nil, num_actions: 0, actions: nil, delayed_start: 0),
+ double("Struct::ServiceInfo", service_name: "CryptSvc", display_name: "Cryptographic Services", service_type: "share process", current_state: "running", controls_accepted: ["shutdown", "stop", "session change"], win32_exit_code: 0, service_specific_exit_code: 0, check_point: 0, wait_hint: 0, binary_path_name: 'C:\\Windows\\system32\\svchost.exe -k NetworkService', start_type: "auto start", error_control: "normal", load_order_group: "", tag_id: 0, start_name: 'NT Authority\\NetworkService', dependencies: ["RpcSs"], description: "Provides three management services: Catalog Database Service, which confirms the signatures of Windows files and allows new programs to be installed; Protected Root Service, which adds and removes Trusted Root Certification Authority certificates from this computer; and Automatic Root Certificate Update Service, which retrieves root certificates from Windows Update and enable scenarios such as SSL. If this service is stopped, these management services will not function properly. If this service is disabled, any services that explicitly depend on it will fail to start.", interactive: false, pid: 932, service_flags: 0, reset_period: 86400, reboot_message: nil, command: nil, num_actions: 3, actions: { 1 => { action_type: "restart", delay: 60000 }, 2 => { action_type: "none", delay: 0 }, 3 => { action_type: "none", delay: 0 } }, delayed_start: 0),
+ double("Struct::ServiceInfo", service_name: "DcomLaunch", display_name: "DCOM Server Process Launcher", service_type: "share process", current_state: "running", controls_accepted: ["session change"], win32_exit_code: 0, service_specific_exit_code: 0, check_point: 0, wait_hint: 0, binary_path_name: 'C:\\Windows\\system32\\svchost.exe -k DcomLaunch', start_type: "auto start", error_control: "normal", load_order_group: "COM Infrastructure", tag_id: 0, start_name: "LocalSystem", dependencies: [], description: "The DCOMLAUNCH service launches COM and DCOM servers in response to object activation requests. If this service is stopped or disabled, programs using COM or DCOM will not function properly. It is strongly recommended that you have the DCOMLAUNCH service running.", interactive: false, pid: 552, service_flags: 0, reset_period: 0, reboot_message: nil, command: nil, num_actions: 1, actions: { 1 => { action_type: "reboot", delay: 60000 } }, delayed_start: 0),
+ double("Struct::ServiceInfo", service_name: "Dfsc", display_name: "DFS Namespace Client Driver", service_type: "file system driver", current_state: "running", controls_accepted: ["stop"], win32_exit_code: 0, service_specific_exit_code: 0, check_point: 0, wait_hint: 0, binary_path_name: 'System32\\Drivers\\dfsc.sys', start_type: "system start", error_control: "normal", load_order_group: "Network", tag_id: 0, start_name: "", dependencies: ["Mup"], description: "Client driver for access to DFS Namespaces", interactive: false, pid: 0, service_flags: 0, reset_period: 0, reboot_message: nil, command: nil, num_actions: 0, actions: nil, delayed_start: 0),
+ double("Struct::ServiceInfo", service_name: "Dhcp", display_name: "DHCP Client", service_type: "share process", current_state: "running", controls_accepted: %w{shutdown stop}, win32_exit_code: 0, service_specific_exit_code: 0, check_point: 0, wait_hint: 0, binary_path_name: 'C:\\Windows\\system32\\svchost.exe -k LocalServiceNetworkRestricted', start_type: "auto start", error_control: "normal", load_order_group: "TDI", tag_id: 0, start_name: 'NT Authority\\LocalService', dependencies: %w{NSI Tdx Afd}, description: "Registers and updates IP addresses and DNS records for this computer. If this service is stopped, this computer will not receive dynamic IP addresses and DNS updates. If this service is disabled, any services that explicitly depend on it will fail to start.", interactive: false, pid: 780, service_flags: 0, reset_period: 86400, reboot_message: nil, command: nil, num_actions: 3, actions: { 1 => { action_type: "restart", delay: 120000 }, 2 => { action_type: "restart", delay: 300000 }, 3 => { action_type: "none", delay: 0 } }, delayed_start: 0),
+ double("Struct::ServiceInfo", service_name: "EventLog", display_name: "Windows Event Log", service_type: "share process", current_state: "running", controls_accepted: %w{shutdown stop}, win32_exit_code: 0, service_specific_exit_code: 0, check_point: 0, wait_hint: 0, binary_path_name: 'C:\\Windows\\System32\\svchost.exe -k LocalServiceNetworkRestricted', start_type: "auto start", error_control: "normal", load_order_group: "Event Log", tag_id: 0, start_name: 'NT AUTHORITY\\LocalService', dependencies: [], description: "This service manages events and event logs. It supports logging events, querying events, subscribing to events, archiving event logs, and managing event metadata. It can display events in both XML and plain text format. Stopping this service may compromise security and reliability of the system.", interactive: false, pid: 780, service_flags: 0, reset_period: 86400, reboot_message: nil, command: nil, num_actions: 3, actions: { 1 => { action_type: "restart", delay: 60000 }, 2 => { action_type: "restart", delay: 120000 }, 3 => { action_type: "none", delay: 0 } }, delayed_start: 0),
+ double("Struct::ServiceInfo", service_name: "EventSystem", display_name: "COM+ Event System", service_type: "share process", current_state: "running", controls_accepted: ["stop"], win32_exit_code: 0, service_specific_exit_code: 0, check_point: 0, wait_hint: 0, binary_path_name: 'C:\\Windows\\system32\\svchost.exe -k LocalService', start_type: "auto start", error_control: "normal", load_order_group: "", tag_id: 0, start_name: 'NT AUTHORITY\\LocalService', dependencies: ["rpcss"], description: "Supports System Event Notification Service (SENS), which provides automatic distribution of events to subscribing Component Object Model (COM) components. If the service is stopped, SENS will close and will not be able to provide logon and logoff notifications. If this service is disabled, any services that explicitly depend on it will fail to start.", interactive: false, pid: 844, service_flags: 0, reset_period: 86400, reboot_message: nil, command: nil, num_actions: 3, actions: { 1 => { action_type: "restart", delay: 1000 }, 2 => { action_type: "restart", delay: 5000 }, 3 => { action_type: "none", delay: 0 } }, delayed_start: 0),
+ double("Struct::ServiceInfo", service_name: "LanmanWorkstation", display_name: "Workstation", service_type: "share process", current_state: "running", controls_accepted: ["pause continue", "stop", "power event"], win32_exit_code: 0, service_specific_exit_code: 0, check_point: 0, wait_hint: 0, binary_path_name: 'C:\\Windows\\System32\\svchost.exe -k NetworkService', start_type: "auto start", error_control: "normal", load_order_group: "NetworkProvider", tag_id: 0, start_name: 'NT AUTHORITY\\NetworkService', dependencies: %w{Bowser MRxSmb20 NSI}, description: "Creates and maintains client network connections to remote servers using the SMB protocol. If this service is stopped, these connections will be unavailable. If this service is disabled, any services that explicitly depend on it will fail to start.", interactive: false, pid: 932, service_flags: 0, reset_period: 86400, reboot_message: nil, command: nil, num_actions: 3, actions: { 1 => { action_type: "restart", delay: 60000 }, 2 => { action_type: "restart", delay: 120000 }, 3 => { action_type: "none", delay: 0 } }, delayed_start: 0),
+ double("Struct::ServiceInfo", service_name: "lmhosts", display_name: "TCP/IP NetBIOS Helper", service_type: "share process", current_state: "running", controls_accepted: ["stop"], win32_exit_code: 0, service_specific_exit_code: 0, check_point: 0, wait_hint: 0, binary_path_name: 'C:\\Windows\\system32\\svchost.exe -k LocalServiceNetworkRestricted', start_type: "auto start", error_control: "normal", load_order_group: "TDI", tag_id: 0, start_name: 'NT AUTHORITY\\LocalService', dependencies: %w{NetBT Afd}, description: "Provides support for the NetBIOS over TCP/IP (NetBT) service and NetBIOS name resolution for clients on the network, therefore enabling users to share files, print, and log on to the network. If this service is stopped, these functions might be unavailable. If this service is disabled, any services that explicitly depend on it will fail to start.", interactive: false, pid: 780, service_flags: 0, reset_period: 86400, reboot_message: nil, command: nil, num_actions: 3, actions: { 1 => { action_type: "restart", delay: 100 }, 2 => { action_type: "restart", delay: 100 }, 3 => { action_type: "none", delay: 0 } }, delayed_start: 0),
+ double("Struct::ServiceInfo", service_name: "MpsSvc", display_name: "Windows Firewall", service_type: "share process", current_state: "running", controls_accepted: ["stop"], win32_exit_code: 0, service_specific_exit_code: 0, check_point: 0, wait_hint: 0, binary_path_name: 'C:\\Windows\\system32\\svchost.exe -k LocalServiceNoNetwork', start_type: "auto start", error_control: "normal", load_order_group: "NetworkProvider", tag_id: 0, start_name: 'NT Authority\\LocalService', dependencies: %w{mpsdrv bfe}, description: "Windows Firewall helps protect your computer by preventing unauthorized users from gaining access to your computer through the Internet or a network.", interactive: false, pid: 340, service_flags: 0, reset_period: 86400, reboot_message: nil, command: nil, num_actions: 3, actions: { 1 => { action_type: "restart", delay: 120000 }, 2 => { action_type: "restart", delay: 300000 }, 3 => { action_type: "none", delay: 0 } }, delayed_start: 0),
+ double("Struct::ServiceInfo", service_name: "mrxsmb", display_name: "SMB MiniRedirector Wrapper and Engine", service_type: "file system driver", current_state: "running", controls_accepted: ["stop"], win32_exit_code: 0, service_specific_exit_code: 0, check_point: 0, wait_hint: 0, binary_path_name: 'system32\\DRIVERS\\mrxsmb.sys', start_type: "demand start", error_control: "normal", load_order_group: "Network", tag_id: 5, start_name: "", dependencies: ["rdbss"], description: "Implements the framework for the SMB filesystem redirector", interactive: false, pid: 0, service_flags: 0, reset_period: 0, reboot_message: nil, command: nil, num_actions: 0, actions: nil, delayed_start: 0),
+ double("Struct::ServiceInfo", service_name: "Ntfs", display_name: "Ntfs", service_type: "file system driver", current_state: "running", controls_accepted: ["stop"], win32_exit_code: 0, service_specific_exit_code: 0, check_point: 0, wait_hint: 0, binary_path_name: "", start_type: "demand start", error_control: "normal", load_order_group: "Boot File System", tag_id: 0, start_name: "", dependencies: [], description: "", interactive: false, pid: 0, service_flags: 0, reset_period: 0, reboot_message: nil, command: nil, num_actions: 0, actions: nil, delayed_start: 0),
+ double("Struct::ServiceInfo", service_name: "Tcpip", display_name: "TCP/IP Protocol Driver", service_type: "kernel driver", current_state: "running", controls_accepted: ["stop"], win32_exit_code: 0, service_specific_exit_code: 0, check_point: 0, wait_hint: 0, binary_path_name: '\\SystemRoot\\System32\\drivers\\tcpip.sys', start_type: "boot start", error_control: "normal", load_order_group: "PNP_TDI", tag_id: 3, start_name: "", dependencies: [], description: "TCP/IP Protocol Driver", interactive: false, pid: 0, service_flags: 0, reset_period: 0, reboot_message: nil, command: nil, num_actions: 0, actions: nil, delayed_start: 0),
+ double("Struct::ServiceInfo", service_name: "W32Time", display_name: "Windows Time", service_type: "share process", current_state: "running", controls_accepted: ["netbind change", "param change", "shutdown", "stop", "hardware profile change", "power event"], win32_exit_code: 0, service_specific_exit_code: 0, check_point: 0, wait_hint: 0, binary_path_name: 'C:\\Windows\\system32\\svchost.exe -k LocalService', start_type: "demand start", error_control: "normal", load_order_group: "", tag_id: 0, start_name: 'NT AUTHORITY\\LocalService', dependencies: [], description: "Maintains date and time synchronization on all clients and servers in the network. If this service is stopped, date and time synchronization will be unavailable. If this service is disabled, any services that explicitly depend on it will fail to start.", interactive: false, pid: 844, service_flags: 0, reset_period: 86400, reboot_message: nil, command: nil, num_actions: 3, actions: { 1 => { action_type: "restart", delay: 60000 }, 2 => { action_type: "restart", delay: 120000 }, 3 => { action_type: "none", delay: 0 } }, delayed_start: 0),
+ double("Struct::ServiceInfo", service_name: "Winmgmt", display_name: "Windows Management Instrumentation", service_type: "share process", current_state: "running", controls_accepted: ["pause continue", "shutdown", "stop"], win32_exit_code: 0, service_specific_exit_code: 0, check_point: 0, wait_hint: 0, binary_path_name: 'C:\\Windows\\system32\\svchost.exe -k netsvcs', start_type: "auto start", error_control: "ignore", load_order_group: "", tag_id: 0, start_name: "localSystem", dependencies: ["RPCSS"], description: "Provides a common interface and object model to access management information about operating system, devices, applications and services. If this service is stopped, most Windows-based software will not function properly. If this service is disabled, any services that explicitly depend on it will fail to start.", interactive: false, pid: 812, service_flags: 0, reset_period: 86400, reboot_message: nil, command: nil, num_actions: 3, actions: { 1 => { action_type: "restart", delay: 120000 }, 2 => { action_type: "restart", delay: 300000 }, 3 => { action_type: "none", delay: 0 } }, delayed_start: 0),
+ double("Struct::ServiceInfo", service_name: "WinRM", display_name: "Windows Remote Management (WS-Management)", service_type: "share process", current_state: "running", controls_accepted: %w{shutdown stop}, win32_exit_code: 0, service_specific_exit_code: 0, check_point: 0, wait_hint: 0, binary_path_name: 'C:\\Windows\\System32\\svchost.exe -k NetworkService', start_type: "auto start", error_control: "normal", load_order_group: "", tag_id: 0, start_name: 'NT AUTHORITY\\NetworkService', dependencies: %w{RPCSS HTTP}, description: "Windows Remote Management (WinRM) service implements the WS-Management protocol for remote management. WS-Management is a standard web services protocol used for remote software and hardware management. The WinRM service listens on the network for WS-Management requests and processes them. The WinRM Service needs to be configured with a listener using winrm.cmd command line tool or through Group Policy in order for it to listen over the network. The WinRM service provides access to WMI data and enables event collection. Event collection and subscription to events require that the service is running. WinRM messages use HTTP and HTTPS as transports. The WinRM service does not depend on IIS but is preconfigured to share a port with IIS on the same machine. The WinRM service reserves the /wsman URL prefix. To prevent conflicts with IIS, administrators should ensure that any websites hosted on IIS do not use the /wsman URL prefix.", interactive: false, pid: 932, service_flags: 0, reset_period: 86400, reboot_message: nil, command: nil, num_actions: 3, actions: { 1 => { action_type: "restart", delay: 120000 }, 2 => { action_type: "restart", delay: 300000 }, 3 => { action_type: "none", delay: 0 } }, delayed_start: 0),
])
allow(Win32::Service).to receive(:exists?).and_return(true)
allow(Win32::Service).to receive(:configure).and_return(Win32::Service)
allow(Chef::ReservedNames::Win32::Security).to receive(:get_account_right).and_return([])
- allow(Chef::ReservedNames::Win32::Security).to receive(:add_account_right).with('LocalSystem', 'SeServiceLogonRight').and_return(0)
+ allow(Chef::ReservedNames::Win32::Security).to receive(:add_account_right).with("LocalSystem", "SeServiceLogonRight").and_return(0)
end
after(:each) do
@@ -153,9 +153,9 @@ describe Chef::Provider::Service::Windows, "load_current_resource" do
allow(Win32::Service).to receive(:exists?).with(chef_service_name).and_return(false)
end
- %w(running enabled startup_type error_control binary_path_name
- load_order_group dependencies run_as_user display_name ).each do |prop|
- it "does not set #{prop}" do
+ %w{running enabled startup_type error_control binary_path_name
+ load_order_group dependencies run_as_user display_name }.each do |prop|
+ it "does not set #{prop}" do
expect(provider.current_resource.running).to be_nil
end
end
@@ -166,31 +166,31 @@ describe Chef::Provider::Service::Windows, "load_current_resource" do
allow(Win32::Service).to receive(:exists?).with(chef_service_name).and_return(true)
allow(Win32::Service).to receive(:config_info).with(new_resource.service_name).and_return(
double("Struct::ServiceConfigInfo",
- service_type: 'share process',
- start_type: 'demand start',
- error_control: 'normal',
+ service_type: "share process",
+ start_type: "demand start",
+ error_control: "normal",
binary_path_name: 'C:\\Windows\\system32\\svchost.exe -k LocalServiceNetworkRestricted',
- load_order_group: 'TDI',
+ load_order_group: "TDI",
tag_id: 0,
- dependencies: %w(NSI Tdx Afd),
+ dependencies: %w{NSI Tdx Afd},
service_start_name: 'NT Authority\\LocalService',
- display_name: 'DHCP Client'
+ display_name: "DHCP Client"
))
end
- context 'startup_type is neither :automatic or :disabled' do
+ context "startup_type is neither :automatic or :disabled" do
before do
allow(Win32::Service).to receive(:config_info).with(new_resource.service_name).and_return(
double("Struct::ServiceConfigInfo",
- service_type: 'share process',
- start_type: 'demand start',
- error_control: 'normal',
+ service_type: "share process",
+ start_type: "demand start",
+ error_control: "normal",
binary_path_name: 'C:\\Windows\\system32\\svchost.exe -k LocalServiceNetworkRestricted',
- load_order_group: 'TDI',
+ load_order_group: "TDI",
tag_id: 0,
- dependencies: %w(NSI Tdx Afd),
+ dependencies: %w{NSI Tdx Afd},
service_start_name: 'NT Authority\\LocalService',
- display_name: 'DHCP Client'
+ display_name: "DHCP Client"
))
end
@@ -313,8 +313,8 @@ describe Chef::Provider::Service::Windows, "load_current_resource" do
start_type: 2,
error_control: 1,
binary_path_name: chef_service_binary_path_name,
- service_start_name: 'LocalSystem',
- desired_access: 983551,
+ service_start_name: "LocalSystem",
+ desired_access: 983551
)
provider.action_create
end
@@ -381,8 +381,8 @@ describe Chef::Provider::Service::Windows, "load_current_resource" do
end
# Attributes that are Strings
- %i(binary_path_name load_order_group dependencies run_as_user
- display_name).each do |attr|
+ %i{binary_path_name load_order_group dependencies run_as_user
+ display_name}.each do |attr|
it "configures service if #{attr} has changed" do
provider.current_resource.send("#{attr}=", "old value")
provider.new_resource.send("#{attr}=", "new value")
@@ -393,7 +393,7 @@ describe Chef::Provider::Service::Windows, "load_current_resource" do
end
# Attributes that are Integers
- %i(service_type error_control).each do |attr|
+ %i{service_type error_control}.each do |attr|
it "configures service if #{attr} has changed" do
provider.current_resource.send("#{attr}=", 1)
provider.new_resource.send("#{attr}=", 2)
@@ -784,7 +784,7 @@ describe Chef::Provider::Service::Windows, "load_current_resource" do
end
describe Chef::Provider::Service::Windows, "action_configure_startup" do
- %i[automatic manual disabled].each do |type|
+ %i{automatic manual disabled}.each do |type|
it "sets the startup type to #{type} if it is something else" do
new_resource.startup_type(type)
allow(provider).to receive(:current_startup_type).and_return(:fire)
diff --git a/spec/unit/resource/windows_service_spec.rb b/spec/unit/resource/windows_service_spec.rb
index 1b6b5e76d6..f5de5b6965 100644
--- a/spec/unit/resource/windows_service_spec.rb
+++ b/spec/unit/resource/windows_service_spec.rb
@@ -44,8 +44,8 @@ describe Chef::Resource::WindowsService, "initialize" do
end
# Attributes that are Strings
- %i(description service_name binary_path_name load_order_group dependencies
- run_as_user run_as_password display_name).each do |prop|
+ %i{description service_name binary_path_name load_order_group dependencies
+ run_as_user run_as_password display_name}.each do |prop|
it "support setting #{prop}" do
resource.send("#{prop}=", "some value")
expect(resource.send(prop)).to eq("some value")
@@ -53,7 +53,7 @@ describe Chef::Resource::WindowsService, "initialize" do
end
# Attributes that are Integers
- %i(desired_access error_control service_type).each do |prop|
+ %i{desired_access error_control service_type}.each do |prop|
it "support setting #{prop}" do
resource.send("#{prop}=", 1)
expect(resource.send(prop)).to eq(1)
@@ -61,7 +61,7 @@ describe Chef::Resource::WindowsService, "initialize" do
end
# Attributes that are Booleans
- %i(delayed_start).each do |prop|
+ %i{delayed_start}.each do |prop|
it "support setting #{prop}" do
resource.send("#{prop}=", true)
expect(resource.send(prop)).to eq(true)