BigW Consortium Gitlab
Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gitlab-ce
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Forest Godfrey
gitlab-ce
Commits
f7511caa
Commit
f7511caa
authored
Apr 11, 2017
by
Bob Van Landuyt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Split off validating full paths
The first part of a full path needs to be validated as a `top_level` while the rest need to be validated as `wildcard`
parent
e4f5b7ca
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
28 additions
and
6 deletions
+28
-6
namespace_validator.rb
app/validators/namespace_validator.rb
+8
-6
namespace_validator_spec.rb
spec/validators/namespace_validator_spec.rb
+20
-0
No files found.
app/validators/namespace_validator.rb
View file @
f7511caa
...
...
@@ -77,12 +77,14 @@ class NamespaceValidator < ActiveModel::EachValidator
STRICT_RESERVED
=
(
TOP_LEVEL_ROUTES
|
WILDCARD_ROUTES
)
def
self
.
valid_full_path?
(
full_path
)
pieces
=
full_path
.
split
(
'/'
)
first_part
=
pieces
.
first
pieces
.
all?
do
|
namespace
|
type
=
first_part
==
namespace
?
:
top_level
:
:wildcard
valid?
(
namespace
,
type:
type
)
end
path_segments
=
full_path
.
split
(
'/'
)
root_segment
=
path_segments
.
shift
valid?
(
root_segment
,
type: :top_level
)
&&
valid_wildcard_segments?
(
path_segments
)
end
def
self
.
valid_wildcard_segments?
(
segments
)
segments
.
all?
{
|
segment
|
valid?
(
segment
,
type: :wildcard
)
}
end
def
self
.
valid?
(
value
,
type: :strict
)
...
...
spec/validators/namespace_validator_spec.rb
View file @
f7511caa
...
...
@@ -81,6 +81,26 @@ describe NamespaceValidator do
end
end
describe
'#valid_full_path'
do
it
"isn't valid when the top level is reserved"
do
test_path
=
'u/should-be-a/reserved-word'
expect
(
described_class
.
valid_full_path?
(
test_path
)).
to
be
(
false
)
end
it
"isn't valid if any of the path segments is reserved"
do
test_path
=
'the-wildcard/wikis/is-a-reserved-path'
expect
(
described_class
.
valid_full_path?
(
test_path
)).
to
be
(
false
)
end
it
"is valid if the path doen't contain reserved words"
do
test_path
=
'there-are/no-wildcards/in-this-path'
expect
(
described_class
.
valid_full_path?
(
test_path
)).
to
be
(
true
)
end
end
describe
'#validation_type'
do
it
'uses top level validation for groups without parent'
do
group
=
build
(
:group
)
...
...
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