[Pkg-puppet-devel] [SCM] Puppet packaging for Debian branch, experimental, updated. debian/2.6.8-1-844-g7ec39d5

Paul Berry paul at puppetlabs.com
Tue May 10 08:02:51 UTC 2011


The following commit has been merged in the experimental branch:
commit beb85d65e4cced7691163add392f53ec58cb1a3d
Author: Paul Berry <paul at puppetlabs.com>
Date:   Mon Nov 29 16:32:41 2010 -0800

    Maint: Moved auto-signing logic into an indirector extension
    
    Autosigning was previously accomplished by overriding
    CertificateRequest#save.  This meant that it wouldn't work if
    certificate requests were saved via a direct call to Indirection#save.
    Changed it to use the indirector :extend mechanism, which works no
    matter how the save is invoked.

diff --git a/lib/puppet/ssl/certificate_request.rb b/lib/puppet/ssl/certificate_request.rb
index 2f6cae3..8c83339 100644
--- a/lib/puppet/ssl/certificate_request.rb
+++ b/lib/puppet/ssl/certificate_request.rb
@@ -5,7 +5,20 @@ class Puppet::SSL::CertificateRequest < Puppet::SSL::Base
   wraps OpenSSL::X509::Request
 
   extend Puppet::Indirector
-  indirects :certificate_request, :terminus_class => :file
+
+  # If auto-signing is on, sign any certificate requests as they are saved.
+  module AutoSigner
+    def save(instance, key = nil)
+      super
+
+      # Try to autosign the CSR.
+      if ca = Puppet::SSL::CertificateAuthority.instance
+        ca.autosign
+      end
+    end
+  end
+
+  indirects :certificate_request, :terminus_class => :file, :extend => AutoSigner
 
   # Convert a string into an instance.
   def self.from_s(string)
@@ -46,13 +59,4 @@ class Puppet::SSL::CertificateRequest < Puppet::SSL::Base
     Puppet.info "Certificate Request fingerprint (md5): #{fingerprint}"
     @content
   end
-
-  def save(args = {})
-    super()
-
-    # Try to autosign the CSR.
-    if ca = Puppet::SSL::CertificateAuthority.instance
-      ca.autosign
-    end
-  end
 end
diff --git a/spec/unit/ssl/certificate_request_spec.rb b/spec/unit/ssl/certificate_request_spec.rb
index f37f9ba..25b77b3 100755
--- a/spec/unit/ssl/certificate_request_spec.rb
+++ b/spec/unit/ssl/certificate_request_spec.rb
@@ -200,7 +200,9 @@ describe Puppet::SSL::CertificateRequest do
         Puppet::SSL::CertificateAuthority.expects(:instance).returns ca
 
         csr = Puppet::SSL::CertificateRequest.new("me")
-        Puppet::SSL::CertificateRequest.indirection.expects(:save).with(csr, nil)
+        terminus = mock 'terminus'
+        Puppet::SSL::CertificateRequest.indirection.expects(:prepare).returns(terminus)
+        terminus.expects(:save).with { |request| puts request.key.inspect; request.instance == csr && request.key == "me" }
 
         csr.save
       end
@@ -211,7 +213,9 @@ describe Puppet::SSL::CertificateRequest do
         Puppet::SSL::CertificateAuthority.expects(:instance).returns nil
 
         csr = Puppet::SSL::CertificateRequest.new("me")
-        Puppet::SSL::CertificateRequest.indirection.expects(:save).with(csr, nil)
+        terminus = mock 'terminus'
+        Puppet::SSL::CertificateRequest.indirection.expects(:prepare).returns(terminus)
+        terminus.expects(:save).with { |request| puts request.key.inspect; request.instance == csr && request.key == "me" }
 
         csr.save
       end

-- 
Puppet packaging for Debian



More information about the Pkg-puppet-devel mailing list