diff options
author | Francois Deppierraz <francois@ctrlaltdel.ch> | 2009-04-30 02:33:50 +0200 |
---|---|---|
committer | James Turnbull <james@lovedthanlost.net> | 2009-05-06 20:23:15 +1000 |
commit | 5cc491060f35a29faff20911f54c57e9e065b6a3 (patch) | |
tree | d8ad2c418154a272f09ca71142c4afb15c733a34 | |
parent | a6af5bf8aa45af05186088b02e68acff41f404a6 (diff) | |
download | puppet-5cc491060f35a29faff20911f54c57e9e065b6a3.tar.gz puppet-5cc491060f35a29faff20911f54c57e9e065b6a3.tar.xz puppet-5cc491060f35a29faff20911f54c57e9e065b6a3.zip |
Fix #1409 once again, including test
"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.
-rw-r--r-- | lib/puppet/type/ssh_authorized_key.rb | 20 | ||||
-rwxr-xr-x | 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 997afb81e..33ed1d62b 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 db389864e..f1e9963e9 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 |