[Pkg-puppet-devel] [SCM] Puppet packaging for Debian branch, master, updated. debian/0.24.7-1-98-gf19c0e5

James Turnbull james at lovedthanlost.net
Wed Apr 8 21:48:25 UTC 2009


The following commit has been merged in the master branch:
commit 9eb377aab786296d2b9c5c4807026bf8e5f89f55
Author: Francois Deppierraz <francois at slayer.ctrlaltdel.ch>
Date:   Sat Mar 21 23:32:02 2009 +0100

    Fixed #2004 - ssh_authorized_key fails if no target is defined
    
    This commit depends on 7f291afdacf59f762c3b78481f5420ec8919e46d
    (fixing #1629) which was cherry-picked from master.
    
    Signed-off-by: Francois Deppierraz <francois at ctrlaltdel.ch>

diff --git a/lib/puppet/provider/ssh_authorized_key/parsed.rb b/lib/puppet/provider/ssh_authorized_key/parsed.rb
index 5604ba3..051fb63 100644
--- a/lib/puppet/provider/ssh_authorized_key/parsed.rb
+++ b/lib/puppet/provider/ssh_authorized_key/parsed.rb
@@ -36,21 +36,8 @@ Puppet::Type.type(:ssh_authorized_key).provide(:parsed,
         :rts      => /^\s+/,
         :match    => /^(?:(.+) )?(\d+) (\d+) (\d+)(?: (.+))?$/
 
-    def prefetch
-        # This was done in the type class but path expansion was failing for
-        # not yet existing users, the only workaround I found was to move that
-        # in the provider.
-        @resource[:target] = target
-
-        super
-    end
-
     def target
-        if user
-            File.expand_path("~%s/.ssh/authorized_keys" % user)
-        elsif target = @resource.should(:target)
-            target
-        end
+        @resource.should(:target)
     end
 
     def user
diff --git a/lib/puppet/type/ssh_authorized_key.rb b/lib/puppet/type/ssh_authorized_key.rb
index 66cf3e7..997afb8 100644
--- a/lib/puppet/type/ssh_authorized_key.rb
+++ b/lib/puppet/type/ssh_authorized_key.rb
@@ -31,6 +31,20 @@ module Puppet
 
         newproperty(:target) do
             desc "The file in which to store the SSH key."
+
+            defaultto :absent
+
+            def should
+                if defined? @should and @should[0] != :absent
+                    return super
+                end
+
+                if user = resource[:user]
+                    return File.expand_path("~%s/.ssh/authorized_keys" % user)
+                end
+
+                return nil
+            end
         end
 
         newproperty(:options, :array_matching => :all) do
diff --git a/spec/unit/provider/ssh_authorized_key/parsed.rb b/spec/unit/provider/ssh_authorized_key/parsed.rb
index 73d6235..1e5d6be 100755
--- a/spec/unit/provider/ssh_authorized_key/parsed.rb
+++ b/spec/unit/provider/ssh_authorized_key/parsed.rb
@@ -72,27 +72,6 @@ describe provider_class do
         genkey(key).should == "from=\"192.168.1.1\",no-pty,no-X11-forwarding ssh-rsa AAAAfsfddsjldjgksdflgkjsfdlgkj root at localhost\n"
     end
 
-    it "should prefetch ~user/.ssh/authorized_keys when user is given" do
-        key = Puppet::Type.type(:ssh_authorized_key).create(
-            :name => "Test",
-            :key => "AA",
-            :type => "rsa",
-            :ensure => :present,
-            :user => "root")
-        prov = @provider.new key
-
-        prov.prefetch
-        prov.target.should == File.expand_path("~root/.ssh/authorized_keys")
-    end
-
-    it "should create destination dir" do
-        # No idea how to test the flush method
-    end
-
-    it "should set correct default permissions" do
-        # No idea how to test the flush method
-    end
-
     it "'s parse_options method should be able to parse options containing commas" do
         options = %w{from="host1.reductlivelabs.com,host.reductivelabs.com" command="/usr/local/bin/run" ssh-pty}
         optionstr = options.join(", ")
@@ -119,7 +98,8 @@ describe provider_class do
         describe "and a user has been specified" do
             before :each do
                 @resource.stubs(:should).with(:user).returns "nobody"
-                @resource.stubs(:should).with(:target).returns nil
+                target = File.expand_path("~nobody/.ssh/authorized_keys")
+                @resource.stubs(:should).with(:target).returns target
            end
 
             it "should create the directory" do
diff --git a/spec/unit/type/ssh_authorized_key.rb b/spec/unit/type/ssh_authorized_key.rb
index 2cd5171..6d60ac2 100755
--- a/spec/unit/type/ssh_authorized_key.rb
+++ b/spec/unit/type/ssh_authorized_key.rb
@@ -89,14 +89,37 @@ describe ssh_authorized_key do
         @class.attrtype(:target).should == :property
     end
 
-    it "should raise an error when neither user nor target is given" do
-        proc do
-            @class.create(
-              :name   => "Test",
-              :key    => "AAA",
-              :type   => "ssh-rsa",
-              :ensure => :present)
-        end.should raise_error(Puppet::Error)
+    describe "when neither user nor target is specified" do
+        it "should raise an error" do
+            proc do
+                @class.create(
+                  :name   => "Test",
+                  :key    => "AAA",
+                  :type   => "ssh-rsa",
+                  :ensure => :present)
+            end.should raise_error(Puppet::Error)
+        end
+    end
+
+    describe "when both target and user are specified" do
+        it "should use target" do
+            resource = @class.create(
+                :name => "Test",
+                :user => "root",
+                :target => "/tmp/blah")
+            resource.should(:target).should == "/tmp/blah"
+        end
+    end
+
+
+    describe "when user is specified" do
+        it "should determine target" do
+            resource = @class.create(
+                :name   => "Test",
+                :user   => "root")
+            target = File.expand_path("~root/.ssh/authorized_keys")
+            resource.should(:target).should == target
+        end
     end
 
     after do

-- 
Puppet packaging for Debian



More information about the Pkg-puppet-devel mailing list