summaryrefslogtreecommitdiffstats
path: root/spec
diff options
context:
space:
mode:
Diffstat (limited to 'spec')
-rw-r--r--spec/unit/provider/user/user_role_add_spec.rb2
-rwxr-xr-xspec/unit/provider/user/useradd_spec.rb42
-rwxr-xr-xspec/unit/util/pson_spec.rb (renamed from spec/unit/util/json_spec.rb)17
3 files changed, 60 insertions, 1 deletions
diff --git a/spec/unit/provider/user/user_role_add_spec.rb b/spec/unit/provider/user/user_role_add_spec.rb
index b3244f19d..9cf649267 100644
--- a/spec/unit/provider/user/user_role_add_spec.rb
+++ b/spec/unit/provider/user/user_role_add_spec.rb
@@ -72,7 +72,7 @@ describe provider_class do
@provider = provider_class.new(@resource)
@provider.stubs(:user_attributes)
@provider.stubs(:execute)
- @provider.expects(:execute).with { |cmd, *args| args == ["-m", 5, "-M", 10, "myuser"] }
+ @provider.expects(:execute).with { |cmd, *args| args == ["-n", 5, "-x", 10, "myuser"] }
@provider.create
end
end
diff --git a/spec/unit/provider/user/useradd_spec.rb b/spec/unit/provider/user/useradd_spec.rb
index 26367c584..9ebba596c 100755
--- a/spec/unit/provider/user/useradd_spec.rb
+++ b/spec/unit/provider/user/useradd_spec.rb
@@ -131,4 +131,46 @@ describe provider_class do
@provider.addcmd.must == ["useradd", "-G", "somegroup", "-o", "-m", "someuser"]
end
end
+
+ describe "when calling passcmd" do
+ before do
+ @resource.stubs(:allowdupe?).returns true
+ @resource.stubs(:managehome?).returns true
+ end
+
+ it "should call command with :pass" do
+ @provider.expects(:command).with(:password)
+ @provider.passcmd
+ end
+
+ it "should return nil if neither min nor max is set" do
+ @resource.stubs(:should).with(:password_min_age).returns nil
+ @resource.stubs(:should).with(:password_max_age).returns nil
+ @provider.passcmd.must == nil
+ end
+
+ it "should return a chage command array with -m <value> and the user name if password_min_age is set" do
+ @provider.stubs(:command).with(:password).returns("chage")
+ @resource.stubs(:[]).with(:name).returns("someuser")
+ @resource.stubs(:should).with(:password_min_age).returns 123
+ @resource.stubs(:should).with(:password_max_age).returns nil
+ @provider.passcmd.must == ['chage','-m',123,'someuser']
+ end
+
+ it "should return a chage command array with -M <value> if password_max_age is set" do
+ @provider.stubs(:command).with(:password).returns("chage")
+ @resource.stubs(:[]).with(:name).returns("someuser")
+ @resource.stubs(:should).with(:password_min_age).returns nil
+ @resource.stubs(:should).with(:password_max_age).returns 999
+ @provider.passcmd.must == ['chage','-M',999,'someuser']
+ end
+
+ it "should return a chage command array with -M <value> -m <value> if both password_min_age and password_max_age are set" do
+ @provider.stubs(:command).with(:password).returns("chage")
+ @resource.stubs(:[]).with(:name).returns("someuser")
+ @resource.stubs(:should).with(:password_min_age).returns 123
+ @resource.stubs(:should).with(:password_max_age).returns 999
+ @provider.passcmd.must == ['chage','-m',123,'-M',999,'someuser']
+ end
+ end
end
diff --git a/spec/unit/util/json_spec.rb b/spec/unit/util/pson_spec.rb
index 4f6cea997..d02d28517 100755
--- a/spec/unit/util/json_spec.rb
+++ b/spec/unit/util/pson_spec.rb
@@ -18,4 +18,21 @@ describe Puppet::Util::Pson do
pson.expects(:from_pson).with("mydata")
pson.pson_create("type" => "foo", "data" => "mydata")
end
+
+
+ {
+ 'foo' => '"foo"',
+ 1 => '1',
+ "\x80" => "\"\x80\"",
+ [] => '[]'
+ }.each { |str,pson|
+ it "should be able to encode #{str.inspect}" do
+ str.to_pson.should == pson
+ end
+ }
+
+ it "should be able to handle arbitrary binary data" do
+ bin_string = (1..20000).collect { |i| ((17*i+13*i*i) % 255).chr }.join
+ PSON.parse(%Q{{ "type": "foo", "data": #{bin_string.to_pson} }})["data"].should == bin_string
+ end
end