summaryrefslogtreecommitdiffstats
path: root/spec/unit/provider/user/windows_adsi_spec.rb
diff options
context:
space:
mode:
authorJosh Cooper <josh@puppetlabs.com>2011-08-19 14:03:56 -0700
committerJosh Cooper <josh@puppetlabs.com>2011-08-19 14:03:56 -0700
commit384302af6dec8c51442f2f29a4c7c555379cd297 (patch)
tree27680b19648100058c752e5fa4136a88a73d7a4f /spec/unit/provider/user/windows_adsi_spec.rb
parent71e190bf255f98e900f7ddd55db393d448df3274 (diff)
parent2091cbeade9d69a18689609f407f9d7f0304dc04 (diff)
downloadpuppet-384302af6dec8c51442f2f29a4c7c555379cd297.tar.gz
puppet-384302af6dec8c51442f2f29a4c7c555379cd297.tar.xz
puppet-384302af6dec8c51442f2f29a4c7c555379cd297.zip
Merge branch 'backport-windows-work-to-2.7' into 2.7.x
* backport-windows-work-to-2.7: (60 commits) maint: Fix build break due to recent merge from 2.7.x to master Fix posix exec provider spec failures on Windows (#5495) Remove dead Windows-specific code from posix exec provider Stop trying to make config directories in Windows specs (#8272) Add missing tests for Windows service provider methods. (#8409) Add a default group provider for Windows (#8408) Add a default user provider for Windows (#8408/8409) Add a Windows ADSI helper module (#8663) Exclude exec timeout test on Windows (#8663) Exclude git rev-parse HEAD spec test on Windows Check for the appropriate permissions in File type tests on Windows Remove :fails_on_windows from file type tests that no longer fail on Windows Disable file bucket diffing tests on Windows Always put a slash between the checksum and path in filebucket URLs Treat Windows absolute paths as absolute paths Consolidate test logic determining if a registered file is in the temp directory Clarify logic and error messages when initializing Puppet::FileBucket::File Disable symlink related file tests on Windows (#8644) Host provider on Windows (#8660) Fix destdir option on Windows ...
Diffstat (limited to 'spec/unit/provider/user/windows_adsi_spec.rb')
-rw-r--r--spec/unit/provider/user/windows_adsi_spec.rb110
1 files changed, 110 insertions, 0 deletions
diff --git a/spec/unit/provider/user/windows_adsi_spec.rb b/spec/unit/provider/user/windows_adsi_spec.rb
new file mode 100644
index 000000000..073a3d328
--- /dev/null
+++ b/spec/unit/provider/user/windows_adsi_spec.rb
@@ -0,0 +1,110 @@
+#!/usr/bin/env ruby
+
+require 'spec_helper'
+
+describe Puppet::Type.type(:user).provider(:windows_adsi) do
+ let(:resource) do
+ Puppet::Type.type(:user).new(
+ :title => 'testuser',
+ :comment => 'Test J. User',
+ :provider => :windows_adsi
+ )
+ end
+
+ let(:provider) { resource.provider }
+
+ let(:connection) { stub 'connection' }
+
+ before :each do
+ Puppet::Util::ADSI.stubs(:computer_name).returns('testcomputername')
+ Puppet::Util::ADSI.stubs(:connect).returns connection
+ end
+
+ describe ".instances" do
+ it "should enumerate all users" do
+ names = ['user1', 'user2', 'user3']
+ stub_users = names.map{|n| stub(:name => n)}
+
+ connection.stubs(:execquery).with("select * from win32_useraccount").returns(stub_users)
+
+ described_class.instances.map(&:name).should =~ names
+ end
+ end
+
+ it "should provide access to a Puppet::Util::ADSI::User object" do
+ provider.user.should be_a(Puppet::Util::ADSI::User)
+ end
+
+ describe "when managing groups" do
+ it 'should return the list of groups as a comma-separated list' do
+ provider.user.stubs(:groups).returns ['group1', 'group2', 'group3']
+
+ provider.groups.should == 'group1,group2,group3'
+ end
+
+ it "should return absent if there are no groups" do
+ provider.user.stubs(:groups).returns []
+
+ provider.groups.should == ''
+ end
+
+ it 'should be able to add a user to a set of groups' do
+ resource[:membership] = :minimum
+ provider.user.expects(:set_groups).with('group1,group2', true)
+
+ provider.groups = 'group1,group2'
+
+ resource[:membership] = :inclusive
+ provider.user.expects(:set_groups).with('group1,group2', false)
+
+ provider.groups = 'group1,group2'
+ end
+ end
+
+ describe "when creating a user" do
+ it "should create the user on the system and set its other properties" do
+ resource[:groups] = ['group1', 'group2']
+ resource[:membership] = :inclusive
+ resource[:comment] = 'a test user'
+ resource[:home] = 'C:\Users\testuser'
+
+ user = stub 'user'
+ Puppet::Util::ADSI::User.expects(:create).with('testuser').returns user
+
+ user.stubs(:groups).returns(['group2', 'group3'])
+
+ user.expects(:set_groups).with('group1,group2', false)
+ user.expects(:[]=).with('Description', 'a test user')
+ user.expects(:[]=).with('HomeDirectory', 'C:\Users\testuser')
+
+ provider.create
+ end
+ end
+
+ it 'should be able to test whether a user exists' do
+ Puppet::Util::ADSI.stubs(:connect).returns stub('connection')
+ provider.should be_exists
+
+ Puppet::Util::ADSI.stubs(:connect).returns nil
+ provider.should_not be_exists
+ end
+
+ it 'should be able to delete a user' do
+ connection.expects(:Delete).with('user', 'testuser')
+
+ provider.delete
+ end
+
+ it "should commit the user when flushed" do
+ provider.user.expects(:commit)
+
+ provider.flush
+ end
+
+ [:uid, :gid, :shell].each do |prop|
+ it "should warn when trying to manage the #{prop} property" do
+ provider.expects(:warning).with { |msg| msg =~ /No support for managing property #{prop}/ }
+ provider.send("#{prop}=", 'foo')
+ end
+ end
+end