diff options
-rw-r--r-- | lib/puppet/provider/ssh_authorized_key/parsed.rb | 6 | ||||
-rwxr-xr-x | 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 fb4d0956e..b222e5133 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 0edf2b0ae..f8613e35e 100755 --- a/spec/unit/provider/ssh_authorized_key/parsed.rb +++ b/spec/unit/provider/ssh_authorized_key/parsed.rb @@ -204,5 +204,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 |