Commit 010cd3de authored by Michael Kozono's avatar Michael Kozono

Rescue DN normalization attempts

parent 79b5cbde
......@@ -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)
......
......@@ -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
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment