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
2ee8f590
Commit
2ee8f590
authored
Sep 25, 2017
by
James Lopez
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added ldap validator and spec
parent
734ca1eb
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
40 additions
and
0 deletions
+40
-0
app/validators/ldap_filter_validator.rb
app/validators/ldap_filter_validator.rb
+17
-0
spec/validators/ldap_filter_validator_spec.rb
spec/validators/ldap_filter_validator_spec.rb
+23
-0
No files found.
app/validators/ldap_filter_validator.rb
0 → 100644
View file @
2ee8f590
# LdapFilteralidator
#
# Custom validator for LDAP filters
#
# Example:
#
# class LdapGroupLink < ActiveRecord::Base
# validates :filter, ldap_filter: true
# end
#
class
LdapFilterValidator
<
ActiveModel
::
EachValidator
def
validate_each
(
record
,
attribute
,
value
)
Net
::
LDAP
::
Filter
::
FilterParser
.
parse
(
value
)
rescue
Net
::
LDAP
::
FilterSyntaxInvalidError
record
.
errors
.
add
(
attribute
,
'must be a valid filter'
)
end
end
spec/validators/ldap_filter_validator_spec.rb
0 → 100644
View file @
2ee8f590
require
'spec_helper'
describe
LdapFilterValidator
do
let
(
:validator
)
{
described_class
.
new
(
attributes:
[
:filter
])
}
describe
'#validates_each'
do
it
'adds a message when the filter is not valid'
do
link
=
build
(
:ldap_group_link
,
cn:
nil
)
validator
.
validate_each
(
link
,
:filter
,
'wrong filter'
)
expect
(
link
.
errors
[
:filter
]).
to
match_array
([
'must be a valid filter'
])
end
it
'has no errors when is valid'
do
link
=
build
(
:ldap_group_link
,
cn:
nil
)
validator
.
validate_each
(
link
,
:filter
,
'(cn=Babs Jensen)'
)
expect
(
link
.
errors
[
:filter
]).
to
eq
([])
end
end
end
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