diff --git a/lib/gitlab/ldap/person.rb b/lib/gitlab/ldap/person.rb index ca96a099714..5b0d011ee00 100644 --- a/lib/gitlab/ldap/person.rb +++ b/lib/gitlab/ldap/person.rb @@ -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(/(? 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) diff --git a/spec/lib/gitlab/ldap/person_spec.rb b/spec/lib/gitlab/ldap/person_spec.rb index 5f5ac990c55..f561fc18f2a 100644 --- a/spec/lib/gitlab/ldap/person_spec.rb +++ b/spec/lib/gitlab/ldap/person_spec.rb @@ -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