Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
1d1ad7e0
Commit
1d1ad7e0
authored
Oct 05, 2017
by
Michael Kozono
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor DN error classes
parent
1c945de9
Changes
4
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
78 additions
and
76 deletions
+78
-76
lib/gitlab/background_migration/normalize_ldap_extern_uids_range.rb
.../background_migration/normalize_ldap_extern_uids_range.rb
+15
-14
lib/gitlab/ldap/dn.rb
lib/gitlab/ldap/dn.rb
+14
-13
lib/gitlab/ldap/person.rb
lib/gitlab/ldap/person.rb
+1
-1
spec/lib/gitlab/ldap/dn_spec.rb
spec/lib/gitlab/ldap/dn_spec.rb
+48
-48
No files found.
lib/gitlab/background_migration/normalize_ldap_extern_uids_range.rb
View file @
1d1ad7e0
...
...
@@ -10,10 +10,11 @@ module Gitlab
# accompanied by another migration.
module
Gitlab
module
LDAP
MalformedDnError
=
Class
.
new
(
StandardError
)
UnsupportedDnFormatError
=
Class
.
new
(
StandardError
)
class
DN
FormatError
=
Class
.
new
(
StandardError
)
MalformedError
=
Class
.
new
(
FormatError
)
UnsupportedError
=
Class
.
new
(
FormatError
)
def
self
.
normalize_value
(
given_value
)
dummy_dn
=
"placeholder=
#{
given_value
}
"
normalized_dn
=
new
(
*
dummy_dn
).
to_normalized_s
...
...
@@ -79,19 +80,19 @@ module Gitlab
state
=
:key_oid
key
<<
char
when
' '
then
state
=
:key
else
raise
(
Malformed
Dn
Error
,
"Unrecognized first character of an RDN attribute type name
\"
#{
char
}
\"
"
)
else
raise
(
MalformedError
,
"Unrecognized first character of an RDN attribute type name
\"
#{
char
}
\"
"
)
end
when
:key_normal
then
case
char
when
'='
then
state
=
:value
when
'a'
..
'z'
,
'A'
..
'Z'
,
'0'
..
'9'
,
'-'
,
' '
then
key
<<
char
else
raise
(
Malformed
Dn
Error
,
"Unrecognized RDN attribute type name character
\"
#{
char
}
\"
"
)
else
raise
(
MalformedError
,
"Unrecognized RDN attribute type name character
\"
#{
char
}
\"
"
)
end
when
:key_oid
then
case
char
when
'='
then
state
=
:value
when
'0'
..
'9'
,
'.'
,
' '
then
key
<<
char
else
raise
(
Malformed
Dn
Error
,
"Unrecognized RDN OID attribute type name character
\"
#{
char
}
\"
"
)
else
raise
(
MalformedError
,
"Unrecognized RDN OID attribute type name character
\"
#{
char
}
\"
"
)
end
when
:value
then
case
char
...
...
@@ -118,7 +119,7 @@ module Gitlab
yield
key
.
string
.
strip
,
rstrip_except_escaped
(
value
.
string
,
dn_index
)
key
=
StringIO
.
new
value
=
StringIO
.
new
when
'+'
then
raise
(
Unsupported
DnFormat
Error
,
"Multivalued RDNs are not supported"
)
when
'+'
then
raise
(
UnsupportedError
,
"Multivalued RDNs are not supported"
)
else
value
<<
char
end
when
:value_normal_escape
then
...
...
@@ -135,7 +136,7 @@ module Gitlab
when
'0'
..
'9'
,
'a'
..
'f'
,
'A'
..
'F'
then
state
=
:value_normal
value
<<
"
#{
hex_buffer
}#{
char
}
"
.
to_i
(
16
).
chr
else
raise
(
Malformed
Dn
Error
,
"Invalid escaped hex code
\"\\
#{
hex_buffer
}#{
char
}
\"
"
)
else
raise
(
MalformedError
,
"Invalid escaped hex code
\"\\
#{
hex_buffer
}#{
char
}
\"
"
)
end
when
:value_quoted
then
case
char
...
...
@@ -157,7 +158,7 @@ module Gitlab
when
'0'
..
'9'
,
'a'
..
'f'
,
'A'
..
'F'
then
state
=
:value_quoted
value
<<
"
#{
hex_buffer
}#{
char
}
"
.
to_i
(
16
).
chr
else
raise
(
Malformed
Dn
Error
,
"Expected the second character of a hex pair inside a double quoted value, but got
\"
#{
char
}
\"
"
)
else
raise
(
MalformedError
,
"Expected the second character of a hex pair inside a double quoted value, but got
\"
#{
char
}
\"
"
)
end
when
:value_hexstring
then
case
char
...
...
@@ -170,14 +171,14 @@ module Gitlab
yield
key
.
string
.
strip
,
rstrip_except_escaped
(
value
.
string
,
dn_index
)
key
=
StringIO
.
new
value
=
StringIO
.
new
else
raise
(
Malformed
Dn
Error
,
"Expected the first character of a hex pair, but got
\"
#{
char
}
\"
"
)
else
raise
(
MalformedError
,
"Expected the first character of a hex pair, but got
\"
#{
char
}
\"
"
)
end
when
:value_hexstring_hex
then
case
char
when
'0'
..
'9'
,
'a'
..
'f'
,
'A'
..
'F'
then
state
=
:value_hexstring
value
<<
char
else
raise
(
Malformed
Dn
Error
,
"Expected the second character of a hex pair, but got
\"
#{
char
}
\"
"
)
else
raise
(
MalformedError
,
"Expected the second character of a hex pair, but got
\"
#{
char
}
\"
"
)
end
when
:value_end
then
case
char
...
...
@@ -187,14 +188,14 @@ module Gitlab
yield
key
.
string
.
strip
,
rstrip_except_escaped
(
value
.
string
,
dn_index
)
key
=
StringIO
.
new
value
=
StringIO
.
new
else
raise
(
Malformed
Dn
Error
,
"Expected the end of an attribute value, but got
\"
#{
char
}
\"
"
)
else
raise
(
MalformedError
,
"Expected the end of an attribute value, but got
\"
#{
char
}
\"
"
)
end
else
raise
"Fell out of state machine"
end
end
# Last pair
raise
(
Malformed
Dn
Error
,
'DN string ended unexpectedly'
)
unless
raise
(
MalformedError
,
'DN string ended unexpectedly'
)
unless
[
:value
,
:value_normal
,
:value_hexstring
,
:value_end
].
include?
state
yield
key
.
string
.
strip
,
rstrip_except_escaped
(
value
.
string
,
@dn
.
length
)
...
...
@@ -290,7 +291,7 @@ module Gitlab
unless
identity
.
save
Rails
.
logger
.
info
"Unable to normalize
\"
#{
identity
.
extern_uid
}
\"
. Skipping."
end
rescue
Gitlab
::
LDAP
::
MalformedDnError
,
Gitlab
::
LDAP
::
UnsupportedDn
FormatError
=>
e
rescue
Gitlab
::
LDAP
::
DN
::
FormatError
=>
e
Rails
.
logger
.
info
"Unable to normalize
\"
#{
identity
.
extern_uid
}
\"
due to
\"
#{
e
.
message
}
\"
. Skipping."
end
end
...
...
lib/gitlab/ldap/dn.rb
View file @
1d1ad7e0
...
...
@@ -21,10 +21,11 @@
# class also helps take care of that.
module
Gitlab
module
LDAP
MalformedDnError
=
Class
.
new
(
StandardError
)
UnsupportedDnFormatError
=
Class
.
new
(
StandardError
)
class
DN
FormatError
=
Class
.
new
(
StandardError
)
MalformedError
=
Class
.
new
(
FormatError
)
UnsupportedError
=
Class
.
new
(
FormatError
)
def
self
.
normalize_value
(
given_value
)
dummy_dn
=
"placeholder=
#{
given_value
}
"
normalized_dn
=
new
(
*
dummy_dn
).
to_normalized_s
...
...
@@ -90,19 +91,19 @@ module Gitlab
state
=
:key_oid
key
<<
char
when
' '
then
state
=
:key
else
raise
(
Malformed
Dn
Error
,
"Unrecognized first character of an RDN attribute type name
\"
#{
char
}
\"
"
)
else
raise
(
MalformedError
,
"Unrecognized first character of an RDN attribute type name
\"
#{
char
}
\"
"
)
end
when
:key_normal
then
case
char
when
'='
then
state
=
:value
when
'a'
..
'z'
,
'A'
..
'Z'
,
'0'
..
'9'
,
'-'
,
' '
then
key
<<
char
else
raise
(
Malformed
Dn
Error
,
"Unrecognized RDN attribute type name character
\"
#{
char
}
\"
"
)
else
raise
(
MalformedError
,
"Unrecognized RDN attribute type name character
\"
#{
char
}
\"
"
)
end
when
:key_oid
then
case
char
when
'='
then
state
=
:value
when
'0'
..
'9'
,
'.'
,
' '
then
key
<<
char
else
raise
(
Malformed
Dn
Error
,
"Unrecognized RDN OID attribute type name character
\"
#{
char
}
\"
"
)
else
raise
(
MalformedError
,
"Unrecognized RDN OID attribute type name character
\"
#{
char
}
\"
"
)
end
when
:value
then
case
char
...
...
@@ -129,7 +130,7 @@ module Gitlab
yield
key
.
string
.
strip
,
rstrip_except_escaped
(
value
.
string
,
dn_index
)
key
=
StringIO
.
new
value
=
StringIO
.
new
when
'+'
then
raise
(
Unsupported
DnFormat
Error
,
"Multivalued RDNs are not supported"
)
when
'+'
then
raise
(
UnsupportedError
,
"Multivalued RDNs are not supported"
)
else
value
<<
char
end
when
:value_normal_escape
then
...
...
@@ -146,7 +147,7 @@ module Gitlab
when
'0'
..
'9'
,
'a'
..
'f'
,
'A'
..
'F'
then
state
=
:value_normal
value
<<
"
#{
hex_buffer
}#{
char
}
"
.
to_i
(
16
).
chr
else
raise
(
Malformed
Dn
Error
,
"Invalid escaped hex code
\"\\
#{
hex_buffer
}#{
char
}
\"
"
)
else
raise
(
MalformedError
,
"Invalid escaped hex code
\"\\
#{
hex_buffer
}#{
char
}
\"
"
)
end
when
:value_quoted
then
case
char
...
...
@@ -168,7 +169,7 @@ module Gitlab
when
'0'
..
'9'
,
'a'
..
'f'
,
'A'
..
'F'
then
state
=
:value_quoted
value
<<
"
#{
hex_buffer
}#{
char
}
"
.
to_i
(
16
).
chr
else
raise
(
Malformed
Dn
Error
,
"Expected the second character of a hex pair inside a double quoted value, but got
\"
#{
char
}
\"
"
)
else
raise
(
MalformedError
,
"Expected the second character of a hex pair inside a double quoted value, but got
\"
#{
char
}
\"
"
)
end
when
:value_hexstring
then
case
char
...
...
@@ -181,14 +182,14 @@ module Gitlab
yield
key
.
string
.
strip
,
rstrip_except_escaped
(
value
.
string
,
dn_index
)
key
=
StringIO
.
new
value
=
StringIO
.
new
else
raise
(
Malformed
Dn
Error
,
"Expected the first character of a hex pair, but got
\"
#{
char
}
\"
"
)
else
raise
(
MalformedError
,
"Expected the first character of a hex pair, but got
\"
#{
char
}
\"
"
)
end
when
:value_hexstring_hex
then
case
char
when
'0'
..
'9'
,
'a'
..
'f'
,
'A'
..
'F'
then
state
=
:value_hexstring
value
<<
char
else
raise
(
Malformed
Dn
Error
,
"Expected the second character of a hex pair, but got
\"
#{
char
}
\"
"
)
else
raise
(
MalformedError
,
"Expected the second character of a hex pair, but got
\"
#{
char
}
\"
"
)
end
when
:value_end
then
case
char
...
...
@@ -198,14 +199,14 @@ module Gitlab
yield
key
.
string
.
strip
,
rstrip_except_escaped
(
value
.
string
,
dn_index
)
key
=
StringIO
.
new
value
=
StringIO
.
new
else
raise
(
Malformed
Dn
Error
,
"Expected the end of an attribute value, but got
\"
#{
char
}
\"
"
)
else
raise
(
MalformedError
,
"Expected the end of an attribute value, but got
\"
#{
char
}
\"
"
)
end
else
raise
"Fell out of state machine"
end
end
# Last pair
raise
(
Malformed
Dn
Error
,
'DN string ended unexpectedly'
)
unless
raise
(
MalformedError
,
'DN string ended unexpectedly'
)
unless
[
:value
,
:value_normal
,
:value_hexstring
,
:value_end
].
include?
state
yield
key
.
string
.
strip
,
rstrip_except_escaped
(
value
.
string
,
@dn
.
length
)
...
...
lib/gitlab/ldap/person.rb
View file @
1d1ad7e0
...
...
@@ -42,7 +42,7 @@ module Gitlab
# 2. The string is downcased (for case-insensitivity)
def
self
.
normalize_uid
(
uid
)
::
Gitlab
::
LDAP
::
DN
.
normalize_value
(
uid
)
rescue
::
Gitlab
::
LDAP
::
MalformedDnError
,
::
Gitlab
::
LDAP
::
UnsupportedDn
FormatError
=>
e
rescue
::
Gitlab
::
LDAP
::
DN
::
FormatError
=>
e
Rails
.
logger
.
info
(
"Returning original UID
\"
#{
uid
}
\"
due to error during normalization attempt:
#{
e
.
message
}
"
)
Rails
.
logger
.
info
(
e
.
backtrace
.
join
(
"
\n
"
))
...
...
spec/lib/gitlab/ldap/dn_spec.rb
View file @
1d1ad7e0
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment