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
0bedee33
Commit
0bedee33
authored
May 13, 2020
by
Michael Kozono
Committed by
Igor Drozdov
May 13, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add feature flag to skip codeowners in the web UI
parent
b7d15b5f
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
64 additions
and
7 deletions
+64
-7
ee/changelogs/unreleased/security-apply-codeowners-checks-to-web_ui.yml
...unreleased/security-apply-codeowners-checks-to-web_ui.yml
+5
-0
ee/lib/ee/gitlab/checks/diff_check.rb
ee/lib/ee/gitlab/checks/diff_check.rb
+19
-2
ee/spec/lib/gitlab/checks/diff_check_spec.rb
ee/spec/lib/gitlab/checks/diff_check_spec.rb
+40
-5
No files found.
ee/changelogs/unreleased/security-apply-codeowners-checks-to-web_ui.yml
0 → 100644
View file @
0bedee33
---
title
:
Apply CODEOWNERS validations to web requests
merge_request
:
31283
author
:
type
:
security
ee/lib/ee/gitlab/checks/diff_check.rb
View file @
0bedee33
...
...
@@ -12,13 +12,28 @@ module EE
def
path_validations
validations
=
[
super
].
flatten
if
!
updated_from_web?
&&
project
.
branch_requires_code_owner_approval?
(
branch_name
)
if
validate_code_owners?
validations
<<
validate_code_owners
end
validations
end
def
validate_code_owners?
return
false
if
updated_from_web?
&&
skip_web_ui_code_owner_validations?
project
.
branch_requires_code_owner_approval?
(
branch_name
)
end
# To allow self-hosted installations to ignore CODEOWNERS rules when
# clicking Merge in the UI. By default, these rules are not skipped.
#
# Issue to remove this feature flag:
# https://gitlab.com/gitlab-org/gitlab/-/issues/217427
def
skip_web_ui_code_owner_validations?
::
Feature
.
enabled?
(
:skip_web_ui_code_owner_validations
,
project
)
end
def
validate_code_owners
lambda
do
|
paths
|
loader
=
::
Gitlab
::
CodeOwners
::
Loader
.
new
(
project
,
branch_name
,
paths
)
...
...
@@ -34,11 +49,13 @@ module EE
matched_rules
=
loader
.
entries
.
collect
{
|
e
|
"-
#{
e
.
pattern
}
"
}
code_owner_path
=
project
.
repository
.
code_owners_blob
(
ref:
branch_name
).
path
||
"CODEOWNERS"
"Pushes to protected branches that contain changes to files that
\n
"
\
msg
=
"Pushes to protected branches that contain changes to files that
\n
"
\
"match patterns defined in `
#{
code_owner_path
}
` are disabled for
\n
"
\
"this project. Please submit these changes via a merge request.
\n\n
"
\
"The following pattern(s) from `
#{
code_owner_path
}
` were matched:
\n
"
\
"
#{
matched_rules
.
join
(
'\n'
)
}
\n
"
updated_from_web?
?
msg
.
tr
(
"
\n
"
,
" "
)
:
msg
end
def
validate_path_locks?
...
...
ee/spec/lib/gitlab/checks/diff_check_spec.rb
View file @
0bedee33
...
...
@@ -89,8 +89,22 @@ describe Gitlab::Checks::DiffCheck do
stub_feature_flags
(
sectional_codeowners:
false
)
end
it
"returns an error message"
do
expect
(
validation_result
).
to
include
(
"Pushes to protected branches"
)
context
"for a non-web-based request"
do
it
"returns an error message"
do
expect
(
validation_result
).
to
include
(
"Pushes to protected branches"
)
expect
(
validation_result
).
to
include
(
"
\n
"
)
end
end
context
"for a web-based request"
do
before
do
allow
(
subject
).
to
receive
(
:updated_from_web?
).
and_return
(
true
)
end
it
"returns an error message with newline chars removed"
do
expect
(
validation_result
).
to
include
(
"Pushes to protected branches"
)
expect
(
validation_result
).
not_to
include
(
"
\n
"
)
end
end
end
...
...
@@ -211,11 +225,32 @@ describe Gitlab::Checks::DiffCheck do
context
"updated_from_web? == true"
do
before
do
expect
(
subject
).
to
receive
(
:updated_from_web?
).
and_return
(
true
)
expect
(
project
).
not_to
receive
(
:branch_requires_code_owner_approval?
)
end
it
"returns an empty array"
do
expect
(
subject
.
send
(
:path_validations
)).
to
eq
([])
context
"when skip_web_ui_code_owner_validations is disabled"
do
before
do
stub_feature_flags
(
skip_web_ui_code_owner_validations:
false
)
allow
(
project
).
to
receive
(
:branch_requires_code_owner_approval?
)
.
once
.
and_return
(
true
)
end
it
"returns an array of Proc(s)"
do
validations
=
subject
.
send
(
:path_validations
)
expect
(
validations
.
any?
).
to
be_truthy
expect
(
validations
.
any?
{
|
v
|
!
v
.
is_a?
Proc
}).
to
be_falsy
end
end
context
"when skip_web_ui_code_owner_validations is enabled"
do
before
do
stub_feature_flags
(
skip_web_ui_code_owner_validations:
true
)
expect
(
project
).
not_to
receive
(
:branch_requires_code_owner_approval?
)
end
it
"returns an empty array"
do
expect
(
subject
.
send
(
:path_validations
)).
to
eq
([])
end
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