summaryrefslogtreecommitdiff
path: root/spec/functional/win32/service_manager_spec.rb
diff options
context:
space:
mode:
authorChris Doherty <cdoherty@getchef.com>2014-10-21 14:09:04 -0700
committerChris Doherty <cdoherty@getchef.com>2014-12-19 16:24:03 -0800
commitbe28ba90bde1fe0240f313151e3d564ce57e8b29 (patch)
treeae83d0079f55c07452dba11982d1e73f76638368 /spec/functional/win32/service_manager_spec.rb
parent3569079f9831b5e14e8e46b51840f3b6a069d9eb (diff)
downloadchef-be28ba90bde1fe0240f313151e3d564ce57e8b29.tar.gz
Enable Windows services to run as a different user (CHEF-4921). This adds :run_as_user andcdoherty-enhance-win-service
:run_as_password attributes to the windows_service resource. If a logon user is specified, the resource will (on every run) grant the logon-as-service privilege to that user, using secedit.exe.
Diffstat (limited to 'spec/functional/win32/service_manager_spec.rb')
-rw-r--r--spec/functional/win32/service_manager_spec.rb60
1 files changed, 3 insertions, 57 deletions
diff --git a/spec/functional/win32/service_manager_spec.rb b/spec/functional/win32/service_manager_spec.rb
index fd21e7d82e..d2474deace 100644
--- a/spec/functional/win32/service_manager_spec.rb
+++ b/spec/functional/win32/service_manager_spec.rb
@@ -24,7 +24,7 @@ end
#
# ATTENTION:
# This test creates a windows service for testing purposes and runs it
-# as Local System on windows boxes.
+# as Local System (or an otherwise specified user) on windows boxes.
# This test will fail if you run the tests inside a Windows VM by
# sharing the code from your host since Local System account by
# default can't see the mounted partitions.
@@ -35,61 +35,7 @@ end
describe "Chef::Application::WindowsServiceManager", :windows_only, :system_windows_service_gem_only do
- # Some helper methods.
-
- def test_service_exists?
- ::Win32::Service.exists?("spec-service")
- end
-
- def test_service_state
- ::Win32::Service.status("spec-service").current_state
- end
-
- def service_manager
- Chef::Application::WindowsServiceManager.new(test_service)
- end
-
- def cleanup
- # Uninstall if the test service is installed.
- if test_service_exists?
-
- # We can only uninstall when the service is stopped.
- if test_service_state != "stopped"
- ::Win32::Service.send("stop", "spec-service")
- while test_service_state != "stopped"
- sleep 1
- end
- end
-
- ::Win32::Service.delete("spec-service")
- end
-
- # Delete the test_service_file if it exists
- if File.exists?(test_service_file)
- File.delete(test_service_file)
- end
-
- end
-
-
- # Definition for the test-service
-
- let(:test_service) {
- {
- :service_name => "spec-service",
- :service_display_name => "Spec Test Service",
- :service_description => "Service for testing Chef::Application::WindowsServiceManager.",
- :service_file_path => File.expand_path(File.join(File.dirname(__FILE__), '../../support/platforms/win32/spec_service.rb'))
- }
- }
-
- # Test service creates a file for us to verify that it is running.
- # Since our test service is running as Local System we should look
- # for the file it creates under SYSTEM temp directory
-
- let(:test_service_file) {
- "#{ENV['SystemDrive']}\\windows\\temp\\spec_service_file"
- }
+ include_context "using Win32::Service"
context "with invalid service definition" do
it "throws an error when initialized with no service definition" do
@@ -190,7 +136,7 @@ describe "Chef::Application::WindowsServiceManager", :windows_only, :system_wind
["pause", "resume"].each do |action|
it "#{action} => should raise error" do
- expect {service_manager.run(["-a", action])}.to raise_error(::Win32::Service::Error)
+ expect { service_manager.run(["-a", action]) }.to raise_error(SystemCallError)
end
end