diff options
author | tyler-ball <tyleraball@gmail.com> | 2014-12-29 15:00:52 -0800 |
---|---|---|
committer | tyler-ball <tyleraball@gmail.com> | 2014-12-29 15:00:52 -0800 |
commit | 43eba1778fab8bc440f97824af7227476457a65c (patch) | |
tree | 5e967abff042f8a7279c3ad049b54cf7a009f6cb /spec/functional | |
parent | 4a91e5e40972f0be7e71aba4615b1f76affeafc6 (diff) | |
parent | b7b7dad4e476b3fde67f0d9881e15efe7e5b60ac (diff) | |
download | chef-43eba1778fab8bc440f97824af7227476457a65c.tar.gz |
Merging master to audit-mode
Diffstat (limited to 'spec/functional')
-rw-r--r-- | spec/functional/knife/ssh_spec.rb | 2 | ||||
-rw-r--r-- | spec/functional/resource/windows_service_spec.rb | 98 | ||||
-rw-r--r-- | spec/functional/win32/service_manager_spec.rb | 60 |
3 files changed, 102 insertions, 58 deletions
diff --git a/spec/functional/knife/ssh_spec.rb b/spec/functional/knife/ssh_spec.rb index cde702e8b2..5b8ad6f368 100644 --- a/spec/functional/knife/ssh_spec.rb +++ b/spec/functional/knife/ssh_spec.rb @@ -260,7 +260,7 @@ describe Chef::Knife::Ssh do Chef::Config[:client_key] = nil Chef::Config[:chef_server_url] = 'http://localhost:9000' - @api.get("/search/node?q=*:*&sort=X_CHEF_id_CHEF_X%20asc&start=0&rows=1000", 200) { + @api.get("/search/node?q=*:*&sort=X_CHEF_id_CHEF_X%20asc&start=0", 200) { %({"total":1, "start":0, "rows":[{"name":"i-xxxxxxxx", "json_class":"Chef::Node", "automatic":{"fqdn":"the.fqdn", "ec2":{"public_hostname":"the_public_hostname"}},"recipes":[]}]}) } end diff --git a/spec/functional/resource/windows_service_spec.rb b/spec/functional/resource/windows_service_spec.rb new file mode 100644 index 0000000000..29d1fc42c3 --- /dev/null +++ b/spec/functional/resource/windows_service_spec.rb @@ -0,0 +1,98 @@ +# +# Author:: Chris Doherty (<cdoherty@chef.io>) +# Copyright:: Copyright (c) 2014 Chef Software, Inc. +# License:: Apache License, Version 2.0 +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +require 'spec_helper' + +describe Chef::Resource::WindowsService, :windows_only, :system_windows_service_gem_only do + + include_context "using Win32::Service" + + let(:username) { "service_spec_user"} + let(:qualified_username) { ".\\#{username}"} + let(:password) { "1a2b3c4X!&narf"} + + let(:user_resource) { + r = Chef::Resource::User.new(username, run_context) + r.username(username) + r.password(password) + r.comment("temp spec user") + r + } + + let(:global_service_file_path) { + "#{ENV['WINDIR']}\\temp\\#{File.basename(test_service[:service_file_path])}" + } + + let(:service_params) { + + id = "#{$$}_#{rand(1000)}" + + test_service.merge( { + run_as_user: qualified_username, + run_as_password: password, + service_name: "spec_service_#{id}", + service_display_name: "windows_service spec #{id}}", + service_description: "Test service for running the windows_service functional spec.", + service_file_path: global_service_file_path, + } ) + } + + let(:manager) { + Chef::Application::WindowsServiceManager.new(service_params) + } + + let(:service_resource) { + r = Chef::Resource::WindowsService.new(service_params[:service_name], run_context) + [:run_as_user, :run_as_password].each { |prop| r.send(prop, service_params[prop]) } + r + } + + before { + user_resource.run_action(:create) + + # the service executable has to be outside the current user's home + # directory in order for the logon user to execute it. + FileUtils::copy_file(test_service[:service_file_path], global_service_file_path) + + # if you don't make the file executable by the service user, you'll get + # the not-very-helpful "service did not respond fast enough" error. + + # #mode may break in a post-Windows 8.1 release, and have to be replaced + # with the rights stuff in the file resource. + file = Chef::Resource::File.new(global_service_file_path, run_context) + file.mode("0777") + + file.run_action(:create) + + manager.run(%w{--action install}) + } + + after { + user_resource.run_action(:remove) + manager.run(%w{--action uninstall}) + File.delete(global_service_file_path) + } + + describe "logon as a service" do + it "successfully runs a service as another user" do + service_resource.run_action(:start) + end + + it "raises an exception when it can't grant the logon privilege" + end +end 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 |