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
185d6a25
Commit
185d6a25
authored
May 31, 2021
by
GitLab Bot
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add latest changes from gitlab-org/security/gitlab@13-12-stable-ee
parent
4530f5d0
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
68 additions
and
2 deletions
+68
-2
lib/api/lint.rb
lib/api/lint.rb
+1
-1
lib/gitlab/current_settings.rb
lib/gitlab/current_settings.rb
+4
-0
spec/lib/gitlab/current_settings_spec.rb
spec/lib/gitlab/current_settings_spec.rb
+36
-0
spec/requests/api/lint_spec.rb
spec/requests/api/lint_spec.rb
+27
-1
No files found.
lib/api/lint.rb
View file @
185d6a25
...
...
@@ -11,7 +11,7 @@ module API
optional
:include_merged_yaml
,
type:
Boolean
,
desc:
'Whether or not to include merged CI config yaml in the response'
end
post
'/lint'
do
unauthorized!
if
Gitlab
::
CurrentSettings
.
signup_disabled?
&&
current_user
.
nil?
unauthorized!
if
(
Gitlab
::
CurrentSettings
.
signup_disabled?
||
Gitlab
::
CurrentSettings
.
signup_limited?
)
&&
current_user
.
nil?
result
=
Gitlab
::
Ci
::
YamlProcessor
.
new
(
params
[
:content
],
user:
current_user
).
execute
...
...
lib/gitlab/current_settings.rb
View file @
185d6a25
...
...
@@ -7,6 +7,10 @@ module Gitlab
!
signup_enabled?
end
def
signup_limited?
domain_allowlist
.
present?
||
email_restrictions_enabled?
||
require_admin_approval_after_user_signup?
end
def
current_application_settings
Gitlab
::
SafeRequestStore
.
fetch
(
:current_application_settings
)
{
ensure_application_settings!
}
end
...
...
spec/lib/gitlab/current_settings_spec.rb
View file @
185d6a25
...
...
@@ -24,6 +24,42 @@ RSpec.describe Gitlab::CurrentSettings do
end
end
describe
'.signup_limited?'
do
subject
{
described_class
.
signup_limited?
}
context
'when there are allowed domains'
do
before
do
create
(
:application_setting
,
domain_allowlist:
[
'www.gitlab.com'
])
end
it
{
is_expected
.
to
be_truthy
}
end
context
'when there are email restrictions'
do
before
do
create
(
:application_setting
,
email_restrictions_enabled:
true
)
end
it
{
is_expected
.
to
be_truthy
}
end
context
'when the admin has to approve signups'
do
before
do
create
(
:application_setting
,
require_admin_approval_after_user_signup:
true
)
end
it
{
is_expected
.
to
be_truthy
}
end
context
'when there are no restrictions'
do
before
do
create
(
:application_setting
,
domain_allowlist:
[],
email_restrictions_enabled:
false
,
require_admin_approval_after_user_signup:
false
)
end
it
{
is_expected
.
to
be_falsey
}
end
end
describe
'.signup_disabled?'
do
subject
{
described_class
.
signup_disabled?
}
...
...
spec/requests/api/lint_spec.rb
View file @
185d6a25
...
...
@@ -27,9 +27,10 @@ RSpec.describe API::Lint do
end
end
context
'when signup
settings are enabl
ed'
do
context
'when signup
is enabled and not limit
ed'
do
before
do
Gitlab
::
CurrentSettings
.
signup_enabled
=
true
stub_application_setting
(
domain_allowlist:
[],
email_restrictions_enabled:
false
,
require_admin_approval_after_user_signup:
false
)
end
context
'when unauthenticated'
do
...
...
@@ -50,6 +51,31 @@ RSpec.describe API::Lint do
end
end
context
'when limited signup is enabled'
do
before
do
stub_application_setting
(
domain_allowlist:
[
'www.gitlab.com'
])
Gitlab
::
CurrentSettings
.
signup_enabled
=
true
end
context
'when unauthenticated'
do
it
'returns unauthorized'
do
post
api
(
'/ci/lint'
),
params:
{
content:
'content'
}
expect
(
response
).
to
have_gitlab_http_status
(
:unauthorized
)
end
end
context
'when authenticated'
do
let_it_be
(
:api_user
)
{
create
(
:user
)
}
it
'returns authentication success'
do
post
api
(
'/ci/lint'
,
api_user
),
params:
{
content:
'content'
}
expect
(
response
).
to
have_gitlab_http_status
(
:ok
)
end
end
end
context
'when authenticated'
do
let_it_be
(
:api_user
)
{
create
(
:user
)
}
...
...
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