Rescue DN normalization attempts

This commit is contained in:
Michael Kozono 2017-09-18 16:40:04 -07:00
parent 79b5cbded7
commit 010cd3dea8
2 changed files with 39 additions and 0 deletions

View file

@ -43,6 +43,11 @@ module Gitlab
else
normalize_uid(uid_or_dn)
end
rescue StandardError => e
Rails.logger.info("Returning original DN \"#{uid_or_dn}\" due to error during normalization attempt: #{e.message}")
Rails.logger.info(e.backtrace.join("\n"))
uid_or_dn
end
# Returns true if the string looks like a DN rather than a UID.
@ -59,6 +64,11 @@ module Gitlab
# 2. The string is downcased (for case-insensitivity)
def self.normalize_uid(uid)
normalize_dn_part(uid)
rescue StandardError => e
Rails.logger.info("Returning original UID \"#{uid}\" due to error during normalization attempt: #{e.message}")
Rails.logger.info(e.backtrace.join("\n"))
uid
end
# Returns the DN in a normalized form.
@ -69,6 +79,11 @@ module Gitlab
dn.split(/(?<!\\)([,+=])/).map do |part|
normalize_dn_part(part)
end.join('')
rescue StandardError => e
Rails.logger.info("Returning original DN \"#{dn}\" due to error during normalization attempt: #{e.message}")
Rails.logger.info(e.backtrace.join("\n"))
dn
end
def initialize(entry, provider)

View file

@ -82,18 +82,42 @@ describe Gitlab::LDAP::Person do
it_behaves_like 'normalizes the DN'
it_behaves_like 'normalizes the UID'
context 'with an exception during normalization' do
let(:given) { described_class } # just something that will cause an exception
it 'returns the given object unmodified' do
expect(subject).to eq(given)
end
end
end
describe '.normalize_uid' do
subject { described_class.normalize_uid(given) }
it_behaves_like 'normalizes the UID'
context 'with an exception during normalization' do
let(:given) { described_class } # just something that will cause an exception
it 'returns the given UID unmodified' do
expect(subject).to eq(given)
end
end
end
describe '.normalize_dn' do
subject { described_class.normalize_dn(given) }
it_behaves_like 'normalizes the DN'
context 'with an exception during normalization' do
let(:given) { described_class } # just something that will cause an exception
it 'returns the given DN unmodified' do
expect(subject).to eq(given)
end
end
end
describe '.dn?' do