summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJay Mundrawala <jdmundrawala@gmail.com>2015-05-11 07:05:05 -0700
committerJay Mundrawala <jdmundrawala@gmail.com>2015-05-15 08:51:22 -0700
commit17f8cfa294888ccaf224f3830bc430bd049b654c (patch)
tree33dffea58d1b04f464611152b2c34d7498d85df4
parent217d873e4a5c2e22bd29783b9ae138f8889d60e6 (diff)
downloadchef-17f8cfa294888ccaf224f3830bc430bd049b654c.tar.gz
Added functional tests for user resource on windows
-rw-r--r--spec/functional/resource/user/windows_spec.rb125
1 files changed, 125 insertions, 0 deletions
diff --git a/spec/functional/resource/user/windows_spec.rb b/spec/functional/resource/user/windows_spec.rb
new file mode 100644
index 0000000000..5e68478b34
--- /dev/null
+++ b/spec/functional/resource/user/windows_spec.rb
@@ -0,0 +1,125 @@
+# Author:: Jay Mundrawala (<jdm@chef.io>)
+# Copyright:: Copyright (c) 2015 Chef Software
+# 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'
+require 'chef/mixin/shell_out'
+
+describe Chef::Provider::User::Windows, :windows_only do
+ include Chef::Mixin::ShellOut
+
+ let(:username) { 'ChefFunctionalTest' }
+ let(:password) { SecureRandom.uuid }
+
+ let(:node) do
+ n = Chef::Node.new
+ n.consume_external_attrs(OHAI_SYSTEM.data.dup, {})
+ n
+ end
+
+ let(:events) { Chef::EventDispatch::Dispatcher.new }
+ let(:run_context) { Chef::RunContext.new(node, {}, events) }
+ let(:new_resource) do
+ Chef::Resource::User.new(username, run_context).tap do |r|
+ r.provider(Chef::Provider::User::Windows)
+ r.password(password)
+ end
+ end
+
+ def delete_user(u)
+ shell_out("net user #{u} /delete")
+ end
+
+ before do
+ delete_user(username)
+ end
+
+ describe 'action :create' do
+ it 'creates a user when a username and password are given' do
+ new_resource.run_action(:create)
+ expect(new_resource).to be_updated_by_last_action
+ expect(shell_out("net user #{username}").exitstatus).to eq(0)
+ end
+
+ it 'reports no changes if there are no changes needed' do
+ new_resource.run_action(:create)
+ new_resource.run_action(:create)
+ expect(new_resource).not_to be_updated_by_last_action
+ end
+
+ it 'allows chaning the password' do
+ new_resource.run_action(:create)
+ new_resource.password(SecureRandom.uuid)
+ new_resource.run_action(:create)
+ expect(new_resource).to be_updated_by_last_action
+ end
+ end
+
+ describe 'action :remove' do
+ before do
+ new_resource.run_action(:create)
+ end
+
+ it 'deletes the user' do
+ new_resource.run_action(:remove)
+ expect(new_resource).to be_updated_by_last_action
+ expect(shell_out("net user #{username}").exitstatus).to eq(2)
+ end
+
+ it 'is idempotent' do
+ new_resource.run_action(:remove)
+ new_resource.run_action(:remove)
+ expect(new_resource).not_to be_updated_by_last_action
+ end
+ end
+
+ describe 'action :lock' do
+ before do
+ new_resource.run_action(:create)
+ end
+
+ it 'locks the user account' do
+ new_resource.run_action(:lock)
+ expect(new_resource).to be_updated_by_last_action
+ expect(shell_out("net user #{username}").stdout).to match(/Account active\s*No/)
+ end
+
+ it 'is idempotent' do
+ new_resource.run_action(:lock)
+ new_resource.run_action(:lock)
+ expect(new_resource).not_to be_updated_by_last_action
+ end
+ end
+
+ describe 'action :unlock' do
+ before do
+ new_resource.run_action(:create)
+ new_resource.run_action(:lock)
+ end
+
+ it 'unlocks the user account' do
+ new_resource.run_action(:unlock)
+ expect(new_resource).to be_updated_by_last_action
+ expect(shell_out("net user #{username}").stdout).to match(/Account active\s*Yes/)
+ end
+
+ it 'is idempotent' do
+ new_resource.run_action(:unlock)
+ new_resource.run_action(:unlock)
+ expect(new_resource).not_to be_updated_by_last_action
+ end
+ end
+end