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

Rescue DN normalization attempts

parent 79b5cbde
...@@ -43,6 +43,11 @@ module Gitlab ...@@ -43,6 +43,11 @@ module Gitlab
else else
normalize_uid(uid_or_dn) normalize_uid(uid_or_dn)
end 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 end
# Returns true if the string looks like a DN rather than a UID. # Returns true if the string looks like a DN rather than a UID.
...@@ -59,6 +64,11 @@ module Gitlab ...@@ -59,6 +64,11 @@ module Gitlab
# 2. The string is downcased (for case-insensitivity) # 2. The string is downcased (for case-insensitivity)
def self.normalize_uid(uid) def self.normalize_uid(uid)
normalize_dn_part(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 end
# Returns the DN in a normalized form. # Returns the DN in a normalized form.
...@@ -69,6 +79,11 @@ module Gitlab ...@@ -69,6 +79,11 @@ module Gitlab
dn.split(/(?<!\\)([,+=])/).map do |part| dn.split(/(?<!\\)([,+=])/).map do |part|
normalize_dn_part(part) normalize_dn_part(part)
end.join('') 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 end
def initialize(entry, provider) def initialize(entry, provider)
......
...@@ -82,18 +82,42 @@ describe Gitlab::LDAP::Person do ...@@ -82,18 +82,42 @@ describe Gitlab::LDAP::Person do
it_behaves_like 'normalizes the DN' it_behaves_like 'normalizes the DN'
it_behaves_like 'normalizes the UID' 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 end
describe '.normalize_uid' do describe '.normalize_uid' do
subject { described_class.normalize_uid(given) } subject { described_class.normalize_uid(given) }
it_behaves_like 'normalizes the UID' 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 end
describe '.normalize_dn' do describe '.normalize_dn' do
subject { described_class.normalize_dn(given) } subject { described_class.normalize_dn(given) }
it_behaves_like 'normalizes the DN' 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 end
describe '.dn?' do 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