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
0
Merge Requests
0
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
Boxiang Sun
gitlab-ce
Commits
e16e1d57
Commit
e16e1d57
authored
Mar 07, 2017
by
Dmitriy Zaporozhets
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'dz-nested-groups-restrictions' into 'master'
Nested groups path restrictions pt. 1 See merge request !9738
parents
9533fc35
e6cc7a0a
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
34 additions
and
7 deletions
+34
-7
app/validators/namespace_validator.rb
app/validators/namespace_validator.rb
+14
-3
app/validators/project_path_validator.rb
app/validators/project_path_validator.rb
+2
-4
changelogs/unreleased/dz-nested-groups-restrictions.yml
changelogs/unreleased/dz-nested-groups-restrictions.yml
+4
-0
spec/models/namespace_spec.rb
spec/models/namespace_spec.rb
+14
-0
No files found.
app/validators/namespace_validator.rb
View file @
e16e1d57
...
@@ -35,13 +35,22 @@ class NamespaceValidator < ActiveModel::EachValidator
...
@@ -35,13 +35,22 @@ class NamespaceValidator < ActiveModel::EachValidator
users
users
]
.
freeze
]
.
freeze
WILDCARD_ROUTES
=
%w[tree commits wikis new edit create update logs_tree
preview blob blame raw files create_dir find_file]
.
freeze
STRICT_RESERVED
=
(
RESERVED
+
WILDCARD_ROUTES
).
freeze
def
self
.
valid?
(
value
)
def
self
.
valid?
(
value
)
!
reserved?
(
value
)
&&
follow_format?
(
value
)
!
reserved?
(
value
)
&&
follow_format?
(
value
)
end
end
def
self
.
reserved?
(
value
)
def
self
.
reserved?
(
value
,
strict:
false
)
if
strict
STRICT_RESERVED
.
include?
(
value
)
else
RESERVED
.
include?
(
value
)
RESERVED
.
include?
(
value
)
end
end
end
def
self
.
follow_format?
(
value
)
def
self
.
follow_format?
(
value
)
value
=~
Gitlab
::
Regex
.
namespace_regex
value
=~
Gitlab
::
Regex
.
namespace_regex
...
@@ -54,7 +63,9 @@ class NamespaceValidator < ActiveModel::EachValidator
...
@@ -54,7 +63,9 @@ class NamespaceValidator < ActiveModel::EachValidator
record
.
errors
.
add
(
attribute
,
Gitlab
::
Regex
.
namespace_regex_message
)
record
.
errors
.
add
(
attribute
,
Gitlab
::
Regex
.
namespace_regex_message
)
end
end
if
reserved?
(
value
)
strict
=
record
.
is_a?
(
Group
)
&&
record
.
parent_id
if
reserved?
(
value
,
strict:
strict
)
record
.
errors
.
add
(
attribute
,
"
#{
value
}
is a reserved name"
)
record
.
errors
.
add
(
attribute
,
"
#{
value
}
is a reserved name"
)
end
end
end
end
...
...
app/validators/project_path_validator.rb
View file @
e16e1d57
...
@@ -14,10 +14,8 @@ class ProjectPathValidator < ActiveModel::EachValidator
...
@@ -14,10 +14,8 @@ class ProjectPathValidator < ActiveModel::EachValidator
# without tree as reserved name routing can match 'group/project' as group name,
# without tree as reserved name routing can match 'group/project' as group name,
# 'tree' as project name and 'deploy_keys' as route.
# 'tree' as project name and 'deploy_keys' as route.
#
#
RESERVED
=
(
NamespaceValidator
::
RESERVED
-
RESERVED
=
(
NamespaceValidator
::
STRICT_RESERVED
-
%w[dashboard help ci admin search notes services assets profile public]
+
%w[dashboard help ci admin search notes services assets profile public]
).
freeze
%w[tree commits wikis new edit create update logs_tree
preview blob blame raw files create_dir find_file]
).
freeze
def
self
.
valid?
(
value
)
def
self
.
valid?
(
value
)
!
reserved?
(
value
)
!
reserved?
(
value
)
...
...
changelogs/unreleased/dz-nested-groups-restrictions.yml
0 → 100644
View file @
e16e1d57
---
title
:
Restrict nested group names to prevent ambiguous routes
merge_request
:
9738
author
:
spec/models/namespace_spec.rb
View file @
e16e1d57
...
@@ -28,6 +28,20 @@ describe Namespace, models: true do
...
@@ -28,6 +28,20 @@ describe Namespace, models: true do
expect
(
nested
).
not_to
be_valid
expect
(
nested
).
not_to
be_valid
expect
(
nested
.
errors
[
:parent_id
].
first
).
to
eq
(
'has too deep level of nesting'
)
expect
(
nested
.
errors
[
:parent_id
].
first
).
to
eq
(
'has too deep level of nesting'
)
end
end
describe
'reserved path validation'
do
context
'nested group'
do
let
(
:group
)
{
build
(
:group
,
:nested
,
path:
'tree'
)
}
it
{
expect
(
group
).
not_to
be_valid
}
end
context
'top-level group'
do
let
(
:group
)
{
build
(
:group
,
path:
'tree'
)
}
it
{
expect
(
group
).
to
be_valid
}
end
end
end
end
describe
"Respond to"
do
describe
"Respond to"
do
...
...
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