This correctly renames the files and they still get read in.

Signed-off-by: Luke Kanies <[EMAIL PROTECTED]>
---
 lib/puppet/sslcertificates/support.rb |   24 ++++++++++++++++++++++--
 test/certmgr/support.rb               |   20 +++++++++++++++++++-
 2 files changed, 41 insertions(+), 3 deletions(-)

diff --git a/lib/puppet/sslcertificates/support.rb 
b/lib/puppet/sslcertificates/support.rb
index 1d692c9..95f15f0 100644
--- a/lib/puppet/sslcertificates/support.rb
+++ b/lib/puppet/sslcertificates/support.rb
@@ -28,7 +28,8 @@ module Puppet::SSLCertificates::Support
 
         # Define the reading method.
         define_method(reader) do
-            return nil unless FileTest.exists?(Puppet[param])
+            return nil unless FileTest.exists?(Puppet[param]) or 
rename_files_with_uppercase(Puppet[param])
+
             begin
                 instance_variable_set(var, klass.new(File.read(Puppet[param])))
             rescue => detail
@@ -121,5 +122,24 @@ module Puppet::SSLCertificates::Support
         end
         return retrieved
     end
-end
 
+    # A hack method to deal with files that exist with a different case.
+    # Just renames it; doesn't read it in or anything.
+    def rename_files_with_uppercase(file)
+        dir = File.dirname(file)
+        short = File.basename(file)
+        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
+end
diff --git a/test/certmgr/support.rb b/test/certmgr/support.rb
index cdbbe3f..c055cbc 100755
--- a/test/certmgr/support.rb
+++ b/test/certmgr/support.rb
@@ -78,5 +78,23 @@ class TestCertSupport < Test::Unit::TestCase
             @user.ca_cert
         end
     end
-end
 
+    # Fixing #1382.
+    def test_uppercase_files_are_renamed_and_read
+        # Write a key out to disk in a file containing upper-case.
+        key = OpenSSL::PKey::RSA.new(32)
+        should_path = Puppet[:hostprivkey]
+
+        dir, file = File.split(should_path)
+        newfile = file.sub(/^([a-z.]+)\./) { $1.upcase + "."}
+        upper_path = File.join(dir, newfile)
+        File.open(upper_path, "w") { |f| f.print key.to_s }
+
+        user = CertUser.new
+
+        assert_equal(key.to_s, user.read_key.to_s, "Did not read key in from 
disk")
+        assert(! FileTest.exist?(upper_path), "Upper case file was not 
removed")
+        assert(FileTest.exist?(should_path), "File was not renamed to 
lower-case file")
+        assert_equal(key.to_s, user.read_key.to_s, "Did not read key in from 
disk")
+    end
+end
-- 
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