It only works when finding certificates, but that should be sufficient.

Signed-off-by: Luke Kanies <[EMAIL PROTECTED]>
---
 lib/puppet/indirector/ssl_file.rb |   26 +++++++++++++++++++++++++-
 spec/unit/indirector/ssl_file.rb  |   28 ++++++++++++++++++++++++++++
 2 files changed, 53 insertions(+), 1 deletions(-)

diff --git a/lib/puppet/indirector/ssl_file.rb 
b/lib/puppet/indirector/ssl_file.rb
index 44a66fa..d93298c 100644
--- a/lib/puppet/indirector/ssl_file.rb
+++ b/lib/puppet/indirector/ssl_file.rb
@@ -79,7 +79,7 @@ class Puppet::Indirector::SslFile < 
Puppet::Indirector::Terminus
     def find(request)
         path = path(request.key)
 
-        return nil unless FileTest.exist?(path)
+        return nil unless FileTest.exist?(path) or 
rename_files_with_uppercase(path)
 
         result = model.new(request.key)
         result.read(path)
@@ -124,6 +124,30 @@ class Puppet::Indirector::SslFile < 
Puppet::Indirector::Terminus
         self.class.ca_location
     end
 
+    # A hack method to deal with files that exist with a different case.
+    # Just renames it; doesn't read it in or anything.
+    # LAK:NOTE This is a copy of the method in sslcertificates/support.rb,
+    # which we'll be EOL'ing at some point.  This method was added at 20080702
+    # and should be removed at some point.
+    def rename_files_with_uppercase(file)
+        dir, short = File.split(file)
+        return nil unless FileTest.exist?(dir)
+
+        raise ArgumentError, "Tried to fix SSL files to a file containing 
uppercase" unless short.downcase == short
+        real_file = Dir.entries(dir).reject { |f| f =~ /^\./ }.find do |other|
+            other.downcase == short
+        end
+
+        return nil unless real_file
+
+        full_file = File.join(dir, real_file)
+
+        Puppet.notice "Fixing case in %s; renaming to %s" % [full_file, file]
+        File.rename(full_file, file)
+
+        return true
+    end
+
     # Yield a filehandle set up appropriately, either with our settings doing
     # the work or opening a filehandle manually.
     def write(name, path)
diff --git a/spec/unit/indirector/ssl_file.rb b/spec/unit/indirector/ssl_file.rb
index 864ba14..756101a 100755
--- a/spec/unit/indirector/ssl_file.rb
+++ b/spec/unit/indirector/ssl_file.rb
@@ -91,6 +91,8 @@ describe Puppet::Indirector::SslFile do
         describe "when finding certificates on disk" do
             describe "and no certificate is present" do
                 before do
+                    # Stub things so the case management bits work.
+                    
FileTest.stubs(:exist?).with(File.dirname(@certpath)).returns false
                     FileTest.expects(:exist?).with(@certpath).returns false
                 end
 
@@ -114,6 +116,32 @@ describe Puppet::Indirector::SslFile do
                     @searcher.find(@request).should equal(cert)
                 end
             end
+
+            describe "and a certificate is present but has uppercase letters" 
do
+                before do
+                    @request = stub 'request', :key => "myhost"
+                end
+
+                # This is kind of more an integration test; it's for #1382, 
until
+                # the support for upper-case certs can be removed around 
mid-2009.
+                it "should rename the existing file to the lower-case path" do
+                    @path = @searcher.path("myhost")
+                    FileTest.expects(:exist?).with(@path).returns(false)
+                    dir, file = File.split(@path)
+                    FileTest.expects(:exist?).with(dir).returns true
+                    Dir.expects(:entries).with(dir).returns [".", "..", 
"something.pem", file.upcase]
+
+                    File.expects(:rename).with(File.join(dir, file.upcase), 
@path)
+
+                    cert = mock 'cert'
+                    model = mock 'model'
+                    @searcher.stubs(:model).returns model
+                    @searcher.model.expects(:new).with("myhost").returns cert
+                    cert.expects(:read).with(@path)
+
+                    @searcher.find(@request)
+                end
+            end
         end
 
         describe "when saving certificates to disk" do
-- 
1.5.3.7


--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to