If the target is not specified it is automatically set to the user's home directory. If the user does not exist when the generation of the target path occurs then an ArgumentError exception is raised but not caught. This patch catches the ArgumentError and raises a Puppet::Error instead to more gracefully notify the user and allow any remaining resources to be applied.
Signed-off-by: Sean Millichamp <[email protected]> --- lib/puppet/provider/ssh_authorized_key/parsed.rb | 6 +++++- spec/unit/provider/ssh_authorized_key/parsed.rb | 12 ++++++++++++ 2 files changed, 17 insertions(+), 1 deletions(-) diff --git a/lib/puppet/provider/ssh_authorized_key/parsed.rb b/lib/puppet/provider/ssh_authorized_key/parsed.rb index fb4d095..b222e51 100644 --- a/lib/puppet/provider/ssh_authorized_key/parsed.rb +++ b/lib/puppet/provider/ssh_authorized_key/parsed.rb @@ -54,7 +54,11 @@ Puppet::Type.type(:ssh_authorized_key).provide(:parsed, end def target - @resource.should(:target) || File.expand_path("~%s/.ssh/authorized_keys" % user) + begin + @resource.should(:target) || File.expand_path("~%s/.ssh/authorized_keys" % user) + rescue + raise Puppet::Error, "Target not defined and/or specified user does not exist yet" + end end def user diff --git a/spec/unit/provider/ssh_authorized_key/parsed.rb b/spec/unit/provider/ssh_authorized_key/parsed.rb index fc3f550..1fefd40 100755 --- a/spec/unit/provider/ssh_authorized_key/parsed.rb +++ b/spec/unit/provider/ssh_authorized_key/parsed.rb @@ -202,5 +202,17 @@ describe provider_class do proc { @provider.flush }.should raise_error end end + + describe "and a invalid user has been specified with no target" do + before :each do + @resource.stubs(:should).with(:user).returns "thisusershouldnotexist" + @resource.stubs(:should).with(:target).returns nil + end + + it "should catch an exception and raise a Puppet error" do + lambda { @provider.flush }.should raise_error(Puppet::Error) + end + end + end end -- 1.6.6.1 -- 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.
