This commit is contained in:
Luke Kanies 2008-07-02 18:36:05 -05:00
Родитель 8e4312ed24 e03c1be35c
Коммит 3795654323
2 изменённых файлов: 41 добавлений и 3 удалений

Просмотреть файл

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

Просмотреть файл

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