"user doesn't exit" error appeared once again after the changes which were applied in order to fix #2004.
Validation must only check attributes presence, not their value. Signed-off-by: Francois Deppierraz <[email protected]> --- lib/puppet/type/ssh_authorized_key.rb | 20 ++++++++++++++------ spec/unit/type/ssh_authorized_key.rb | 9 +++++++++ 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/lib/puppet/type/ssh_authorized_key.rb b/lib/puppet/type/ssh_authorized_key.rb index 997afb8..33ed1d6 100644 --- a/lib/puppet/type/ssh_authorized_key.rb +++ b/lib/puppet/type/ssh_authorized_key.rb @@ -39,11 +39,14 @@ module Puppet return super end - if user = resource[:user] + return nil unless user = resource[:user] + + begin return File.expand_path("~%s/.ssh/authorized_keys" % user) + rescue + Puppet.debug "The required user is not yet present on the system" + return nil end - - return nil end end @@ -77,9 +80,14 @@ module Puppet end validate do - unless should(:target) or should(:user) - raise Puppet::Error, "Attribute 'user' or 'target' is mandatory" - end + # Go ahead if target attribute is defined + return if @parameters[:target].shouldorig[0] != :absent + + # Go ahead if user attribute is defined + return if @parameters.include?(:user) + + # If neither target nor user is defined, this is an error + raise Puppet::Error, "Attribute 'user' or 'target' is mandatory" end end end diff --git a/spec/unit/type/ssh_authorized_key.rb b/spec/unit/type/ssh_authorized_key.rb index db38986..f1e9963 100755 --- a/spec/unit/type/ssh_authorized_key.rb +++ b/spec/unit/type/ssh_authorized_key.rb @@ -121,4 +121,13 @@ describe ssh_authorized_key do resource.should(:target).should == target end end + + describe "when calling validate" do + it "should not crash on a non-existant user" do + resource = @class.create( + :name => "Test", + :user => "ihopesuchuserdoesnotexist") + proc { resource.validate }.should_not raise_error + end + end end -- 1.6.0.4 --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Puppet Developers" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/puppet-dev?hl=en -~----------~----~----~----~------~----~------~--~---
