summaryrefslogtreecommitdiffstats
path: root/spec/unit/provider/user
diff options
context:
space:
mode:
authorMarkus Roberts <Markus@reality.com>2010-07-09 18:12:17 -0700
committerMarkus Roberts <Markus@reality.com>2010-07-09 18:12:17 -0700
commit3180b9d9b2c844dade1d361326600f7001ec66dd (patch)
tree98fe7c5ac7eb942aac9c39f019a17b0b3f5a57f4 /spec/unit/provider/user
parent543225970225de5697734bfaf0a6eee996802c04 (diff)
downloadpuppet-3180b9d9b2c844dade1d361326600f7001ec66dd.tar.gz
puppet-3180b9d9b2c844dade1d361326600f7001ec66dd.tar.xz
puppet-3180b9d9b2c844dade1d361326600f7001ec66dd.zip
Code smell: Two space indentation
Replaced 106806 occurances of ^( +)(.*$) with The ruby community almost universally (i.e. everyone but Luke, Markus, and the other eleven people who learned ruby in the 1900s) uses two-space indentation. 3 Examples: The code: end # Tell getopt which arguments are valid def test_get_getopt_args element = Setting.new :name => "foo", :desc => "anything", :settings => Puppet::Util::Settings.new assert_equal([["--foo", GetoptLong::REQUIRED_ARGUMENT]], element.getopt_args, "Did not produce appropriate getopt args") becomes: end # Tell getopt which arguments are valid def test_get_getopt_args element = Setting.new :name => "foo", :desc => "anything", :settings => Puppet::Util::Settings.new assert_equal([["--foo", GetoptLong::REQUIRED_ARGUMENT]], element.getopt_args, "Did not produce appropriate getopt args") The code: assert_equal(str, val) assert_instance_of(Float, result) end # Now test it with a passed object becomes: assert_equal(str, val) assert_instance_of(Float, result) end # Now test it with a passed object The code: end assert_nothing_raised do klass[:Yay] = "boo" klass["Cool"] = :yayness end becomes: end assert_nothing_raised do klass[:Yay] = "boo" klass["Cool"] = :yayness end
Diffstat (limited to 'spec/unit/provider/user')
-rwxr-xr-xspec/unit/provider/user/hpux_spec.rb30
-rwxr-xr-xspec/unit/provider/user/ldap_spec.rb406
-rw-r--r--spec/unit/provider/user/user_role_add_spec.rb478
-rwxr-xr-xspec/unit/provider/user/useradd_spec.rb186
4 files changed, 550 insertions, 550 deletions
diff --git a/spec/unit/provider/user/hpux_spec.rb b/spec/unit/provider/user/hpux_spec.rb
index 4129a7ab6..f53f6c31e 100755
--- a/spec/unit/provider/user/hpux_spec.rb
+++ b/spec/unit/provider/user/hpux_spec.rb
@@ -5,21 +5,21 @@ require File.dirname(__FILE__) + '/../../../spec_helper'
provider_class = Puppet::Type.type(:user).provider(:hpuxuseradd)
describe provider_class do
- # left from the useradd test... I have no clue what I'm doing.
- before do
- @resource = stub("resource", :name => "myuser", :managehome? => nil, :should => "fakeval", :[] => "fakeval")
- @provider = provider_class.new(@resource)
- end
+ # left from the useradd test... I have no clue what I'm doing.
+ before do
+ @resource = stub("resource", :name => "myuser", :managehome? => nil, :should => "fakeval", :[] => "fakeval")
+ @provider = provider_class.new(@resource)
+ end
- it "should add -F when modifying a user" do
- @resource.expects(:allowdupe?).returns true
- @provider.expects(:execute).with { |args| args.include?("-F") }
- @provider.uid = 1000
- end
+ it "should add -F when modifying a user" do
+ @resource.expects(:allowdupe?).returns true
+ @provider.expects(:execute).with { |args| args.include?("-F") }
+ @provider.uid = 1000
+ end
- it "should add -F when deleting a user" do
- @provider.stubs(:exists?).returns(true)
- @provider.expects(:execute).with { |args| args.include?("-F") }
- @provider.delete
- end
+ it "should add -F when deleting a user" do
+ @provider.stubs(:exists?).returns(true)
+ @provider.expects(:execute).with { |args| args.include?("-F") }
+ @provider.delete
+ end
end
diff --git a/spec/unit/provider/user/ldap_spec.rb b/spec/unit/provider/user/ldap_spec.rb
index adc2180ff..b6635705d 100755
--- a/spec/unit/provider/user/ldap_spec.rb
+++ b/spec/unit/provider/user/ldap_spec.rb
@@ -8,272 +8,272 @@ require File.dirname(__FILE__) + '/../../../spec_helper'
provider_class = Puppet::Type.type(:user).provider(:ldap)
describe provider_class do
- it "should have the Ldap provider class as its baseclass" do
- provider_class.superclass.should equal(Puppet::Provider::Ldap)
+ it "should have the Ldap provider class as its baseclass" do
+ provider_class.superclass.should equal(Puppet::Provider::Ldap)
+ end
+
+ it "should manage :posixAccount and :person objectclasses" do
+ provider_class.manager.objectclasses.should == [:posixAccount, :person]
+ end
+
+ it "should use 'ou=People' as its relative base" do
+ provider_class.manager.location.should == "ou=People"
+ end
+
+ it "should use :uid as its rdn" do
+ provider_class.manager.rdn.should == :uid
+ end
+
+ it "should be able to manage passwords" do
+ provider_class.should be_manages_passwords
+ end
+
+ it "should use the ldap group provider to convert group names to numbers" do
+ provider = provider_class.new(:name => "foo")
+ Puppet::Type.type(:group).provider(:ldap).expects(:name2id).with("bar").returns 10
+
+ provider.gid = 'bar'
+ provider.gid.should == 10
+ end
+
+ {:name => "uid",
+ :password => "userPassword",
+ :comment => "cn",
+ :uid => "uidNumber",
+ :gid => "gidNumber",
+ :home => "homeDirectory",
+ :shell => "loginShell"
+ }.each do |puppet, ldap|
+ it "should map :#{puppet.to_s} to '#{ldap}'" do
+ provider_class.manager.ldap_name(puppet).should == ldap
end
+ end
- it "should manage :posixAccount and :person objectclasses" do
- provider_class.manager.objectclasses.should == [:posixAccount, :person]
+ describe "when being created" do
+ before do
+ # So we don't try to actually talk to ldap
+ @connection = mock 'connection'
+ provider_class.manager.stubs(:connect).yields @connection
end
- it "should use 'ou=People' as its relative base" do
- provider_class.manager.location.should == "ou=People"
- end
+ it "should generate the sn as the last field of the cn" do
+ resource = stub 'resource', :should => %w{whatever}
+ resource.stubs(:should).with(:comment).returns ["Luke Kanies"]
+ resource.stubs(:should).with(:ensure).returns :present
+ instance = provider_class.new(:name => "luke", :ensure => :absent)
+ instance.stubs(:resource).returns resource
- it "should use :uid as its rdn" do
- provider_class.manager.rdn.should == :uid
- end
+ @connection.expects(:add).with { |dn, attrs| attrs["sn"] == ["Kanies"] }
- it "should be able to manage passwords" do
- provider_class.should be_manages_passwords
+ instance.create
+ instance.flush
end
- it "should use the ldap group provider to convert group names to numbers" do
- provider = provider_class.new(:name => "foo")
- Puppet::Type.type(:group).provider(:ldap).expects(:name2id).with("bar").returns 10
+ 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=>["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])
- provider.gid = 'bar'
- provider.gid.should == 10
- end
+ 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
- {:name => "uid",
- :password => "userPassword",
- :comment => "cn",
- :uid => "uidNumber",
- :gid => "gidNumber",
- :home => "homeDirectory",
- :shell => "loginShell"
- }.each do |puppet, ldap|
- it "should map :#{puppet.to_s} to '#{ldap}'" do
- provider_class.manager.ldap_name(puppet).should == ldap
- end
- end
+ @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
- describe "when being created" do
- before do
- # So we don't try to actually talk to ldap
- @connection = mock 'connection'
- provider_class.manager.stubs(:connect).yields @connection
- end
-
- it "should generate the sn as the last field of the cn" do
- resource = stub 'resource', :should => %w{whatever}
- resource.stubs(:should).with(:comment).returns ["Luke Kanies"]
- 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["sn"] == ["Kanies"] }
-
- instance.create
- instance.flush
- end
-
- 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=>["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}
- 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"] == ["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
- end
- end
+ 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
+ end
end
+ end
- describe "when flushing" do
- before do
- provider_class.stubs(:suitable?).returns true
+ describe "when flushing" do
+ before do
+ provider_class.stubs(:suitable?).returns true
- @instance = provider_class.new(:name => "myname", :groups => %w{whatever}, :uid => "400")
- end
+ @instance = provider_class.new(:name => "myname", :groups => %w{whatever}, :uid => "400")
+ end
- it "should remove the :groups value before updating" do
- @instance.class.manager.expects(:update).with { |name, ldap, puppet| puppet[:groups].nil? }
+ it "should remove the :groups value before updating" do
+ @instance.class.manager.expects(:update).with { |name, ldap, puppet| puppet[:groups].nil? }
- @instance.flush
- end
+ @instance.flush
+ end
- it "should empty the property hash" do
- @instance.class.manager.stubs(:update)
+ it "should empty the property hash" do
+ @instance.class.manager.stubs(:update)
- @instance.flush
+ @instance.flush
- @instance.uid.should == :absent
- end
+ @instance.uid.should == :absent
+ end
- it "should empty the ldap property hash" do
- @instance.class.manager.stubs(:update)
+ it "should empty the ldap property hash" do
+ @instance.class.manager.stubs(:update)
- @instance.flush
+ @instance.flush
- @instance.ldap_properties[:uid].should be_nil
- end
+ @instance.ldap_properties[:uid].should be_nil
end
+ end
- describe "when checking group membership" do
- before do
- @groups = Puppet::Type.type(:group).provider(:ldap)
- @group_manager = @groups.manager
- provider_class.stubs(:suitable?).returns true
+ describe "when checking group membership" do
+ before do
+ @groups = Puppet::Type.type(:group).provider(:ldap)
+ @group_manager = @groups.manager
+ provider_class.stubs(:suitable?).returns true
- @instance = provider_class.new(:name => "myname")
- end
+ @instance = provider_class.new(:name => "myname")
+ end
- it "should show its group membership as the sorted list of all groups returned by an ldap query of group memberships" do
- one = {:name => "one"}
- two = {:name => "two"}
- @group_manager.expects(:search).with("memberUid=myname").returns([two, one])
+ it "should show its group membership as the sorted list of all groups returned by an ldap query of group memberships" do
+ one = {:name => "one"}
+ two = {:name => "two"}
+ @group_manager.expects(:search).with("memberUid=myname").returns([two, one])
- @instance.groups.should == "one,two"
- end
+ @instance.groups.should == "one,two"
+ end
- it "should show its group membership as :absent if no matching groups are found in ldap" do
- @group_manager.expects(:search).with("memberUid=myname").returns(nil)
+ it "should show its group membership as :absent if no matching groups are found in ldap" do
+ @group_manager.expects(:search).with("memberUid=myname").returns(nil)
- @instance.groups.should == :absent
- end
+ @instance.groups.should == :absent
+ end
- it "should cache the group value" do
- @group_manager.expects(:search).with("memberUid=myname").once.returns nil
+ it "should cache the group value" do
+ @group_manager.expects(:search).with("memberUid=myname").once.returns nil
- @instance.groups
- @instance.groups.should == :absent
- end
+ @instance.groups
+ @instance.groups.should == :absent
end
+ end
- describe "when modifying group membership" do
- before do
- @groups = Puppet::Type.type(:group).provider(:ldap)
- @group_manager = @groups.manager
- provider_class.stubs(:suitable?).returns true
+ describe "when modifying group membership" do
+ before do
+ @groups = Puppet::Type.type(:group).provider(:ldap)
+ @group_manager = @groups.manager
+ provider_class.stubs(:suitable?).returns true
- @one = {:name => "one", :gid => "500"}
- @group_manager.stubs(:find).with("one").returns(@one)
+ @one = {:name => "one", :gid => "500"}
+ @group_manager.stubs(:find).with("one").returns(@one)
- @two = {:name => "one", :gid => "600"}
- @group_manager.stubs(:find).with("two").returns(@two)
+ @two = {:name => "one", :gid => "600"}
+ @group_manager.stubs(:find).with("two").returns(@two)
- @instance = provider_class.new(:name => "myname")
+ @instance = provider_class.new(:name => "myname")
- @instance.stubs(:groups).returns :absent
- end
+ @instance.stubs(:groups).returns :absent
+ end
- it "should fail if the group does not exist" do
- @group_manager.expects(:find).with("mygroup").returns nil
+ it "should fail if the group does not exist" do
+ @group_manager.expects(:find).with("mygroup").returns nil
- lambda { @instance.groups = "mygroup" }.should raise_error(Puppet::Error)
- end
+ lambda { @instance.groups = "mygroup" }.should raise_error(Puppet::Error)
+ end
- it "should only pass the attributes it cares about to the group manager" do
- @group_manager.expects(:update).with { |name, attrs| attrs[:gid].nil? }
+ it "should only pass the attributes it cares about to the group manager" do
+ @group_manager.expects(:update).with { |name, attrs| attrs[:gid].nil? }
- @instance.groups = "one"
- end
+ @instance.groups = "one"
+ end
- it "should always include :ensure => :present in the current values" do
- @group_manager.expects(:update).with { |name, is, should| is[:ensure] == :present }
+ it "should always include :ensure => :present in the current values" do
+ @group_manager.expects(:update).with { |name, is, should| is[:ensure] == :present }
- @instance.groups = "one"
- end
+ @instance.groups = "one"
+ end
- it "should always include :ensure => :present in the desired values" do
- @group_manager.expects(:update).with { |name, is, should| should[:ensure] == :present }
+ it "should always include :ensure => :present in the desired values" do
+ @group_manager.expects(:update).with { |name, is, should| should[:ensure] == :present }
- @instance.groups = "one"
- end
+ @instance.groups = "one"
+ end
- it "should always pass the group's original member list" do
- @one[:members] = %w{yay ness}
- @group_manager.expects(:update).with { |name, is, should| is[:members] == %w{yay ness} }
+ it "should always pass the group's original member list" do
+ @one[:members] = %w{yay ness}
+ @group_manager.expects(:update).with { |name, is, should| is[:members] == %w{yay ness} }
- @instance.groups = "one"
- end
+ @instance.groups = "one"
+ end
- it "should find the group again when resetting its member list, so it has the full member list" do
- @group_manager.expects(:find).with("one").returns(@one)
+ it "should find the group again when resetting its member list, so it has the full member list" do
+ @group_manager.expects(:find).with("one").returns(@one)
- @group_manager.stubs(:update)
+ @group_manager.stubs(:update)
- @instance.groups = "one"
- end
+ @instance.groups = "one"
+ end
- describe "for groups that have no members" do
- it "should create a new members attribute with its value being the user's name" do
- @group_manager.expects(:update).with { |name, is, should| should[:members] == %w{myname} }
+ describe "for groups that have no members" do
+ it "should create a new members attribute with its value being the user's name" do
+ @group_manager.expects(:update).with { |name, is, should| should[:members] == %w{myname} }
- @instance.groups = "one"
- end
- end
+ @instance.groups = "one"
+ end
+ end
- describe "for groups it is being removed from" do
- it "should replace the group's member list with one missing the user's name" do
- @one[:members] = %w{myname a}
- @two[:members] = %w{myname b}
+ describe "for groups it is being removed from" do
+ it "should replace the group's member list with one missing the user's name" do
+ @one[:members] = %w{myname a}
+ @two[:members] = %w{myname b}
- @group_manager.expects(:update).with { |name, is, should| name == "two" and should[:members] == %w{b} }
+ @group_manager.expects(:update).with { |name, is, should| name == "two" and should[:members] == %w{b} }
- @instance.stubs(:groups).returns "one,two"
- @instance.groups = "one"
- end
+ @instance.stubs(:groups).returns "one,two"
+ @instance.groups = "one"
+ end
- it "should mark the member list as empty if there are no remaining members" do
- @one[:members] = %w{myname}
- @two[:members] = %w{myname b}
+ it "should mark the member list as empty if there are no remaining members" do
+ @one[:members] = %w{myname}
+ @two[:members] = %w{myname b}
- @group_manager.expects(:update).with { |name, is, should| name == "one" and should[:members] == :absent }
+ @group_manager.expects(:update).with { |name, is, should| name == "one" and should[:members] == :absent }
- @instance.stubs(:groups).returns "one,two"
- @instance.groups = "two"
- end
- end
+ @instance.stubs(:groups).returns "one,two"
+ @instance.groups = "two"
+ end
+ end
- describe "for groups that already have members" do
- it "should replace each group's member list with a new list including the user's name" do
- @one[:members] = %w{a b}
- @group_manager.expects(:update).with { |name, is, should| should[:members] == %w{a b myname} }
- @two[:members] = %w{b c}
- @group_manager.expects(:update).with { |name, is, should| should[:members] == %w{b c myname} }
+ describe "for groups that already have members" do
+ it "should replace each group's member list with a new list including the user's name" do
+ @one[:members] = %w{a b}
+ @group_manager.expects(:update).with { |name, is, should| should[:members] == %w{a b myname} }
+ @two[:members] = %w{b c}
+ @group_manager.expects(:update).with { |name, is, should| should[:members] == %w{b c myname} }
- @instance.groups = "one,two"
- end
- end
+ @instance.groups = "one,two"
+ end
+ end
- describe "for groups of which it is a member" do
- it "should do nothing" do
- @one[:members] = %w{a b}
- @group_manager.expects(:update).with { |name, is, should| should[:members] == %w{a b myname} }
+ describe "for groups of which it is a member" do
+ it "should do nothing" do
+ @one[:members] = %w{a b}
+ @group_manager.expects(:update).with { |name, is, should| should[:members] == %w{a b myname} }
- @two[:members] = %w{c myname}
- @group_manager.expects(:update).with { |name, *other| name == "two" }.never
+ @two[:members] = %w{c myname}
+ @group_manager.expects(:update).with { |name, *other| name == "two" }.never
- @instance.stubs(:groups).returns "two"
+ @instance.stubs(:groups).returns "two"
- @instance.groups = "one,two"
- end
- end
+ @instance.groups = "one,two"
+ end
end
+ end
end
diff --git a/spec/unit/provider/user/user_role_add_spec.rb b/spec/unit/provider/user/user_role_add_spec.rb
index 4dbfb83be..211f4260a 100644
--- a/spec/unit/provider/user/user_role_add_spec.rb
+++ b/spec/unit/provider/user/user_role_add_spec.rb
@@ -5,245 +5,245 @@ require File.dirname(__FILE__) + '/../../../spec_helper'
provider_class = Puppet::Type.type(:user).provider(:user_role_add)
describe provider_class do
+ before do
+ @resource = stub("resource", :name => "myuser", :managehome? => nil)
+ @resource.stubs(:should).returns "fakeval"
+ @resource.stubs(:[]).returns "fakeval"
+ @resource.stubs(:allowdupe?).returns false
+ @provider = provider_class.new(@resource)
+ end
+
+ describe "when calling command" do
before do
- @resource = stub("resource", :name => "myuser", :managehome? => nil)
- @resource.stubs(:should).returns "fakeval"
- @resource.stubs(:[]).returns "fakeval"
- @resource.stubs(:allowdupe?).returns false
- @provider = provider_class.new(@resource)
- end
-
- describe "when calling command" do
- before do
- klass = stub("provider")
- klass.stubs(:command).with(:foo).returns("userfoo")
- klass.stubs(:command).with(:role_foo).returns("rolefoo")
- @provider.stubs(:class).returns(klass)
- end
-
- it "should use the command if not a role and ensure!=role" do
- @provider.stubs(:is_role?).returns(false)
- @provider.stubs(:exists?).returns(false)
- @resource.stubs(:[]).with(:ensure).returns(:present)
- @provider.command(:foo).should == "userfoo"
- end
-
- it "should use the role command when a role" do
- @provider.stubs(:is_role?).returns(true)
- @provider.command(:foo).should == "rolefoo"
- end
-
- it "should use the role command when !exists and ensure=role" do
- @provider.stubs(:is_role?).returns(false)
- @provider.stubs(:exists?).returns(false)
- @resource.stubs(:[]).with(:ensure).returns(:role)
- @provider.command(:foo).should == "rolefoo"
- end
- end
-
- describe "when calling transition" do
- it "should return the type set to whatever is passed in" do
- @provider.expects(:command).with(:modify).returns("foomod")
- @provider.transition("bar").include?("type=bar")
- end
- end
-
- describe "when calling create" do
- before do
- @provider.stubs(:password=)
- end
-
- it "should use the add command when the user is not a role" do
- @provider.stubs(:is_role?).returns(false)
- @provider.expects(:addcmd).returns("useradd")
- @provider.expects(:run)
- @provider.create
- end
-
- it "should use transition(normal) when the user is a role" do
- @provider.stubs(:is_role?).returns(true)
- @provider.expects(:transition).with("normal")
- @provider.expects(:run)
- @provider.create
- end
- end
-
- describe "when calling destroy" do
- it "should use the delete command if the user exists and is not a role" do
- @provider.stubs(:exists?).returns(true)
- @provider.stubs(:is_role?).returns(false)
- @provider.expects(:deletecmd)
- @provider.expects(:run)
- @provider.destroy
- end
-
- it "should use the delete command if the user is a role" do
- @provider.stubs(:exists?).returns(true)
- @provider.stubs(:is_role?).returns(true)
- @provider.expects(:deletecmd)
- @provider.expects(:run)
- @provider.destroy
- end
- end
-
- describe "when calling create_role" do
- it "should use the transition(role) if the user exists" do
- @provider.stubs(:exists?).returns(true)
- @provider.stubs(:is_role?).returns(false)
- @provider.expects(:transition).with("role")
- @provider.expects(:run)
- @provider.create_role
- end
-
- it "should use the add command when role doesn't exists" do
- @provider.stubs(:exists?).returns(false)
- @provider.expects(:addcmd)
- @provider.expects(:run)
- @provider.create_role
- end
- end
-
- describe "when allow duplicate is enabled" do
- before do
- @resource.expects(:allowdupe?).returns true
- @provider.stubs(:is_role?).returns(false)
- @provider.expects(:execute).with { |args| args.include?("-o") }
- end
-
- it "should add -o when the user is being created" do
- @provider.stubs(:password=)
- @provider.create
- end
-
- it "should add -o when the uid is being modified" do
- @provider.uid = 150
- end
- end
-
- [:roles, :auths, :profiles].each do |val|
- describe "when getting #{val}" do
- it "should get the user_attributes" do
- @provider.expects(:user_attributes)
- @provider.send(val)
- end
-
- it "should get the #{val} attribute" do
- attributes = mock("attributes")
- attributes.expects(:[]).with(val)
- @provider.stubs(:user_attributes).returns(attributes)
- @provider.send(val)
- end
- end
- end
-
- describe "when getting the keys" do
- it "should get the user_attributes" do
- @provider.expects(:user_attributes)
- @provider.keys
- end
-
- it "should call removed_managed_attributes" do
- @provider.stubs(:user_attributes).returns({ :type => "normal", :foo => "something" })
- @provider.expects(:remove_managed_attributes)
- @provider.keys
- end
-
- it "should removed managed attribute (type, auths, roles, etc)" do
- @provider.stubs(:user_attributes).returns({ :type => "normal", :foo => "something" })
- @provider.keys.should == { :foo => "something" }
- end
- end
-
- describe "when adding properties" do
- it "should call build_keys_cmd" do
- @resource.stubs(:should).returns ""
- @resource.expects(:should).with(:keys).returns({ :foo => "bar" })
- @provider.expects(:build_keys_cmd).returns([])
- @provider.add_properties
- end
-
- it "should add the elements of the keys hash to an array" do
- @resource.stubs(:should).returns ""
- @resource.expects(:should).with(:keys).returns({ :foo => "bar"})
- @provider.add_properties.must == ["-K", "foo=bar"]
- end
- end
-
- describe "when calling build_keys_cmd" do
- it "should build cmd array with keypairs seperated by -K ending with user" do
- @provider.build_keys_cmd({"foo" => "bar", "baz" => "boo"}).should.eql? ["-K", "foo=bar", "-K", "baz=boo"]
- end
- end
-
- describe "when setting the keys" do
- before do
- @provider.stubs(:is_role?).returns(false)
- end
-
- it "should run a command" do
- @provider.expects(:run)
- @provider.keys=({})
- end
-
- it "should build the command" do
- @resource.stubs(:[]).with(:name).returns("someuser")
- @provider.stubs(:command).returns("usermod")
- @provider.expects(:build_keys_cmd).returns(["-K", "foo=bar"])
- @provider.expects(:run).with(["usermod", "-K", "foo=bar", "someuser"], "modify attribute key pairs")
- @provider.keys=({})
- end
- end
-
- describe "when getting the hashed password" do
- before do
- @array = mock "array"
- end
-
- it "should readlines of /etc/shadow" do
- File.expects(:readlines).with("/etc/shadow").returns([])
- @provider.password
- end
-
- it "should reject anything that doesn't start with alpha numerics" do
- @array.expects(:reject).returns([])
- File.stubs(:readlines).with("/etc/shadow").returns(@array)
- @provider.password
- end
-
- it "should collect splitting on ':'" do
- @array.stubs(:reject).returns(@array)
- @array.expects(:collect).returns([])
- File.stubs(:readlines).with("/etc/shadow").returns(@array)
- @provider.password
- end
-
- it "should find the matching user" do
- @resource.stubs(:[]).with(:name).returns("username")
- @array.stubs(:reject).returns(@array)
- @array.stubs(:collect).returns([["username", "hashedpassword"], ["someoneelse", "theirpassword"]])
- File.stubs(:readlines).with("/etc/shadow").returns(@array)
- @provider.password.must == "hashedpassword"
- end
-
- it "should get the right password" do
- @resource.stubs(:[]).with(:name).returns("username")
- File.stubs(:readlines).with("/etc/shadow").returns(["#comment", " nonsense", " ", "username:hashedpassword:stuff:foo:bar:::", "other:pword:yay:::"])
- @provider.password.must == "hashedpassword"
- end
- end
-
- describe "when setting the password" do
- #how can you mock these blocks up?
- it "should open /etc/shadow for reading and /etc/shadow_tmp for writing" do
- File.expects(:open).with("/etc/shadow", "r")
- File.stubs(:rename)
- @provider.password=("hashedpassword")
- end
-
- it "should rename the /etc/shadow_tmp to /etc/shadow" do
- File.stubs(:open).with("/etc/shadow", "r")
- File.expects(:rename).with("/etc/shadow_tmp", "/etc/shadow")
- @provider.password=("hashedpassword")
- end
+ klass = stub("provider")
+ klass.stubs(:command).with(:foo).returns("userfoo")
+ klass.stubs(:command).with(:role_foo).returns("rolefoo")
+ @provider.stubs(:class).returns(klass)
end
+
+ it "should use the command if not a role and ensure!=role" do
+ @provider.stubs(:is_role?).returns(false)
+ @provider.stubs(:exists?).returns(false)
+ @resource.stubs(:[]).with(:ensure).returns(:present)
+ @provider.command(:foo).should == "userfoo"
+ end
+
+ it "should use the role command when a role" do
+ @provider.stubs(:is_role?).returns(true)
+ @provider.command(:foo).should == "rolefoo"
+ end
+
+ it "should use the role command when !exists and ensure=role" do
+ @provider.stubs(:is_role?).returns(false)
+ @provider.stubs(:exists?).returns(false)
+ @resource.stubs(:[]).with(:ensure).returns(:role)
+ @provider.command(:foo).should == "rolefoo"
+ end
+ end
+
+ describe "when calling transition" do
+ it "should return the type set to whatever is passed in" do
+ @provider.expects(:command).with(:modify).returns("foomod")
+ @provider.transition("bar").include?("type=bar")
+ end
+ end
+
+ describe "when calling create" do
+ before do
+ @provider.stubs(:password=)
+ end
+
+ it "should use the add command when the user is not a role" do
+ @provider.stubs(:is_role?).returns(false)
+ @provider.expects(:addcmd).returns("useradd")
+ @provider.expects(:run)
+ @provider.create
+ end
+
+ it "should use transition(normal) when the user is a role" do
+ @provider.stubs(:is_role?).returns(true)
+ @provider.expects(:transition).with("normal")
+ @provider.expects(:run)
+ @provider.create
+ end
+ end
+
+ describe "when calling destroy" do
+ it "should use the delete command if the user exists and is not a role" do
+ @provider.stubs(:exists?).returns(true)
+ @provider.stubs(:is_role?).returns(false)
+ @provider.expects(:deletecmd)
+ @provider.expects(:run)
+ @provider.destroy
+ end
+
+ it "should use the delete command if the user is a role" do
+ @provider.stubs(:exists?).returns(true)
+ @provider.stubs(:is_role?).returns(true)
+ @provider.expects(:deletecmd)
+ @provider.expects(:run)
+ @provider.destroy
+ end
+ end
+
+ describe "when calling create_role" do
+ it "should use the transition(role) if the user exists" do
+ @provider.stubs(:exists?).returns(true)
+ @provider.stubs(:is_role?).returns(false)
+ @provider.expects(:transition).with("role")
+ @provider.expects(:run)
+ @provider.create_role
+ end
+
+ it "should use the add command when role doesn't exists" do
+ @provider.stubs(:exists?).returns(false)
+ @provider.expects(:addcmd)
+ @provider.expects(:run)
+ @provider.create_role
+ end
+ end
+
+ describe "when allow duplicate is enabled" do
+ before do
+ @resource.expects(:allowdupe?).returns true
+ @provider.stubs(:is_role?).returns(false)
+ @provider.expects(:execute).with { |args| args.include?("-o") }
+ end
+
+ it "should add -o when the user is being created" do
+ @provider.stubs(:password=)
+ @provider.create
+ end
+
+ it "should add -o when the uid is being modified" do
+ @provider.uid = 150
+ end
+ end
+
+ [:roles, :auths, :profiles].each do |val|
+ describe "when getting #{val}" do
+ it "should get the user_attributes" do
+ @provider.expects(:user_attributes)
+ @provider.send(val)
+ end
+
+ it "should get the #{val} attribute" do
+ attributes = mock("attributes")
+ attributes.expects(:[]).with(val)
+ @provider.stubs(:user_attributes).returns(attributes)
+ @provider.send(val)
+ end
+ end
+ end
+
+ describe "when getting the keys" do
+ it "should get the user_attributes" do
+ @provider.expects(:user_attributes)
+ @provider.keys
+ end
+
+ it "should call removed_managed_attributes" do
+ @provider.stubs(:user_attributes).returns({ :type => "normal", :foo => "something" })
+ @provider.expects(:remove_managed_attributes)
+ @provider.keys
+ end
+
+ it "should removed managed attribute (type, auths, roles, etc)" do
+ @provider.stubs(:user_attributes).returns({ :type => "normal", :foo => "something" })
+ @provider.keys.should == { :foo => "something" }
+ end
+ end
+
+ describe "when adding properties" do
+ it "should call build_keys_cmd" do
+ @resource.stubs(:should).returns ""
+ @resource.expects(:should).with(:keys).returns({ :foo => "bar" })
+ @provider.expects(:build_keys_cmd).returns([])
+ @provider.add_properties
+ end
+
+ it "should add the elements of the keys hash to an array" do
+ @resource.stubs(:should).returns ""
+ @resource.expects(:should).with(:keys).returns({ :foo => "bar"})
+ @provider.add_properties.must == ["-K", "foo=bar"]
+ end
+ end
+
+ describe "when calling build_keys_cmd" do
+ it "should build cmd array with keypairs seperated by -K ending with user" do
+ @provider.build_keys_cmd({"foo" => "bar", "baz" => "boo"}).should.eql? ["-K", "foo=bar", "-K", "baz=boo"]
+ end
+ end
+
+ describe "when setting the keys" do
+ before do
+ @provider.stubs(:is_role?).returns(false)
+ end
+
+ it "should run a command" do
+ @provider.expects(:run)
+ @provider.keys=({})
+ end
+
+ it "should build the command" do
+ @resource.stubs(:[]).with(:name).returns("someuser")
+ @provider.stubs(:command).returns("usermod")
+ @provider.expects(:build_keys_cmd).returns(["-K", "foo=bar"])
+ @provider.expects(:run).with(["usermod", "-K", "foo=bar", "someuser"], "modify attribute key pairs")
+ @provider.keys=({})
+ end
+ end
+
+ describe "when getting the hashed password" do
+ before do
+ @array = mock "array"
+ end
+
+ it "should readlines of /etc/shadow" do
+ File.expects(:readlines).with("/etc/shadow").returns([])
+ @provider.password
+ end
+
+ it "should reject anything that doesn't start with alpha numerics" do
+ @array.expects(:reject).returns([])
+ File.stubs(:readlines).with("/etc/shadow").returns(@array)
+ @provider.password
+ end
+
+ it "should collect splitting on ':'" do
+ @array.stubs(:reject).returns(@array)
+ @array.expects(:collect).returns([])
+ File.stubs(:readlines).with("/etc/shadow").returns(@array)
+ @provider.password
+ end
+
+ it "should find the matching user" do
+ @resource.stubs(:[]).with(:name).returns("username")
+ @array.stubs(:reject).returns(@array)
+ @array.stubs(:collect).returns([["username", "hashedpassword"], ["someoneelse", "theirpassword"]])
+ File.stubs(:readlines).with("/etc/shadow").returns(@array)
+ @provider.password.must == "hashedpassword"
+ end
+
+ it "should get the right password" do
+ @resource.stubs(:[]).with(:name).returns("username")
+ File.stubs(:readlines).with("/etc/shadow").returns(["#comment", " nonsense", " ", "username:hashedpassword:stuff:foo:bar:::", "other:pword:yay:::"])
+ @provider.password.must == "hashedpassword"
+ end
+ end
+
+ describe "when setting the password" do
+ #how can you mock these blocks up?
+ it "should open /etc/shadow for reading and /etc/shadow_tmp for writing" do
+ File.expects(:open).with("/etc/shadow", "r")
+ File.stubs(:rename)
+ @provider.password=("hashedpassword")
+ end
+
+ it "should rename the /etc/shadow_tmp to /etc/shadow" do
+ File.stubs(:open).with("/etc/shadow", "r")
+ File.expects(:rename).with("/etc/shadow_tmp", "/etc/shadow")
+ @provider.password=("hashedpassword")
+ end
+ end
end
diff --git a/spec/unit/provider/user/useradd_spec.rb b/spec/unit/provider/user/useradd_spec.rb
index 463212e4e..6eb9717b8 100755
--- a/spec/unit/provider/user/useradd_spec.rb
+++ b/spec/unit/provider/user/useradd_spec.rb
@@ -5,111 +5,111 @@ require File.dirname(__FILE__) + '/../../../spec_helper'
provider_class = Puppet::Type.type(:user).provider(:useradd)
describe provider_class do
- before do
- @resource = stub("resource", :name => "myuser", :managehome? => nil)
- @resource.stubs(:should).returns "fakeval"
- @resource.stubs(:[]).returns "fakeval"
- @provider = provider_class.new(@resource)
+ before do
+ @resource = stub("resource", :name => "myuser", :managehome? => nil)
+ @resource.stubs(:should).returns "fakeval"
+ @resource.stubs(:[]).returns "fakeval"
+ @provider = provider_class.new(@resource)
+ end
+
+ # #1360
+ it "should add -o when allowdupe is enabled and the user is being created" do
+ @resource.expects(:allowdupe?).returns true
+ @provider.expects(:execute).with { |args| args.include?("-o") }
+ @provider.create
+ end
+
+ it "should add -o when allowdupe is enabled and the uid is being modified" do
+ @resource.expects(:allowdupe?).returns true
+ @provider.expects(:execute).with { |args| args.include?("-o") }
+
+ @provider.uid = 150
+ end
+
+ describe "when checking to add allow dup" do
+ it "should check allow dup" do
+ @resource.expects(:allowdupe?)
+ @provider.check_allow_dup
+ end
+
+ it "should return an array with a flag if dup is allowed" do
+ @resource.stubs(:allowdupe?).returns true
+ @provider.check_allow_dup.must == ["-o"]
+ end
+
+ it "should return an empty array if no dup is allowed" do
+ @resource.stubs(:allowdupe?).returns false
+ @provider.check_allow_dup.must == []
+ end
+ end
+
+ describe "when checking manage home" do
+ it "should check manage home" do
+ @resource.expects(:managehome?)
+ @provider.check_manage_home
+ end
+
+ it "should return an array with -m flag if home is managed" do
+ @resource.stubs(:managehome?).returns true
+ @provider.check_manage_home.must == ["-m"]
+ end
+
+ it "should return an array with -M if home is not managed and on Redhat" do
+ Facter.stubs(:value).with("operatingsystem").returns("RedHat")
+ @resource.stubs(:managehome?).returns false
+ @provider.check_manage_home.must == ["-M"]
+ end
+
+ it "should return an empty array if home is not managed and not on Redhat" do
+ Facter.stubs(:value).with("operatingsystem").returns("some OS")
+ @resource.stubs(:managehome?).returns false
+ @provider.check_manage_home.must == []
end
+ end
+
+ describe "when adding properties" do
+ it "should get the valid properties"
+ it "should not add the ensure property"
+ it "should add the flag and value to an array"
+ it "should return and array of flags and values"
+ end
- # #1360
- it "should add -o when allowdupe is enabled and the user is being created" do
- @resource.expects(:allowdupe?).returns true
- @provider.expects(:execute).with { |args| args.include?("-o") }
- @provider.create
+ describe "when calling addcmd" do
+ before do
+ @resource.stubs(:allowdupe?).returns true
+ @resource.stubs(:managehome?).returns true
end
- it "should add -o when allowdupe is enabled and the uid is being modified" do
- @resource.expects(:allowdupe?).returns true
- @provider.expects(:execute).with { |args| args.include?("-o") }
+ it "should call command with :add" do
+ @provider.expects(:command).with(:add)
+ @provider.addcmd
+ end
- @provider.uid = 150
+ it "should add properties" do
+ @provider.expects(:add_properties).returns([])
+ @provider.addcmd
end
- describe "when checking to add allow dup" do
- it "should check allow dup" do
- @resource.expects(:allowdupe?)
- @provider.check_allow_dup
- end
-
- it "should return an array with a flag if dup is allowed" do
- @resource.stubs(:allowdupe?).returns true
- @provider.check_allow_dup.must == ["-o"]
- end
-
- it "should return an empty array if no dup is allowed" do
- @resource.stubs(:allowdupe?).returns false
- @provider.check_allow_dup.must == []
- end
+ it "should check and add if dup allowed" do
+ @provider.expects(:check_allow_dup).returns([])
+ @provider.addcmd
end
- describe "when checking manage home" do
- it "should check manage home" do
- @resource.expects(:managehome?)
- @provider.check_manage_home
- end
-
- it "should return an array with -m flag if home is managed" do
- @resource.stubs(:managehome?).returns true
- @provider.check_manage_home.must == ["-m"]
- end
-
- it "should return an array with -M if home is not managed and on Redhat" do
- Facter.stubs(:value).with("operatingsystem").returns("RedHat")
- @resource.stubs(:managehome?).returns false
- @provider.check_manage_home.must == ["-M"]
- end
-
- it "should return an empty array if home is not managed and not on Redhat" do
- Facter.stubs(:value).with("operatingsystem").returns("some OS")
- @resource.stubs(:managehome?).returns false
- @provider.check_manage_home.must == []
- end
+ it "should check and add if home is managed" do
+ @provider.expects(:check_manage_home).returns([])
+ @provider.addcmd
end
- describe "when adding properties" do
- it "should get the valid properties"
- it "should not add the ensure property"
- it "should add the flag and value to an array"
- it "should return and array of flags and values"
+ it "should add the resource :name" do
+ @resource.expects(:[]).with(:name)
+ @provider.addcmd
end
- describe "when calling addcmd" do
- before do
- @resource.stubs(:allowdupe?).returns true
- @resource.stubs(:managehome?).returns true
- end
-
- it "should call command with :add" do
- @provider.expects(:command).with(:add)
- @provider.addcmd
- end
-
- it "should add properties" do
- @provider.expects(:add_properties).returns([])
- @provider.addcmd
- end
-
- it "should check and add if dup allowed" do
- @provider.expects(:check_allow_dup).returns([])
- @provider.addcmd
- end
-
- it "should check and add if home is managed" do
- @provider.expects(:check_manage_home).returns([])
- @provider.addcmd
- end
-
- it "should add the resource :name" do
- @resource.expects(:[]).with(:name)
- @provider.addcmd
- end
-
- it "should return an array with full command" do
- @provider.stubs(:command).with(:add).returns("useradd")
- @provider.stubs(:add_properties).returns(["-G", "somegroup"])
- @resource.stubs(:[]).with(:name).returns("someuser")
- @provider.addcmd.must == ["useradd", "-G", "somegroup", "-o", "-m", "someuser"]
- end
+ it "should return an array with full command" do
+ @provider.stubs(:command).with(:add).returns("useradd")
+ @provider.stubs(:add_properties).returns(["-G", "somegroup"])
+ @resource.stubs(:[]).with(:name).returns("someuser")
+ @provider.addcmd.must == ["useradd", "-G", "somegroup", "-o", "-m", "someuser"]
end
+ end
end