diff options
author | Luke Kanies <luke@madstop.com> | 2008-05-21 00:30:24 -0500 |
---|---|---|
committer | Luke Kanies <luke@madstop.com> | 2008-05-21 00:30:24 -0500 |
commit | 4434072c7f51e4720b40aaea0637cb94dc6aefe5 (patch) | |
tree | deaff95e8283e62f4909964cd09a4193e560db79 | |
parent | 419f2443c40116623b5c82f03eafcc85deeabcad (diff) | |
download | puppet-4434072c7f51e4720b40aaea0637cb94dc6aefe5.tar.gz puppet-4434072c7f51e4720b40aaea0637cb94dc6aefe5.tar.xz puppet-4434072c7f51e4720b40aaea0637cb94dc6aefe5.zip |
The ldap user/group providers now work when no users/groups are in ldap yet.
Previously, they failed if you tried to get them to autogenerate
an id, because they assumed that a result would be returned.
-rw-r--r-- | lib/puppet/provider/group/ldap.rb | 14 | ||||
-rw-r--r-- | lib/puppet/provider/user/ldap.rb | 14 | ||||
-rwxr-xr-x | spec/unit/provider/group/ldap.rb | 22 | ||||
-rwxr-xr-x | spec/unit/provider/user/ldap.rb | 31 |
4 files changed, 52 insertions, 29 deletions
diff --git a/lib/puppet/provider/group/ldap.rb b/lib/puppet/provider/group/ldap.rb index 5af400a4e..a4870fc68 100644 --- a/lib/puppet/provider/group/ldap.rb +++ b/lib/puppet/provider/group/ldap.rb @@ -23,12 +23,14 @@ Puppet::Type.type(:group).provide :ldap, :parent => Puppet::Provider::Ldap do # Find the next gid after the current largest gid. provider = self manager.generates(:gidNumber).with do - largest = 0 - provider.manager.search.each do |hash| - next unless value = hash[:gid] - num = value[0].to_i - if num > largest - largest = num + largest = 500 + if existing = provider.manager.search + existing.each do |hash| + next unless value = hash[:gid] + num = value[0].to_i + if num > largest + largest = num + end end end largest + 1 diff --git a/lib/puppet/provider/user/ldap.rb b/lib/puppet/provider/user/ldap.rb index d670ad435..0d149ac9a 100644 --- a/lib/puppet/provider/user/ldap.rb +++ b/lib/puppet/provider/user/ldap.rb @@ -32,12 +32,14 @@ Puppet::Type.type(:user).provide :ldap, :parent => Puppet::Provider::Ldap do # Find the next uid after the current largest uid. provider = self manager.generates(:uidNumber).with do - largest = 0 - provider.manager.search.each do |hash| - next unless value = hash[:uid] - num = value[0].to_i - if num > largest - largest = num + largest = 500 + if existing = provider.manager.search + existing.each do |hash| + next unless value = hash[:uid] + num = value[0].to_i + if num > largest + largest = num + end end end largest + 1 diff --git a/spec/unit/provider/group/ldap.rb b/spec/unit/provider/group/ldap.rb index 3f12d74e3..53d9e8bfc 100755 --- a/spec/unit/provider/group/ldap.rb +++ b/spec/unit/provider/group/ldap.rb @@ -45,8 +45,8 @@ describe provider_class do describe "with no gid specified" do it "should pick the first available GID after the largest existing GID" do - low = {:name=>["luke"], :gid=>["100"]} - high = {:name=>["testing"], :gid=>["140"]} + low = {:name=>["luke"], :gid=>["600"]} + high = {:name=>["testing"], :gid=>["640"]} provider_class.manager.expects(:search).returns([low, high]) resource = stub 'resource', :should => %w{whatever} @@ -55,12 +55,26 @@ describe provider_class do instance = provider_class.new(:name => "luke", :ensure => :absent) instance.stubs(:resource).returns resource - @connection.expects(:add).with { |dn, attrs| attrs["gidNumber"] == ["141"] } + @connection.expects(:add).with { |dn, attrs| attrs["gidNumber"] == ["641"] } + + instance.create + instance.flush + end + + it "should pick '501' as its GID if no groups are found" do + provider_class.manager.expects(:search).returns nil + + resource = stub 'resource', :should => %w{whatever} + resource.stubs(:should).with(:gid).returns nil + resource.stubs(:should).with(:ensure).returns :present + instance = provider_class.new(:name => "luke", :ensure => :absent) + instance.stubs(:resource).returns resource + + @connection.expects(:add).with { |dn, attrs| attrs["gidNumber"] == ["501"] } instance.create instance.flush end end end - end diff --git a/spec/unit/provider/user/ldap.rb b/spec/unit/provider/user/ldap.rb index eb13d8bbd..90fc7423f 100755 --- a/spec/unit/provider/user/ldap.rb +++ b/spec/unit/provider/user/ldap.rb @@ -24,16 +24,6 @@ describe provider_class do provider_class.manager.rdn.should == :uid end - it "should be unsuitable if ldap is unavailable" do - Puppet.features.expects(:ldap?).returns false - provider_class.should_not be_suitable - end - - it "should be suitable if ldap is available" do - Puppet.features.expects(:ldap?).returns true - provider_class.should be_suitable - end - {:name => "uid", :password => "userPassword", :comment => "cn", @@ -69,8 +59,8 @@ describe provider_class do describe "with no uid specified" do it "should pick the first available UID after the largest existing UID" do - low = {:name=>["luke"], :shell=>:absent, :uid=>["100"], :home=>["/h"], :gid=>["1000"], :password=>["blah"], :comment=>["l k"]} - high = {:name=>["testing"], :shell=>:absent, :uid=>["140"], :home=>["/h"], :gid=>["1000"], :password=>["blah"], :comment=>["t u"]} + low = {:name=>["luke"], :shell=>:absent, :uid=>["600"], :home=>["/h"], :gid=>["1000"], :password=>["blah"], :comment=>["l k"]} + high = {:name=>["testing"], :shell=>:absent, :uid=>["640"], :home=>["/h"], :gid=>["1000"], :password=>["blah"], :comment=>["t u"]} provider_class.manager.expects(:search).returns([low, high]) resource = stub 'resource', :should => %w{whatever} @@ -79,7 +69,22 @@ describe provider_class do instance = provider_class.new(:name => "luke", :ensure => :absent) instance.stubs(:resource).returns resource - @connection.expects(:add).with { |dn, attrs| attrs["uidNumber"] == ["141"] } + @connection.expects(:add).with { |dn, attrs| attrs["uidNumber"] == ["641"] } + + instance.create + instance.flush + end + + it "should pick 501 of no users exist" do + provider_class.manager.expects(:search).returns nil + + resource = stub 'resource', :should => %w{whatever} + resource.stubs(:should).with(:uid).returns nil + resource.stubs(:should).with(:ensure).returns :present + instance = provider_class.new(:name => "luke", :ensure => :absent) + instance.stubs(:resource).returns resource + + @connection.expects(:add).with { |dn, attrs| attrs["uidNumber"] == ["501"] } instance.create instance.flush |