Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
O
OHR Support
Manage
Activity
Members
Labels
Plan
Issues
97
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Projects
OHR Support
Commits
0f8a040d
Commit
0f8a040d
authored
13 years ago
by
Eric Davis
Committed by
elm
13 years ago
Browse files
Options
Downloads
Patches
Plain Diff
[#3619] Validate the AuthSourceLdap#custom_filter
Conflicts: app/models/auth_source_ldap.rb test/unit/auth_source_ldap_test.rb
parent
1318ac20
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
app/models/auth_source_ldap.rb
+11
-0
11 additions, 0 deletions
app/models/auth_source_ldap.rb
test/unit/auth_source_ldap_test.rb
+14
-0
14 additions, 0 deletions
test/unit/auth_source_ldap_test.rb
with
25 additions
and
0 deletions
app/models/auth_source_ldap.rb
+
11
−
0
View file @
0f8a040d
...
...
@@ -21,6 +21,7 @@ class AuthSourceLdap < AuthSource
validates_length_of
:account
,
:account_password
,
:base_dn
,
:maximum
=>
255
,
:allow_nil
=>
true
validates_length_of
:attr_login
,
:attr_firstname
,
:attr_lastname
,
:attr_mail
,
:maximum
=>
30
,
:allow_nil
=>
true
validates_numericality_of
:port
,
:only_integer
=>
true
validate
:custom_filter_should_be_valid_ldap_filter_syntax
before_validation
:strip_ldap_attributes
...
...
@@ -136,6 +137,16 @@ class AuthSourceLdap < AuthSource
return
nil
end
end
def
custom_filter_should_be_valid_ldap_filter_syntax
return
true
unless
custom_filter
.
present?
begin
return
Net
::
LDAP
::
Filter
.
construct
(
custom_filter
)
rescue
Net
::
LDAP
::
LdapError
# Filter syntax error
errors
.
add
(
:custom_filter
,
:invalid
)
end
end
def
self
.
get_attr
(
entry
,
attr_name
)
if
!
attr_name
.
blank?
...
...
This diff is collapsed.
Click to expand it.
test/unit/auth_source_ldap_test.rb
+
14
−
0
View file @
0f8a040d
...
...
@@ -31,6 +31,20 @@ class AuthSourceLdapTest < ActiveSupport::TestCase
assert_equal
'givenName'
,
a
.
reload
.
attr_firstname
end
context
"validations"
do
should
"validate that custom_filter is a valid LDAP filter"
do
@auth
=
AuthSourceLdap
.
new
(
:name
=>
'Validation'
,
:host
=>
'localhost'
,
:port
=>
389
,
:attr_login
=>
'login'
)
@auth
.
custom_filter
=
"(& (homeDirectory=*) (sn=O*"
# Missing ((
assert
@auth
.
invalid?
assert_equal
"is invalid"
,
@auth
.
errors
.
on
(
:custom_filter
)
@auth
.
custom_filter
=
"(& (homeDirectory=*) (sn=O*))"
assert
@auth
.
valid?
assert_equal
nil
,
@auth
.
errors
.
on
(
:custom_filter
)
end
end
if
ldap_configured?
context
'#authenticate'
do
setup
do
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment