From a090e868d55ea9b10f8193dcb2d1f23838a6def1 Mon Sep 17 00:00:00 2001 From: Markus Roberts Date: Mon, 11 Oct 2010 19:41:31 -0700 Subject: Fix for #4963 -- Use correct commands for password expiry on solaris This fixes the command / option issues of #4963 as suggested on the ticket; the setting-expiry when not needed aspects are deferred to #4975. --- spec/unit/provider/user/user_role_add_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'spec') 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 -- cgit From e232770baefc35abb71de6e2f28d053158e6dd45 Mon Sep 17 00:00:00 2001 From: Markus Roberts Date: Mon, 11 Oct 2010 21:07:29 -0700 Subject: Minimal fix for #4975 -- only call chage when managing password age rules This is intended to be a minimal fix, with tests, to prevent chage from running unless needed. --- spec/unit/provider/user/useradd_spec.rb | 42 +++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) (limited to 'spec') 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 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 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 -m 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 -- cgit From 3c56705a95c945778674f9792a07b66b879cb48e Mon Sep 17 00:00:00 2001 From: Markus Roberts Date: Tue, 12 Oct 2010 16:38:59 -0700 Subject: Fix for #4832 -- Making PSON handle arbitrary binary data The PSON library needlessly assumed that the data to be transmitted was well- formed unicode. This made Latin-1 users (and anyone who needed to serialize arbitrary binary data) sad. This patch goes some of the way to resolving the issues, by passing through non-unicode data rather than just failing, adds tests, and cleans up a pernicious assumption about escape characters in ruby regular expressions not marked "n" (no-encoding). --- spec/unit/util/json_spec.rb | 21 --------------------- spec/unit/util/pson_spec.rb | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 21 deletions(-) delete mode 100755 spec/unit/util/json_spec.rb create mode 100755 spec/unit/util/pson_spec.rb (limited to 'spec') diff --git a/spec/unit/util/json_spec.rb b/spec/unit/util/json_spec.rb deleted file mode 100755 index 4f6cea997..000000000 --- a/spec/unit/util/json_spec.rb +++ /dev/null @@ -1,21 +0,0 @@ -#!/usr/bin/env ruby - -Dir.chdir(File.dirname(__FILE__)) { (s = lambda { |f| File.exist?(f) ? require(f) : Dir.chdir("..") { s.call(f) } }).call("spec/spec_helper.rb") } - -require 'puppet/util/pson' - -class PsonUtil - include Puppet::Util::Pson -end - -describe Puppet::Util::Pson do - it "should fail if no data is provided" do - lambda { PsonUtil.new.pson_create("type" => "foo") }.should raise_error(ArgumentError) - end - - it "should call 'from_pson' with the provided data" do - pson = PsonUtil.new - pson.expects(:from_pson).with("mydata") - pson.pson_create("type" => "foo", "data" => "mydata") - end -end diff --git a/spec/unit/util/pson_spec.rb b/spec/unit/util/pson_spec.rb new file mode 100755 index 000000000..d02d28517 --- /dev/null +++ b/spec/unit/util/pson_spec.rb @@ -0,0 +1,38 @@ +#!/usr/bin/env ruby + +Dir.chdir(File.dirname(__FILE__)) { (s = lambda { |f| File.exist?(f) ? require(f) : Dir.chdir("..") { s.call(f) } }).call("spec/spec_helper.rb") } + +require 'puppet/util/pson' + +class PsonUtil + include Puppet::Util::Pson +end + +describe Puppet::Util::Pson do + it "should fail if no data is provided" do + lambda { PsonUtil.new.pson_create("type" => "foo") }.should raise_error(ArgumentError) + end + + it "should call 'from_pson' with the provided data" do + pson = PsonUtil.new + 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 -- cgit