Commit ca5ade22 authored by Michael Kozono's avatar Michael Kozono

Fix `dn?` for a UID with an escaped equal sign

parent fee3c95d
...@@ -50,7 +50,7 @@ module Gitlab ...@@ -50,7 +50,7 @@ module Gitlab
# An empty string is technically a valid DN (null DN), although we should # An empty string is technically a valid DN (null DN), although we should
# never need to worry about that. # never need to worry about that.
def self.dn?(uid_or_dn) def self.dn?(uid_or_dn)
uid_or_dn.blank? || uid_or_dn.include?('=') uid_or_dn.blank? || !!uid_or_dn.match(/(?<!\\)=/)
end end
# Returns the UID in a normalized form. # Returns the UID in a normalized form.
......
...@@ -100,12 +100,13 @@ describe Gitlab::LDAP::Person do ...@@ -100,12 +100,13 @@ describe Gitlab::LDAP::Person do
where(:test_description, :given, :expected) do where(:test_description, :given, :expected) do
'given a DN with a single RDN' | 'uid=John C. Smith' | true 'given a DN with a single RDN' | 'uid=John C. Smith' | true
'given a DN with multiple RDNs' | 'uid=John C. Smith,ou=People,dc=example,dc=com' | true 'given a DN with multiple RDNs' | 'uid=John C. Smith,ou=People,dc=example,dc=com' | true
'given a UID' | 'John C. Smith' | false
'given a DN with a single RDN with excess spaces' | ' uid=John C. Smith ' | true 'given a DN with a single RDN with excess spaces' | ' uid=John C. Smith ' | true
'given a DN with multiple RDNs with excess spaces' | ' uid=John C. Smith,ou=People,dc=example,dc=com ' | true 'given a DN with multiple RDNs with excess spaces' | ' uid=John C. Smith,ou=People,dc=example,dc=com ' | true
'given a UID with excess spaces' | ' John C. Smith ' | false
'given a DN with an escaped equal sign' | 'uid=John C. Smith,ou=People\\=' | true 'given a DN with an escaped equal sign' | 'uid=John C. Smith,ou=People\\=' | true
'given a DN with an equal sign in escaped hex' | 'uid=John C. Smith,ou=People\\3D' | true 'given a DN with an equal sign in escaped hex' | 'uid=John C. Smith,ou=People\\3D' | true
'given a UID' | 'John C. Smith' | false
'given a UID with excess spaces' | ' John C. Smith ' | false
'given a UID with an escaped equal sign' | 'John C. \\= Smith' | false
end end
with_them do with_them 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